Opened 9 years ago

Closed 5 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: master
Severity: normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


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@… 9 years ago.
dateparse.js.diff (2.4 KB) - added by rich@… 9 years ago.
More complete fix of this issue.

Download all attachments as: .zip

Change History (11)

Changed 9 years ago by wangbin@…

comment:1 Changed 9 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

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

Changed 9 years ago by rich@…

More complete fix of this issue.

comment:2 Changed 9 years ago by rich@…

  • Cc simon@… added
  • Resolution fixed deleted
  • Status changed from closed to 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:

  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 Changed 9 years ago by anonymous

  • Cc simon@… removed

comment:4 Changed 9 years ago by anonymous

  • Triage Stage changed from Unreviewed to Ready for checkin

comment:5 Changed 9 years ago by Simon G. <dev@…>

  • Triage Stage changed from Ready for checkin to Accepted

Please don't do anonymous triaging, thanks.

comment:6 Changed 9 years ago by rich@…

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 Changed 9 years ago by Simon G. <dev@…>

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

comment:8 Changed 5 years ago by adamnelson

  • Triage Stage changed from Accepted to 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 Changed 5 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from reopened to closed

(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