Closed
Bug 875668
Opened 12 years ago
Closed 12 years ago
What?! a.getTime() doesn't equal to (new Date(a)).getTime() in Firefox
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
INVALID
People
(Reporter: airpingu, Unassigned)
Details
Please try the following commands in your JS console:
a = new Date()
a.getTime() // shows 1369376858656
(new Date(a)).getTime() // shows 1369376858000
This sounds no good. I don't know who is proper to take this one.
Comment 1•12 years ago
|
||
http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.3.2
> 1. Let v be ToPrimitive(value).
http://www.ecma-international.org/ecma-262/5.1/#sec-9.1
> Object Return a default value for the Object. The default value of an
> object is retrieved by calling the [[DefaultValue]] internal method of the
> object, passing the optional hint PreferredType.
http://www.ecma-international.org/ecma-262/5.1/#sec-8.12.8
> When the [[DefaultValue]] internal method of O is called with no hint, then it
> behaves as if the hint were Number, unless O is a Date object (see 15.9.6), in
> which case it behaves as if the hint were String.
> When the [[DefaultValue]] internal method of O is called with hint String, the following steps are taken:
(Loughly speaking, it will end up with calling O.toString())
http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.5.2
> This function returns a String value. The contents of the String are
> implementation-dependent, but are intended to represent the Date in the
> current time zone in a convenient, human-readable form.
> NOTE For any Date value d whose milliseconds amount is zero, the result of
> Date.parse(d.toString()) is equal to d.valueOf(). See 15.9.4.2.
To wrap up, this is because Firefox don't contain milliseconds in the Date.prototype.toString() result which is allowed by the spec.
If I executes |a.toString = a.toISOString|, |(new Date(a)).getTime()| returned the same value as |a.getTime()|.
You shouldn't rely on implementation-dependent behaviors.
Assignee: nobody → general
Status: NEW → RESOLVED
Closed: 12 years ago
Component: General → JavaScript Engine
Product: Firefox → Core
Resolution: --- → INVALID
Reporter | ||
Comment 2•12 years ago
|
||
OK, I see. Thanks for the info! :)
You need to log in
before you can comment on or make changes to this bug.
Description
•