myusuf3 / delorean

Delorean: Time Travel Made Easy
http://delorean.rtfd.org/
MIT License
1.84k stars 128 forks source link

Documentation mismatch for parsing strings in latest version #84

Closed ParthGandhi closed 8 years ago

ParthGandhi commented 8 years ago

Theres a bug when parsing date strings in the latest release.

In a new virtual env:

$ pip install delorean
$ pip freeze
Babel==2.2.0
Delorean==0.6.0
humanize==0.5.1
python-dateutil==2.5.2
pytz==2016.3
six==1.10.0
tzlocal==1.2.2
wheel==0.24.0
>>> import delorean
>>> delorean.parse("2013-05-06")
Delorean(datetime=datetime.datetime(2013, 6, 5, 0, 0), timezone='UTC')

but the docs say that the output should be Delorean(datetime=datetime.datetime(2013, 5, 6), timezone='UTC') (which is the correct thing to do according to ISO 8601).

Installing python-dateutil==2.5.1 fixes the problem, but i'm not sure if the bug is in delorean or on their end.

andremilk commented 8 years ago

On the changelog for the python-dateutil==2.5.2 they say they fixed a bug regarding dayfirst and yearfirst. https://github.com/dateutil/dateutil/blob/master/NEWS

https://github.com/dateutil/dateutil/pull/229/commits/2d42e046d55b9fbbc0a2f41ce83fb8ec5de2d28b

Looking forward to know more about this.

andremilk commented 8 years ago

I got an error of "ValueError: month must be in 1..12" from dateutil

File "/usr/local/lib/python2.7/site-packages/pynamodb/models.py", line 394, in refresh self._deserialize(item_data) File "/usr/local/lib/python2.7/site-packages/pynamodb/models.py", line 1142, in _deserialize setattr(self, name, attr_instance.deserialize(value)) File "/usr/local/lib/python2.7/site-packages/pynamodb/attributes.py", line 260, in deserialize print parse(value).datetime File "/usr/local/lib/python2.7/site-packages/delorean/interface.py", line 68, in parse dt = capture(datetime_str, dayfirst=dayfirst, yearfirst=yearfirst) File "/usr/local/lib/python2.7/site-packages/dateutil/parser.py", line 1170, in parse return DEFAULTPARSER.parse(timestr, kwargs) File "/usr/local/lib/python2.7/site-packages/dateutil/parser.py", line 580, in parse ret = default.replace(repl) ValueError: month must be in 1..12 and repl = {u'hour': 22, u'month': 28, u'second': 20, u'microsecond': 600703, u'year': 2016, u'day': 3, u'minute': 38}

alan-unravel commented 8 years ago

+1 on this

alan-unravel commented 8 years ago

A quick fix for this to prevent breaks would be to set dayfirst's default value to False, also it is strange that they don't deal with yearfirst flag at all and ideally it should take priority since it was the default

myusuf3 commented 8 years ago

I wont have time to look at this till monday, but I will fix it soon.

ParthGandhi commented 8 years ago

Closing this as a duplicate of #87.