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: wangbin@… 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)

dateparse.patch (567 bytes ) - added by wangbin@… 18 years ago.
dateparse.js.diff (2.4 KB ) - added by rich@… 18 years ago.
More complete fix of this issue.

Download all attachments as: .zip

Change History (11)

by wangbin@…, 18 years ago

Attachment: dateparse.patch added

comment:1 by Jacob, 18 years ago

Resolution: fixed
Status: newclosed

(In [4032]) Fixed #2975: dateparse.js now correctly handles the last day of the year. Thanks, wangbin@….

by rich@…, 18 years ago

Attachment: dateparse.js.diff added

More complete fix of this issue.

comment:2 by rich@…, 18 years ago

Cc: simon@… added
Resolution: fixed
Status: closedreopened

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:

  1. set day to 1 (any day that exists in all months is fine too)
  2. set year
  3. set month
  4. set day

Please reference the attached patch.

comment:3 by anonymous, 18 years ago

Cc: simon@… removed

comment:4 by anonymous, 18 years ago

Triage Stage: UnreviewedReady for checkin

comment:5 by Simon G. <dev@…>, 18 years ago

Triage Stage: Ready for checkinAccepted

Please don't do anonymous triaging, thanks.

comment:6 by rich@…, 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:7 by Simon G. <dev@…>, 18 years ago

No that's ok, we just get a lot of random modifications from spammers.

comment:8 by Adam Nelson, 15 years ago

Triage Stage: AcceptedReady 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 Malcolm Tredinnick, 14 years ago

Resolution: fixed
Status: reopenedclosed

(In [13713]) Fixed date parsing of 31st dates when current month has 30 days (!!).

Patch from rich@…. Fixed #2975.

Note: See TracTickets for help on using tickets.
Back to Top