« Bugzilla Issues Index

#1257 — Make new Date(dateObj) work as expected

1. `new Date(obj)` calls obj.[[DefaultValue]]()

2. Date objects have a special weird [[DefaultValue]] method
that prefers to call .toString() rather than .valueOf().

3. As it happens, Date.prototype.toString() is lossy.
The spec doesn't require it, but implementations don't show milliseconds
in Date toString output and it's unlikely to change.

As a consequence, you can't use new Date(dateObj) to copy a Date object.

Firefox implements this to spec and this causes real-world issues:
However at least Chrome doesn't implement the spec!

Proposal: Special-case this in the Date constructor (

>- 1. Let v be ToPrimitive(value).
>+ 1. If value has a [[DateValue]] property then let v be value.[[DateValue]]; else let v be ToPrimitive(value).

Per Conclusion/Resolution here:

When date object is passed to the Date constructor, it makes an accurate copy of the date object.

fixed in rev15 editor's draft

fixed in rev17, August 23, 2013 draft