diff --git a/.travis.yml b/.travis.yml index 197b11b..c3afb2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,12 @@ language: python python: - "2.7" - # - "3.5" # looks like ruamel.ordereddict doesn't build for python3 + - "3.3" + - "3.4" + - "3.5" + - "3.6" + # command to install dependencies -install: "pip install -r requirements.txt" +install: pip install -r requirements.txt # command to run tests -script: make \ No newline at end of file +script: make diff --git a/maya.py b/maya.py index 7371705..ce485f0 100644 --- a/maya.py +++ b/maya.py @@ -33,6 +33,9 @@ class MayaDT(object): def __repr__(self): return ''.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) @@ -216,7 +219,8 @@ class MayaDT(object): def slang_date(self): """"Returns human slang representation of date.""" - return humanize.naturaldate(self.datetime()) + dt = self.datetime(naive=True, to_timezone=self.local_timezone) + return humanize.naturaldate(dt) def slang_time(self): """"Returns human slang representation of time.""" diff --git a/requirements.txt b/requirements.txt index ed6b7f0..9878b9d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ --e . +-e . dateparser==0.5.0 humanize==0.5.1 iso8601==0.1.11 @@ -8,7 +8,8 @@ pytest==3.0.5 python-dateutil==2.6.0 pytz==2016.10 regex==2016.11.21 -ruamel.ordereddict==0.4.9 +#ruamel.ordereddict is only needed for python 2 +#ruamel.ordereddict==0.4.9 ruamel.yaml==0.13.4 six==1.10.0 typing==3.5.2.2 diff --git a/setup.py b/setup.py index 7471f13..a2a660d 100755 --- a/setup.py +++ b/setup.py @@ -16,8 +16,9 @@ except ImportError: here = os.path.abspath(dirname(__file__)) -def read(*parts): - return codecs.open(os.path.join(here, *parts), 'r').read() +with codecs.open(os.path.join(here, 'README.rst'), encoding='utf-8') as f: + long_description = '\n' + f.read() + if sys.argv[-1] == "publish": os.system("python setup.py sdist bdist_wheel upload") @@ -37,7 +38,7 @@ setup( name='maya', version='0.1.4', description='Datetimes for Humans.', - long_description= '\n' + read('README.rst'), + long_description=long_description, author='Kenneth Reitz', author_email='me@kennethreitz.com', url='https://github.com/kennethreitz/maya', diff --git a/test_maya.py b/test_maya.py index 32a00cc..ad1d8b7 100644 --- a/test_maya.py +++ b/test_maya.py @@ -36,7 +36,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 == 5 + assert (d1.hour - d2.hour) % 24 == 5 def test_dt_tz_naive(): @@ -45,18 +45,34 @@ 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 == 5 + assert (d1.hour - d2.hour) % 24 == 5 def test_random_date(): - 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 + + # 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 def test_print_date(capsys): @@ -64,7 +80,9 @@ def test_print_date(capsys): print(d) out, err = capsys.readouterr() - assert out == '\n' + + assert out == 'Thu, 17 Nov 2011 00:00:00 GMT\n' + assert repr(d) == '' def test_invalid_date(): @@ -120,19 +138,3 @@ def test_comparison_operations(): assert (now >= now_copy) is True assert (now >= tomorrow) is False - - -def test_weekday(): - dt = maya.parse('February 21, 1994') - assert dt.weekday == 1 # was a Monday - - dt = maya.parse('February 29, 1992') - assert dt.weekday == 6 # was a Saturday - - -def test_week(): - dt = maya.parse('February 21, 1994') - assert dt.week == 8 - - dt = maya.parse('May 29, 1992') - assert dt.week == 22