mirror of
https://github.com/kennethreitz/maya.git
synced 2026-06-05 23:00:18 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4fd8baf3eb |
+3
-7
@@ -1,12 +1,8 @@
|
||||
language: python
|
||||
python:
|
||||
- "2.7"
|
||||
- "3.3"
|
||||
- "3.4"
|
||||
- "3.5"
|
||||
- "3.6"
|
||||
|
||||
# - "3.5" # looks like ruamel.ordereddict doesn't build for python3
|
||||
# command to install dependencies
|
||||
install: pip install -r requirements.txt
|
||||
install: "pip install -r requirements.txt"
|
||||
# command to run tests
|
||||
script: make
|
||||
script: make
|
||||
+4
-7
@@ -1,14 +1,12 @@
|
||||
Contributions to the maya project
|
||||
=================================
|
||||
|
||||
Creator & Maintainer
|
||||
--------------------
|
||||
# Contributions to the maya project
|
||||
|
||||
## Creator & Maintainer
|
||||
|
||||
- Kenneth Reitz <me@kennethreitz.org> `@kennethreitz <https://github.com/kennethreitz>`_
|
||||
|
||||
|
||||
Contributors
|
||||
------------
|
||||
## Contributors
|
||||
|
||||
In chronological order:
|
||||
|
||||
@@ -19,4 +17,3 @@ In chronological order:
|
||||
- Tzu-ping Chung <uranusjr@gmail.com> (`@uranusjr <https://github.com/uranusjr>`_)
|
||||
- aaronjeline (`@aaronjeline <https://github.com/aaronjeline>`_)
|
||||
- jerry2yu (`@jerry2yu <https://github.com/jerry2yu>`_)
|
||||
- Joshua Li <joshua.r.li.98@gmail.com> (`@JoshuaRLi <https://github.com/JoshuaRLi>`_)
|
||||
|
||||
@@ -23,26 +23,19 @@ from tzlocal import get_localzone
|
||||
_EPOCH_START = (1970, 1, 1)
|
||||
|
||||
|
||||
def validate_class_type_arguments(operator):
|
||||
def validate_type_mayadt(func):
|
||||
"""
|
||||
Decorator to validate all the arguments to function
|
||||
are of the type of calling class
|
||||
are of type `MayaDT`
|
||||
"""
|
||||
|
||||
def inner(function):
|
||||
def wrapper(self, *args, **kwargs):
|
||||
for arg in args + tuple(kwargs.values()):
|
||||
if not isinstance(arg, self.__class__):
|
||||
raise TypeError('unorderable types: {}() {} {}()'.format(
|
||||
type(self).__name__, operator, type(arg).__name__))
|
||||
return function(self, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
def inner(*args, **kwargs):
|
||||
for arg in args + tuple(kwargs.values()):
|
||||
if not isinstance(arg, MayaDT):
|
||||
raise ValueError("Operation allowed only on object of type '{}'".format(MayaDT.__name__))
|
||||
return func(*args, **kwargs)
|
||||
return inner
|
||||
|
||||
|
||||
|
||||
class MayaDT(object):
|
||||
"""The Maya Datetime object."""
|
||||
|
||||
@@ -53,37 +46,37 @@ class MayaDT(object):
|
||||
def __repr__(self):
|
||||
return '<MayaDT epoch={}>'.format(self._epoch)
|
||||
|
||||
def __str__(self):
|
||||
return self.rfc2822()
|
||||
|
||||
def __format__(self, *args, **kwargs):
|
||||
"""Return's the datetime's format"""
|
||||
return format(self.datetime(), *args, **kwargs)
|
||||
|
||||
@validate_type_mayadt
|
||||
def __sub__(self, maya_dt):
|
||||
return MayaDT(self._epoch - maya_dt._epoch)
|
||||
|
||||
@validate_class_type_arguments('==')
|
||||
@validate_type_mayadt
|
||||
def __eq__(self, maya_dt):
|
||||
return self._epoch == maya_dt._epoch
|
||||
|
||||
@validate_class_type_arguments('!=')
|
||||
@validate_type_mayadt
|
||||
def __ne__(self, maya_dt):
|
||||
return self._epoch != maya_dt._epoch
|
||||
return not self.__eq__(maya_dt)
|
||||
|
||||
@validate_class_type_arguments('<')
|
||||
@validate_type_mayadt
|
||||
def __lt__(self, maya_dt):
|
||||
return self._epoch < maya_dt._epoch
|
||||
|
||||
@validate_class_type_arguments('<=')
|
||||
@validate_type_mayadt
|
||||
def __le__(self, maya_dt):
|
||||
return self._epoch <= maya_dt._epoch
|
||||
return self.__lt__(maya_dt) or self.__eq__(maya_dt)
|
||||
|
||||
@validate_class_type_arguments('>')
|
||||
@validate_type_mayadt
|
||||
def __gt__(self, maya_dt):
|
||||
return self._epoch > maya_dt._epoch
|
||||
|
||||
@validate_class_type_arguments('>=')
|
||||
@validate_type_mayadt
|
||||
def __ge__(self, maya_dt):
|
||||
return self._epoch >= maya_dt._epoch
|
||||
return self.__gt__(maya_dt) or self.__eq__(maya_dt)
|
||||
|
||||
|
||||
# Timezone Crap
|
||||
@@ -224,8 +217,7 @@ class MayaDT(object):
|
||||
|
||||
def slang_date(self):
|
||||
""""Returns human slang representation of date."""
|
||||
dt = self.datetime(naive=True, to_timezone=self.local_timezone)
|
||||
return humanize.naturaldate(dt)
|
||||
return humanize.naturaldate(self.datetime())
|
||||
|
||||
def slang_time(self):
|
||||
""""Returns human slang representation of time."""
|
||||
|
||||
+2
-3
@@ -1,4 +1,4 @@
|
||||
-e .
|
||||
-e .
|
||||
dateparser==0.5.0
|
||||
humanize==0.5.1
|
||||
iso8601==0.1.11
|
||||
@@ -8,8 +8,7 @@ pytest==3.0.5
|
||||
python-dateutil==2.6.0
|
||||
pytz==2016.10
|
||||
regex==2016.11.21
|
||||
#ruamel.ordereddict is only needed for python 2
|
||||
#ruamel.ordereddict==0.4.9
|
||||
ruamel.ordereddict==0.4.9
|
||||
ruamel.yaml==0.13.4
|
||||
six==1.10.0
|
||||
typing==3.5.2.2
|
||||
|
||||
@@ -16,9 +16,8 @@ except ImportError:
|
||||
|
||||
here = os.path.abspath(dirname(__file__))
|
||||
|
||||
with codecs.open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
|
||||
long_description = '\n' + f.read()
|
||||
|
||||
def read(*parts):
|
||||
return codecs.open(os.path.join(here, *parts), 'r').read()
|
||||
|
||||
if sys.argv[-1] == "publish":
|
||||
os.system("python setup.py sdist bdist_wheel upload")
|
||||
@@ -36,9 +35,9 @@ required = [
|
||||
|
||||
setup(
|
||||
name='maya',
|
||||
version='0.1.6',
|
||||
version='0.1.5',
|
||||
description='Datetimes for Humans.',
|
||||
long_description=long_description,
|
||||
long_description= '\n' + read('README.rst'),
|
||||
author='Kenneth Reitz',
|
||||
author_email='me@kennethreitz.com',
|
||||
url='https://github.com/kennethreitz/maya',
|
||||
|
||||
Regular → Executable
+15
-48
@@ -1,20 +1,19 @@
|
||||
import pytest
|
||||
from datetime import datetime
|
||||
import copy
|
||||
|
||||
import maya
|
||||
|
||||
|
||||
def test_rfc2822():
|
||||
r = maya.parse('February 21, 1994').rfc2822()
|
||||
r = maya.now().rfc2822()
|
||||
d = maya.MayaDT.from_rfc2822(r)
|
||||
assert r == 'Mon, 21 Feb 1994 00:00:00 GMT'
|
||||
assert r == d.rfc2822()
|
||||
|
||||
|
||||
def test_iso8601():
|
||||
r = maya.parse('February 21, 1994').iso8601()
|
||||
r = maya.now().iso8601()
|
||||
d = maya.MayaDT.from_iso8601(r)
|
||||
assert r == '1994-02-21T00:00:00Z'
|
||||
assert r == d.iso8601()
|
||||
|
||||
|
||||
@@ -22,8 +21,7 @@ def test_human_when():
|
||||
r1 = maya.when('yesterday')
|
||||
r2 = maya.when('today')
|
||||
|
||||
assert (r2.day - r1.day) in (1, -30, -29, -28, -27)
|
||||
|
||||
assert r2.day - r1.day == 1
|
||||
|
||||
def test_machine_parse():
|
||||
r1 = maya.parse('August 14, 2015')
|
||||
@@ -36,7 +34,7 @@ def test_machine_parse():
|
||||
def test_dt_tz_translation():
|
||||
d1 = maya.now().datetime()
|
||||
d2 = maya.now().datetime(to_timezone='US/Eastern')
|
||||
assert (d1.hour - d2.hour) % 24 == 5
|
||||
assert d1.hour - d2.hour == 5
|
||||
|
||||
|
||||
def test_dt_tz_naive():
|
||||
@@ -45,34 +43,18 @@ def test_dt_tz_naive():
|
||||
|
||||
d2 = maya.now().datetime(to_timezone='US/Eastern', naive=True)
|
||||
assert d2.tzinfo is None
|
||||
assert (d1.hour - d2.hour) % 24 == 5
|
||||
assert d1.hour - d2.hour == 5
|
||||
|
||||
|
||||
def test_random_date():
|
||||
|
||||
# Test properties for maya.when()
|
||||
d1 = maya.when('11-17-11 08:09:10')
|
||||
assert d1.year == 2011
|
||||
assert d1.month == 11
|
||||
assert d1.day == 17
|
||||
assert d1.week == 46
|
||||
assert d1.weekday == 4
|
||||
assert d1.hour == 8
|
||||
assert d1.minute == 9
|
||||
assert d1.second == 10
|
||||
assert d1.microsecond == 0
|
||||
|
||||
# Test properties for maya.parse()
|
||||
d2 = maya.parse('February 29, 1992 13:12:34')
|
||||
assert d2.year == 1992
|
||||
assert d2.month == 2
|
||||
assert d2.day == 29
|
||||
assert d2.week == 9
|
||||
assert d2.weekday == 6
|
||||
assert d2.hour == 13
|
||||
assert d2.minute == 12
|
||||
assert d2.second == 34
|
||||
assert d2.microsecond == 0
|
||||
d = maya.when('11-17-11 08:09:10')
|
||||
assert d.year == 2011
|
||||
assert d.month == 11
|
||||
assert d.day == 17
|
||||
assert d.hour == 8
|
||||
assert d.minute == 9
|
||||
assert d.second == 10
|
||||
assert d.microsecond == 0
|
||||
|
||||
|
||||
def test_print_date(capsys):
|
||||
@@ -80,9 +62,7 @@ def test_print_date(capsys):
|
||||
|
||||
print(d)
|
||||
out, err = capsys.readouterr()
|
||||
|
||||
assert out == 'Thu, 17 Nov 2011 00:00:00 GMT\n'
|
||||
assert repr(d) == '<MayaDT epoch=1321488000.0>'
|
||||
assert out == '<MayaDT epoch=1321488000.0>\n'
|
||||
|
||||
|
||||
def test_invalid_date():
|
||||
@@ -139,16 +119,3 @@ def test_comparison_operations():
|
||||
assert (now >= now_copy) is True
|
||||
assert (now >= tomorrow) is False
|
||||
|
||||
# Check Exceptions
|
||||
with pytest.raises(TypeError):
|
||||
now == 1
|
||||
with pytest.raises(TypeError):
|
||||
now != 1
|
||||
with pytest.raises(TypeError):
|
||||
now < 1
|
||||
with pytest.raises(TypeError):
|
||||
now <= 1
|
||||
with pytest.raises(TypeError):
|
||||
now > 1
|
||||
with pytest.raises(TypeError):
|
||||
now >= 1
|
||||
|
||||
Reference in New Issue
Block a user