Date.prototype.toISOString and Invalid Date

Allen Wirfs-Brock Allen.Wirfs-Brock at microsoft.com
Wed Jun 10 08:48:03 PDT 2009


I believe that support for ISO dates in ES5 is intended to provide a standard interchange format for dates, not for providing a locale customized format for human consumption.  Since ISO 8601 apparently doesn't provide an encoding for "invalid date/time", arguably new Date(NaN).toISOString() should never be passed to someone expecting a valid ISO date. If that is true, then be best thing to do may be to specify that toISOString throws a RangeError when applied to such Date objects.

Allen

>-----Original Message-----
>From: John Cowan [mailto:cowan at ccil.org]
>Sent: Wednesday, June 10, 2009 8:21 AM
>To: Adam Peller
>Cc: Allen Wirfs-Brock; es5-discuss at mozilla.org; Garrett Smith; es-
>discuss at mozilla.org
>Subject: Re: Date.prototype.toISOString and Invalid Date
>
>Adam Peller scripsit:
>
>> I don't feel strongly on this, but it does strike me as odd that
>> a function intended to avoid culturally-sensitive output would use
>> an English phrase.  I'd lean towards IE/Opera, using notation from
>> ECMAScript that is equally cryptic to all cultures :-)  At least that
>> would be consistent with Number.toString() and would reinforce the
>fact
>> that there are other methods to produce strings in the user's locale.
>
>In fact, "NaN" is an abbreviation of an English phrase, namely "not
>a number".  But neither dates nor date strings are numbers.  What say
>you to "NaD"?
>
>--
>John Cowan                                cowan at ccil.org
>At times of peril or dubitation,          http://www.ccil.org/~cowan
>Perform swift circular ambulation,
>With loud and high-pitched ululation.



More information about the es-discuss mailing list