Closed Bug 363578 Opened 18 years ago Closed 17 years ago

Date.UTC returns incorrect value if date is less than or equal to 0

Categories

(Core :: JavaScript Engine, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: nanto, Assigned: jag+mozilla)

Details

Attachments

(2 files, 1 obsolete file)

new Date(Date.UTC(2006, 0, 0)).getUTCDate() returns 1 (2006-01-01), but should return 31 (2005-12-31). Other browsers (IE 7, Opera 9 and Safari 2) returns 31. js/src/jsdate.c 594 /* if we got a 0 for 'date' (which is out of range) 595 * pretend it's a 1. (So Date.UTC(1972, 5) works) */ 596 if (array[2] < 1) 597 array[2] = 1; Should check argc. ECMA-262 3rd 15.9.4.3 says "3. If date is supplied use ToNumber(date); else use 1."
1) per 15.9.4.3 step 3, default day-of-month to 1 if missing 2) per 15.9.1.12 step 8, simply add the day-of-month value as-is 3) return NaN if any arg is NaN or infinite 4) use js_DoubleToInteger() instead of floor()
See bug 379104 for the Rhino version of this
Attachment #263105 - Flags: review?(mrbkap)
Comment on attachment 263105 [details] [diff] [review] Same, but with most of the shared code factored out Remove that terribly outdated Win16 comment and r=mrbkap.
Attachment #263105 - Flags: review?(mrbkap) → review+
Comment on attachment 263105 [details] [diff] [review] Same, but with most of the shared code factored out Seeking approval for 1.9. Whoever checks this in, don't forget to remove the Win16 comment.
Attachment #263105 - Flags: approval1.9?
Attachment #263105 - Attachment is obsolete: true
Attachment #275169 - Flags: review?(mrbkap)
Attachment #263105 - Flags: approval1.9?
Attachment #275169 - Flags: review?(mrbkap) → review+
Attachment #275169 - Flags: approval1.9?
Attachment #275169 - Flags: approval1.9? → approval1.9+
jag: thanks for the fix, approved for 1.9! /be
jag: forgot to add, please take assignment of this bug -- you fixed it. /be
Checked in, finally. I'm really sorry for the long delay!
Assignee: general → jag
This should be fixed now.
Status: NEW → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Checking in 15.9.4.3.js; /cvsroot/mozilla/js/tests/ecma_3/Date/15.9.4.3.js,v <-- 15.9.4.3.js initial revision: 1.1
Flags: in-testsuite+
verified fixed 1.9.0 linux/mac*/windows.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: