No support for dates before 1900
|Reported by:||Antti Kaihola||Owned by:||Adrian Holovaty|
|Severity:||normal||Keywords:||date 1900 datetime|
|Cc:||rafaelbm_sbo@…, gary.wilson@…, brian.mabry.edwards@…, greenwaldjared@…, simon@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
See logviewer for a short discussion.
#1070 changed date validation so dates before 1900 raise an error. But that's only to avoid problems further down the road.
>>> datetime(1805,12,24).strftime('%Y-%m-%d') ValueError: year=1805 is before 1900; the datetime strftime() methods require year >= 1900
Using PHP-style date formatting is broken too:
>>> dateformat.format(datetime(1899,4,12), 'Y-m-d') /usr/local/lib/djangomr2458/django/utils/tzinfo.py in _isdst(self, dt) ---> 50 stamp = time.mktime(tt) ValueError: year out of range
The problem is deeper in Python (or C, or the OS, or whatever):
>>> time.mktime((1901,12,14,0,0,0,0,0,0)) -2147477992.0 >>> time.mktime((1901,12,13,0,0,0,0,0,0)) OverflowError: mktime argument out of range >>> time.mktime((1899,12,31,0,0,0,0,0,0)) ValueError: year out of range
Would mx.DateTime be a solution?
>>> mx.DateTime.Date(1543,12,24).strftime('%Y-%m-%d') '1543-12-24'
I realize that adding another external module dependency is not a Good Thing. Maybe it's worth checking if mx.DateTime is similar enough to be used as a drop-in replacement for datetime in case it's installed on the system? This way those who need to go back to 19th century or before could just install mx.DateTime and enjoy.
Change History (35)
comment:2 Changed 10 years ago by
|Status:||closed → reopened|
comment:3 Changed 10 years ago by
|Summary:||no support for dates before 1900 → [patch] no support for dates before 1900|
comment:4 Changed 10 years ago by
|Keywords:||date 1900 datetime added|
|Triage Stage:||Unreviewed → Accepted|
comment:15 Changed 9 years ago by
|Status:||reopened → closed|
|Triage Stage:||Ready for checkin → Design decision needed|
comment:20 Changed 9 years ago by
|Patch needs improvement:||unset|
|Summary:||[patch] no support for dates before 1900 → No support for dates before 1900|
comment:27 Changed 8 years ago by
|Owner:||changed from Chris Beaven to Adrian Holovaty|
|Status:||new → assigned|
|Triage Stage:||Design decision needed → Accepted|