Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing when current day is not in month #74

Open
hector opened this issue Sep 30, 2015 · 10 comments
Open

Error parsing when current day is not in month #74

hector opened this issue Sep 30, 2015 · 10 comments

Comments

@hector
Copy link

hector commented Sep 30, 2015

Hi,

Since delorean.parse() fills missing info from the string with the current date, it will fail if trying to parse a date with month if your current day is out of that month.
An example to make it clear:

  1. Today is 30th September
  2. I do `delorean.parse('2000-02')``
  3. I will get "Unknown string format" since 30th does not exist for February

What would be the correct approach to parse this kind of strings? Is there a way to parse without filling the missing information with the current date (for example with day 1, hour 0 etc)?

@myusuf3
Copy link
Owner

myusuf3 commented Oct 1, 2015

I wasn't aware of this behaviour and something I will have to look into the usage of dateutil.

@gordol
Copy link

gordol commented Jun 30, 2017

this is related also to this bug i think? #99

@myusuf3
Copy link
Owner

myusuf3 commented Jun 30, 2017

@gordol was this related, can this be closed?

@gordol
Copy link

gordol commented Jun 30, 2017

It's a dateutil issue upstream. Not fixed and they aren't planning to fix any time soon it seems.

@myusuf3
Copy link
Owner

myusuf3 commented Jun 30, 2017

@gordol did they give a reason?

@gordol
Copy link

gordol commented Jul 1, 2017

i think this is actually a different bug...

dateutil/dateutil#149 (comment)

that is the reason given. basically, it implements an old RFC.

@gordol
Copy link

gordol commented Jul 1, 2017

delorean basically just implements dateutil.parser.parse

This module attempts to be forgiving with regards to unlikely input formats, returning a datetime object even for dates which are ambiguous. If an element of a date/time stamp is omitted, the following rules are applied: - If AM or PM is left unspecified, a 24-hour clock is assumed, however, an hour

on a 12-hour clock (0 <= hour <= 12) must be specified if AM or PM is specified.
If a time zone is omitted, a timezone-naive datetime is returned.
If any other elements are missing, they are taken from the datetime.datetime object passed to the parameter default. If this results in a day number exceeding the valid number of days per month, the value falls back to the end of the month.

Anyway, this led me down a journey into dateutil... and it seems this may have been fixed in 2.5?

dateutil/dateutil#25

currently delorean lists dateutil 2.4.2 as the required version.

however, i think there are some other issues in dateutil after 2.5.1...

so you may want to stick with 2.5.1 for now.

see the changelog here where this was fixed in 2.5.0:
https://github.com/dateutil/dateutil/blob/38232aacc3c46ef3b649ec730a2444ed13fe3894/NEWS#L150

@gordol
Copy link

gordol commented Jul 1, 2017

2.6 has a new parsing overhaul, so maybe give it a whirl?

@gordol
Copy link

gordol commented Jul 1, 2017

#87

@gordol
Copy link

gordol commented Jul 1, 2017

you can pass a default date to the parse() method also... to work around this. or you can simply set the first day of your date string to "1" to be first day of month. by default it uses the current day's date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants