Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#13935 closed defect (fixed)

Calendar does not accept ISO date with Safari

Reported by: Philippe May Owned by: bill
Priority: high Milestone: 1.7
Component: Dijit Version: 1.7.0b1
Keywords: Calendar Safari Cc:
Blocked By: Blocking:

Description

Setting a proper ISO date value to a calendar widget fails with Safari (5.1, Snow Leopard, Dojo trunk). This bug can be seen on the second calendar of http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/test_Calendar.html where no date is selected (it should be 2008-03-14).

It seems there's a bug in the native Date function: it accepts a localized date (like 17/09/2011 with French locale). But new Date('2011-09-09') returns Invalid Date.

This also affects dojox calendars.

Attachments (2)

CalendarLite.js.diff (1.1 KB) - added by Philippe May 8 years ago.
Patch for dijit.Calendar
MultiSelectCalendar.js.diff (3.3 KB) - added by Philippe May 8 years ago.
Patch for dojox.widget.MultiSelectCalendar?, including a change of the constructor matching dijit.CalendarLite?

Download all attachments as: .zip

Change History (9)

comment:1 Changed 8 years ago by bill

This sounds familiar. IIRC someone hit this problem and had a solution calling either new Date() or new Date(""), either once, or every time prior to initializing a Calendar.

Note that we already have some workaround code for another browser bug, in _DateTimeTextBox.js:

new Date("X"); // workaround for #11279, new Date("") == NaN

comment:2 Changed 8 years ago by Adam Peller

That value should be passed to dojo.date.stamp.fromISOString, not the Date constructor. If a dojox calendar is using the Date constructor this way, it may be a separate bug.

Changed 8 years ago by Philippe May

Attachment: CalendarLite.js.diff added

Patch for dijit.Calendar

Changed 8 years ago by Philippe May

Attachment: MultiSelectCalendar.js.diff added

Patch for dojox.widget.MultiSelectCalendar?, including a change of the constructor matching dijit.CalendarLite?

comment:3 Changed 8 years ago by bill

Owner: set to bill
Status: newassigned

Hi aprilmay,

There's actually a bug in the dijit test file. Calendar / CalendarLite will accept a number or a Date for the set("value", ...) call, but they don't accept a String. (Maybe it should accept a string, but it doesn't, according to it's spec.)

Normally you don't have to worry about using strings since the parser will convert a string like value="2008-03-14" into a Date before the value gets to the Calendar widget. However, the test file, starting with 1.6, is doing

data-dojo-props='dayWidth:"abbr", value:"2008-03-14"'

so the parser is hands-off, doing no conversions. The markup should either be:

data-dojo-props='dayWidth:"abbr",
    value:dojo.date.stamp.fromISOString("2008-03-14")'

or

data-dojo-props='dayWidth:"abbr"' value="2008-03-14"

I'll update the dijit test file.

As for dojox MultiSelectCalendar, I suspect it's the same issue (an error with the test file), but can you file a separate ticket for that issue? It will be handled by someone else.

comment:4 Changed 8 years ago by bill

PS: I do think it would be a good enhancement for Calendar to accept a string, so I filed #14139.

comment:5 Changed 8 years ago by bill

PPS: Oh, there's another problem (does your patch fix this?) where the Calendar's grid isn't updated to reflect the initially specified value, even if it's specified as a Date. I filed that as #14140.

comment:6 Changed 8 years ago by bill

Resolution: fixed
Status: assignedclosed

In [26897]:

Fix error in test file, value must be specified as a Date or a Number, not as a String. Fixes #13935.

comment:7 Changed 8 years ago by Philippe May

Hi Bill,

Thanks for the explanation and resolution. Agree with #14139: it is nice to be able to set and get serializable values.

Created #14197 for dojox.MultiSelectCalendar

Note: See TracTickets for help on using tickets.