-
Notifications
You must be signed in to change notification settings - Fork 523
Description
I wrote the following simple test using the python-hypothesis library. It generates dates, renders them as strings, then unpacks them using parser.parse() and checks the date survived the trip:
from dateutil.parser import parse
@given(datetimes())
def test_round_trip(d):
assert parse(str(d)) == dIf you try enough examples: this test fails:
- Pass in
d=datetime.datetime(4, 4, 1, 0, 0)– i.e., April 1st in the year 4 - Casting to
str(), this becomes'0004-04-01 00:00:00' - When unpacked with
parse(), it becomesdatetime.datetime(1, 4, 4, 0, 0)– i.e., April 4th in the year 1. Mismatch!
The same problem occurs for all datetime.datetime(M, M, 1, 0, 0) for 1 < M <= 12.
Given the four-digit year, I think this string is fairly unambiguous, but it seems to be getting confused somewhere, and treating the -01 as the year. But two-digit years are supposed to be within 50 years of the current year:
Converting two digit years
When a two digit year is found, it is processed considering the current year, so that the computed year is never more than 49 years after then current year, nor 50 years before the current year. In other words, if we are in year 2003, and the year 30 is found, it will be considered as 2030, but if the year 60 is found, it will be considered 1960.
So if it really is treating -01 as the year, then based on this rule it should be returning datetime.datetime(2001, 4, 4, 0, 0).