Opened 18 years ago
Closed 14 years ago
#2975 closed defect (fixed)
[patch] parseDateString function in dateparse.js return wrong date for '2006-12-31'
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When using parseDateString function in django/contrib/admin/media/js/dateparse.js to parse '2006-12-31', i got a wrong date 2006-12-1, this happens when the current month has no 31st date(e.g. November), I believe it is a bug in dateParsePatterns line 172-173, it set date before month, should be the month set before date, and i made a patch for this.
Attachments (2)
Change History (11)
by , 18 years ago
Attachment: | dateparse.patch added |
---|
comment:1 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 18 years ago
Cc: | added |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
The previous patch is an incomplete fix. In addition, the scope of this issue extends further than the message for [4032] indicates.
This problem manifests itself because months have different number of days and JavaScript automatically rolls over when modifying date objects if there are days past the max day of that month. (e.g. Feb 15, 2007 -> Jan 31, 2007 and vice versa)
The root of the problem is the order in which the JavaScript data object is modified. To get consistent results when changing the entire date object, it's important to set the date in this manner:
- set day to 1 (any day that exists in all months is fine too)
- set year
- set month
- set day
Please reference the attached patch.
comment:3 by , 18 years ago
Cc: | removed |
---|
comment:4 by , 18 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
comment:5 by , 18 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
Please don't do anonymous triaging, thanks.
comment:6 by , 18 years ago
Sorry, those anonymous comments were mine. I'm used to my Trac instantiation which remembers me. I changed the stage after reading the contribution docs. I'm sorry if I was not supposed to do that.
comment:8 by , 15 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Amazingly, this dateparse is still unchanged from up to 6 years ago. jQuery surely has a supported date parsing plugin that would be better to move to, but this patch fixes the bug without changing libraries.
comment:9 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
(In [4032]) Fixed #2975: dateparse.js now correctly handles the last day of the year. Thanks, wangbin@….