Opened 13 years ago

Closed 12 years ago

#2480 closed enhancement (wontfix)

Support for serializing dates and times to ISO8601 format.

Reported by: james@… Owned by: Adam Peller
Priority: high Milestone:
Component: Date Version: 0.4.1
Keywords: Cc: Adam Peller
Blocked By: Blocking:

Description

This patch adds methods for serializing Date objects to ISO8601 date and time strings with dojo.date.serialize. New methods are: dojo.date.toIso8601(), dojo.date.toIso8601Date(), and dojo.date.toIso8601Time(). Users can set the timezone and choose between human-readable and compact output.

Automated tests for all methods are included.

Attachments (3)

toIso8601.patch (7.6 KB) - added by james@… 13 years ago.
Add support for serializing Dates to ISO8601 format.
toIso8601-2.patch (10.6 KB) - added by james@… 13 years ago.
Improved patch. Simplified toRfc3339() by calling toIso8601*() methods.
toIso8601-3.patch (11.5 KB) - added by james@… 13 years ago.
Minor improvements to documentation and tests.

Download all attachments as: .zip

Change History (7)

Changed 13 years ago by james@…

Attachment: toIso8601.patch added

Add support for serializing Dates to ISO8601 format.

comment:1 Changed 13 years ago by Adam Peller

Cc: Adam Peller added

Changed 13 years ago by james@…

Attachment: toIso8601-2.patch added

Improved patch. Simplified toRfc3339() by calling toIso8601*() methods.

Changed 13 years ago by james@…

Attachment: toIso8601-3.patch added

Minor improvements to documentation and tests.

comment:2 Changed 13 years ago by Adam Peller

Owner: changed from psowden to Adam Peller

comment:3 Changed 13 years ago by james@…

Although there is an existing dojo.date.toRfc3339() method, and RFC3339 is a subset of ISO8601, the new toIso8601*() methods that I've added have some advantages:

  • Support for any timezone, including UTC and local time (no timezone specified).
  • Choice of standard (2007-02-27) and compact (20070227) output.

The dojo.date.toRfc3339() method is only called by four widgets in the trunk: DatePicker?, TimePicker?, DropdownDatePicker?, and DropdownTimePicker?. In all four cases it is easy to replace the toRfc3339() call with a toIso8601*() call.

I revised my patch to have toRfc3339() call toIso8601*() methods, in order to avoid redundancy. If the choice has to be made between RFC3339 and ISO8601 methods, I think that the ISO methods should be preferred because of their greater flexibility. Although the existing fromIso8601*() and setIso8601*() methods don't seem to be used in the trunk, they are good pieces of code with nice unit test coverage. Adding matching toIso8601*() methods makes sense to me.

comment:4 Changed 12 years ago by Adam Peller

Resolution: wontfix
Status: newclosed

Hi James.

I think most of this was covered by #3007, except for the ability to serialize to arbitrary timezones. Do you think it's sufficient to be able to output a choice of the local time zone or UTC?

Let me know if you have suggestions/issues with the new code.

Note: See TracTickets for help on using tickets.