|
View:
New views
16 Messages
—
Rating Filter:
Alert me
|
|
|
Date.prototype.toISOString and Invalid DateWhat is the expected result of calling toISOString on a date where the
year is NaN? var d = new Date(NaN); d.toISOString(); ? Garrett _______________________________________________ es-discuss mailing list es-discuss@... https://mail.mozilla.org/listinfo/es-discuss |
||||||||||
|
|
RE: Date.prototype.toISOString and Invalid DateCurrently, implementations are inconsistent about what they produce for (new Date(NaN).toString()).
IE and Opera produce "NaN", while FF and Safari produce "Invalid Date". Since toISOString is a new function, we have the opportunity to specify what we want the result to be. Does anybody have an opinion. It could be either "NaN" or "Invalid Date" or something else. "Invalid Date" has the advantage that it is more end-user meaningful if it actually leaks through to be visible on a web page (although that is a pretty Anglo-centric perspective). Unless, I here strong opinions otherwise I think I'll go with "Invalid Date". Allen >-----Original Message----- >From: es-discuss-bounces@... [mailto:es-discuss- >bounces@...] On Behalf Of Garrett Smith >Sent: Saturday, June 06, 2009 12:40 AM >To: es-discuss >Subject: Date.prototype.toISOString and Invalid Date > >What is the expected result of calling toISOString on a date where the >year is NaN? > >var d = new Date(NaN); >d.toISOString(); > >? > >Garrett >_______________________________________________ >es-discuss mailing list >es-discuss@... >https://mail.mozilla.org/listinfo/es-discuss _______________________________________________ es-discuss mailing list es-discuss@... https://mail.mozilla.org/listinfo/es-discuss |
||||||||||
|
|
Re: Date.prototype.toISOString and Invalid DateIf the spec says that toISOString() must return a certain value that
doesn't parse according to 15.9.1.15 maybe, for symmetry, it should also say what Date.parse should do when passed that value? On Wed, Jun 10, 2009 at 3:06 AM, Allen Wirfs-Brock<Allen.Wirfs-Brock@...> wrote: > Currently, implementations are inconsistent about what they produce for (new Date(NaN).toString()). > IE and Opera produce "NaN", while FF and Safari produce "Invalid Date". > > Since toISOString is a new function, we have the opportunity to specify what we want the result to be. > > Does anybody have an opinion. It could be either "NaN" or "Invalid Date" or something else. "Invalid Date" has the advantage that it is more end-user meaningful if it actually leaks through to be visible on a web page (although that is a pretty Anglo-centric perspective). > > Unless, I here strong opinions otherwise I think I'll go with "Invalid Date". > > Allen > >>-----Original Message----- >>From: es-discuss-bounces@... [mailto:es-discuss- >>bounces@...] On Behalf Of Garrett Smith >>Sent: Saturday, June 06, 2009 12:40 AM >>To: es-discuss >>Subject: Date.prototype.toISOString and Invalid Date >> >>What is the expected result of calling toISOString on a date where the >>year is NaN? >> >>var d = new Date(NaN); >>d.toISOString(); >> >>? >> >>Garrett >>_______________________________________________ >>es-discuss mailing list >>es-discuss@... >>https://mail.mozilla.org/listinfo/es-discuss > > _______________________________________________ > es-discuss mailing list > es-discuss@... > https://mail.mozilla.org/listinfo/es-discuss > es-discuss mailing list es-discuss@... https://mail.mozilla.org/listinfo/es-discuss |
||||||||||
|
|
RE: Date.prototype.toISOString and Invalid DateI 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.
Currently, implementations are inconsistent about what they produce for (new Date(NaN).toString()). IE and Opera produce "NaN", while FF and Safari produce "Invalid Date". Since toISOString is a new function, we have the opportunity to specify what we want the result to be. Does anybody have an opinion. It could be either "NaN" or "Invalid Date" or something else. "Invalid Date" has the advantage that it is more end-user meaningful if it actually leaks through to be visible on a web page (although that is a pretty Anglo-centric perspective). Unless, I here strong opinions otherwise I think I'll go with "Invalid Date". Allen >-----Original Message----- >From: es-discuss-bounces@... [... >bounces@...] On Behalf Of Garrett Smith >Sent: Saturday, June 06, 2009 12:40 AM >To: es-discuss >Subject: Date.prototype.toISOString and Invalid Date > >What is the expected result of calling toISOString on a date where the >year is NaN? > >var d = new Date(NaN); >d.toISOString(); > >? > >Garrett >_______________________________________________ >es-discuss mailing list >es-discuss@... >https://mail.mozilla.org/listinfo/es-discuss _______________________________________________ es5-discuss mailing list es5-discuss@... https://mail.mozilla.org/listinfo/es5-discuss _______________________________________________ es-discuss mailing list es-discuss@... https://mail.mozilla.org/listinfo/es-discuss |
||||||||||
|
|
|
06/10/2009 11:21 AM |
|
This would also imply that (new Date(NaN).toJSON()) also throws. Is everybody fine with that??
Date.prototype.toJSON is defined (using pseudo code) to be generally
equivalent to
return this.toISOString();
From: Mark S. Miller
[mailto:erights@...]
Sent: Wednesday, June 10, 2009 11:04 AM
To: Allen Wirfs-Brock
Cc: Brendan Eich; es5-discuss@...; es-discuss@...
Subject: Re: Date.prototype.toISOString and Invalid Date
On Wed, Jun 10, 2009 at 11:00 AM, Allen Wirfs-Brock <Allen.Wirfs-Brock@...>
wrote:
This would also imply that (new Date(NaN).toJSON()) also throws. Is everybody fine with that??
I must be missing something. How does that follow?
--
Cheers,
--MarkM
Douglas Crockford writes:
>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.
>
>I think this is what exceptions are for.
>An English string makes little sense.
>NaN is nonsense.
For toISOString I also favor an exception. The toString reference threw me off, since toString would not be able to throw in the invalid case and remain compatible. toString Implementations could certainly call toISOString, catch the exception, and choose some nonsensical, unspecified replacement, in which case we don't address the browser deviations, and that's probably fine. At one point, I think we discussed providing guidance for toString implementations to use toISOString. Was that deemed too likely to cause compatibility issues, or is it better to just leave the specification open here?
-Adam
_______________________________________________
es-discuss mailing list
es-discuss@...
https://mail.mozilla.org/listinfo/es-discuss
| Free embeddable forum powered by Nabble | Forum Help |