From: Hans-Georg Michna on
On Thu, 8 Oct 2009 09:59:46 +0100, Richard Cornford wrote:

>The Date object's - valueOf - method returns its 'time value', which is
>the millisecond value. Any process specified as calling the - valueOf -
>methods of objects will see this numeric value, including, for example,
>step 1 in "The Abstract Relational Comparison Algorithm" (11.8.5), where
>it reads "Call ToPrimitive(x, hint Number)". All other
>type-converting-to-number processes applied to a date object will call
>its - valueOf - method and use the result.

Richard,

thanks. I understand all that. I just cannot find it in any
official specification.

If there is any place in the official documentation, like the
Gecko DOM docs, where it is explicitly and unambiguously said
that on a Date instance the .valueOf() method returns the time
in milliseconds, I must have overlooked it.

Moreover, in the case I remembered somebody didn't even use
..valueOf(). There I saw a direct comparison of two Date
instances, and I thought that some programmers must be bold to
rely on something like that.

Where does it say that an expression like date1 < date2 converts
to numbers? The < operator does not only work on numbers. It
works, for example, on strings, so it would not be entirely
inconceivable that the dates would be converted to strings, then
compared. Semantic nonsense, but who says that a programming
language processor has to be intelligent? (:-)

But it is well possible that I have overlooked the relevant
documentation or severely misunderstood it. On the other hand,
if I misunderstand it, then some others will also misunderstand
it.

Hans-Georg
From: Dr J R Stockton on
In comp.lang.javascript message <vu5rc5563vrjdrifr9voh68jgf7fevn6co(a)4ax.
com>, Thu, 8 Oct 2009 09:54:56, Hans-Georg Michna <hans-
georgNoEmailPlease(a)michna.com> posted:
>On Wed, 7 Oct 2009 20:33:56 +0100, Dr J R Stockton wrote:
>
>>You could have read <URL:http://www.merlyn.demon.co.uk/js=-date0.htm#DC>
>>instead of asking.
>
>Could you check the link? I get Page not found (404). Perhaps a
>little typo.

Sorry, <URL:http://www.merlyn.demon.co.uk/js-date0.htm#DC> - though you
could have found it via my sig.

>However, even if that page explains very well how Date behaves,
>it is still not an official specification, or is it? I mean, who
>guarantees that Date will still behave that way in the next new
>browser or browser version?

The newsgroup FAQ and <URL:http://www.merlyn.demon.co.uk/js-dates.htm>
have links to the current and draft future standards. They define how
browsers (etc.) ought to behave.

There is IMHO no likelihood that the long-established general properties
of Date will be changed in the Standard; but other properties will,
should, and may be added.

Page <URL:http://www.merlyn.demon.co.uk/js-datex.htm> shows a number of
bugs which ought to be removed from future versions of browsers.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
From: Richard Cornford on
Hans-Georg Michna wrote:
> Richard Cornford wrote:
>
>> The Date object's - valueOf - method returns its 'time value',
>> which is the millisecond value. Any process specified as
>> calling the - valueOf - methods of objects will see this
>> numeric value, including, for example, step 1 in "The
>> Abstract Relational Comparison Algorithm" (11.8.5), where
>> it reads "Call ToPrimitive(x, hint Number)". All other
>> type-converting-to-number processes applied to a date
>> object will call its - valueOf - method and use the
>> result.
>
> Richard,
>
> thanks. I understand all that. I just cannot find it in any
> official specification.
>
> If there is any place in the official documentation, like the
> Gecko DOM docs,

What would the documentation for a DOM implementation have to do with
javascript behaviour?

> where it is explicitly and unambiguously said
> that on a Date instance the .valueOf() method returns
> the time in milliseconds, I must have overlooked it.

ECMA 262 3rd Ed. Section 15.9.5.8 asserts the behaviour for the -
valueOf - method of date objects.

> Moreover, in the case I remembered somebody didn't even use
> .valueOf().

As I said, the use of a object's - valueOf - function is implied in
some type-conversion to primitive operations. When the operation is
type-conversion to a numeric primitive and the - valueOf - operation
returns a numeric type primitive value then that value is always the
result of the type-conversion. Relational comparison implies a
type-conversion operation on any operands that are not primitive type
values, that type-conversion uses 'hint Number' so any object type
operands will have their - valueOf - methods called (if they have such).

> There I saw a direct comparison of two Date instances, and
> I thought that some programmers must be bold to rely on
> something like that.

Familiarity with the language, its specification and implementations,
would be sufficient to justify that action.

> Where does it say that an expression like date1 < date2 converts
> to numbers?

In steps 1 and 2 of "The Abstract Relational Comparison Algorithm" (ECMA
262 3rd Ed. Section 11.8.5), then in the algorithm for - ToPrimative -
(Section 9.1), then steps 4 and 5 of the "The Abstract Relational
Comparison Algorithm", and back to Section 9.3 for the - ToNumber -
behaviour.

> The < operator does not only work on numbers. It
> works, for example, on strings, so it would not be
> entirely inconceivable that the dates would be converted
> to strings, then compared.

Not inconceivable, but also not the way the behaviour was specified.

> Semantic nonsense, but who says that a programming
> language processor has to be intelligent? (:-)
>
> But it is well possible that I have overlooked the relevant
> documentation or severely misunderstood it.

It is frankly bizarre that you did not know where to look, it is hardly
a secret that ECMA 262 is the applicable specification.

> On the other hand, if I misunderstand it, then some others will
> also misunderstand it.

Yes, and some of them will make out that they know what they are doing
despite that misunderstanding.

Richard.

From: Garrett Smith on
Dr J R Stockton wrote:
> In comp.lang.javascript message <haj2vd$j23$1(a)news.eternal-
> september.org>, Wed, 7 Oct 2009 14:59:03, Garrett Smith
> <dhtmlkitchen(a)gmail.com> posted:
>> John G Harris wrote:
>>> On Mon, 5 Oct 2009 at 19:43:47, in comp.lang.javascript, Dr J R Stockton
>>> wrote:
>>>> In comp.lang.javascript message <4ac928fb$0$289$14726298(a)news.sunsite.dk
>>>>> , Sun, 4 Oct 2009 23:00:03, FAQ server <javascript(a)dotinternet.be>
>>>> posted:
>>>>

[...]
>>> Strictly speaking, the Date Object is the object named Date : the
>>> constructor you use when you do new Date().
>>>
>> And one of those is "a Date".
>>
>> A Date *is* and Object. Adding "Object" is redundant.
>
correction: A Date *is* an Object.

> It is not superfluous, since "date" is an ordinary English word and may
> also be used with that meaning - and in a natural language a little
> redundancy is often a great help in transferring a meaning without
> either error or doubt.
>
In context of a javascript FAQ, capitalized "Date" seems obvious to me.
Are there others who feel it is confusing?
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Hans-Georg Michna on
On Fri, 9 Oct 2009 00:08:28 +0100, Richard Cornford wrote:

>What would the documentation for a DOM implementation have to do with
>javascript behaviour?

Sorry, in this case it would, of course, be the documentation of
the JavaScript implementation or perhaps any general
specification of the language.

>Hans-Georg Michna wrote:

>> where it is explicitly and unambiguously said
>> that on a Date instance the .valueOf() method returns
>> the time in milliseconds, I must have overlooked it.

>ECMA 262 3rd Ed. Section 15.9.5.8 asserts the behaviour for the -
>valueOf - method of date objects.
>[...]
>As I said, the use of a object's - valueOf - function is implied in
>some type-conversion to primitive operations. When the operation is
>type-conversion to a numeric primitive and the - valueOf - operation
>returns a numeric type primitive value then that value is always the
>result of the type-conversion. Relational comparison implies a
>type-conversion operation on any operands that are not primitive type
>values, that type-conversion uses 'hint Number' so any object type
>operands will have their - valueOf - methods called (if they have such).
>[...]
>Familiarity with the language, its specification and implementations,
>would be sufficient to justify that action.

Perhaps my excuse can be that I've delved deeper into JavaScript
only about a month ago, with some earlier, more superficial
excursions earlier this year. (Anyway, I find JavaScript
fascinating.)

>> Where does it say that an expression like date1 < date2 converts
>> to numbers?

>In steps 1 and 2 of "The Abstract Relational Comparison Algorithm" (ECMA
>262 3rd Ed. Section 11.8.5), then in the algorithm for - ToPrimative -
>(Section 9.1), then steps 4 and 5 of the "The Abstract Relational
>Comparison Algorithm", and back to Section 9.3 for the - ToNumber -
>behaviour.

Thanks, found it. Good to know! Makes my future JavaScript
programs shorter and more concise.

>It is frankly bizarre that you did not know where to look, it is hardly
>a secret that ECMA 262 is the applicable specification.

Won't happen again. Downloaded, reading. Perhaps I've looked at
the Mozilla Gecko docs too much. Even looked at the MSDN JScript
stuff, which is a bit better organized, but proprietary.

Thanks again. This discussion is helpful for me.

Hans-Georg
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Prev: Computer Techs Wanted
Next: move div by drag etc.