Django

Code

Ticket #2975 (reopened)

Opened 2 years ago

Last modified 2 years ago

[patch] parseDateString function in dateparse.js return wrong date for '2006-12-31'

Reported by: wangbin@exoweb.net Assigned to: nobody
Milestone: Component: django.contrib.admin
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

dateparse.patch (0.6 kB) - added by wangbin@exoweb.net on 11/02/06 22:57:50.
dateparse.js.diff (2.4 kB) - added by rich@tablexi.com on 02/17/07 02:42:11.
More complete fix of this issue.

Change History

11/02/06 22:57:50 changed by wangbin@exoweb.net

  • attachment dateparse.patch added.

11/06/06 19:59:47 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

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

02/17/07 02:42:11 changed by rich@tablexi.com

  • attachment dateparse.js.diff added.

More complete fix of this issue.

02/17/07 02:54:31 changed by rich@tablexi.com

  • cc set to simon@simonwillison.net.
  • status changed from closed to reopened.
  • resolution deleted.

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.

02/17/07 02:55:16 changed by anonymous

  • cc deleted.

02/17/07 03:07:42 changed by anonymous

  • stage changed from Unreviewed to Ready for checkin.

02/17/07 03:36:49 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Ready for checkin to Accepted.

Please don't do anonymous triaging, thanks.

02/17/07 03:42:38 changed by rich@tablexi.com

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.

02/17/07 05:32:42 changed by Simon G. <dev@simon.net.nz>

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


Add/Change #2975 ([patch] parseDateString function in dateparse.js return wrong date for '2006-12-31')




Change Properties
Action