diff --git a/README.rst b/README.rst index bd6b635..b4e8253 100644 --- a/README.rst +++ b/README.rst @@ -30,7 +30,7 @@ Behold, datetimes for humans! >>> tomorrow.iso8601() '2016-12-16T15:11:30.263350Z' - >>> tomorrrow.rfc2822() + >>> tomorrow.rfc2822() 'Fri, 16 Dec 2016 20:11:30 -0000' >>> tomorrow.datetime() @@ -60,10 +60,10 @@ Behold, datetimes for humans! - All timezone algebra will behave identically on all machines, regardless of system locale. - Complete symmetric import and export of both ISO 8601 and RFC 2822 datetime stamps. - Fantastic parsing of both dates written for/by humans and machines (``maya.when()`` vs ``maya.parse()``). -- Support for human slang, both import and export (e.g. `an hour ago`). -- Datetimes can very easily be generated, with our without tzinfo attached. +- Support for human slang, both import and export (e.g. `an hour ago`). +- Datetimes can very easily be generated, with or without tzinfo attached. - This library is based around epoch time, but dates before Jan 1 1970 are indeed supported, via negative integers. -- Maya never panics, and always carrys a towel. +- Maya never panics, and always carries a towel. ☤ Installing Maya ----------------- @@ -73,3 +73,8 @@ Installation is easy, with pip:: $ pip install maya ✨🍰✨ + +☤ Like it? +---------- + +`Say Thanks `_! diff --git a/maya.py b/maya.py index 94d52e5..dce4e3a 100644 --- a/maya.py +++ b/maya.py @@ -34,7 +34,7 @@ class MayaDT(object): def __format__(self, *args, **kwargs): """Return's the datetime's format""" - return self.datetime(*args, **kwargs) + return format(self.datetime(*args, **kwargs)) # Timezone Crap # ------------- @@ -205,4 +205,4 @@ def parse(string): string -- string to be parsed """ dt = dateutil.parser.parse(string) - return MayaDT.from_datetime(dt) \ No newline at end of file + return MayaDT.from_datetime(dt) diff --git a/setup.py b/setup.py index 5381108..29f1973 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ setup( author='Kenneth Reitz', author_email='me@kennethreitz.com', url='https://github.com/kennethreitz/maya', - my_modules=['maya'], + py_modules=['maya'], install_requires=required, license='MIT', classifiers=( diff --git a/test_maya.py b/test_maya.py index 8406b6c..413e371 100644 --- a/test_maya.py +++ b/test_maya.py @@ -1,3 +1,6 @@ +import pytest +from datetime import datetime + import maya @@ -43,10 +46,29 @@ def test_dt_tz_naive(): def test_random_date(): - d = maya.when('11-17-11') + 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): + d = maya.when('11-17-11') + + print(d) + out, err = capsys.readouterr() + assert out == '\n' + + assert type(d.__format__()) is datetime + + +def test_invalid_date(): + with pytest.raises(ValueError): + d = maya.when('another day') def test_slang_date(): @@ -58,4 +80,9 @@ def test_slang_time(): d = maya.when('one hour ago') assert d.slang_time() == 'an hour ago' + +def test_format(): + d = maya.parse('February 21, 1994') + assert format(d) == format(d.datetime()) + # rand_day = maya.when('2011-02-07', timezone='US/Eastern')