Open hector opened 9 years ago
I wasn't aware of this behaviour and something I will have to look into the usage of dateutil
.
this is related also to this bug i think? https://github.com/myusuf3/delorean/issues/99
@gordol was this related, can this be closed?
It's a dateutil issue upstream. Not fixed and they aren't planning to fix any time soon it seems.
@gordol did they give a reason?
i think this is actually a different bug...
https://github.com/dateutil/dateutil/issues/149#issuecomment-186367034
that is the reason given. basically, it implements an old RFC.
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?
https://github.com/dateutil/dateutil/issues/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
2.6 has a new parsing overhaul, so maybe give it a whirl?
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.
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: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)?