Bug 92782 - Error in Date.setMonth()
Summary: Error in Date.setMonth()
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-31 12:10 PDT by rgunnyon
Modified: 2012-08-02 09:04 PDT (History)
1 user (show)

See Also:


Attachments
Demonstrates the failure in setMonth() (579 bytes, text/html)
2012-08-01 13:07 PDT, rgunnyon
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description rgunnyon 2012-07-31 12:10:40 PDT
There is an error in setMonth that seems to crop up on even numbered months.

This is taken from the console of the nightly build:

d=new Date()
Tue Jul 31 2012 11:32:27 GMT-0700 (Pacific Daylight Time)
d.getMonth()
6
d.setMonth(8)
1349116347499
d
Mon Oct 01 2012 11:32:27 GMT-0700 (Pacific Daylight Time)
d.setMonth(8)
1346524347499
d
Sat Sep 01 2012 11:32:27 GMT-0700 (Pacific Daylight Time)

Setting the month to the same value twice had an incorrect setting first, then the correct setting.
Comment 1 Alexey Proskuryakov 2012-08-01 12:44:21 PDT
I cannot reproduce this.

Could you please attach a complete HTML test case that can be opened to easily see a pass/fail result?
Comment 2 rgunnyon 2012-08-01 13:07:08 PDT
Created attachment 155865 [details]
Demonstrates the failure in setMonth()

This bug appears if you set the month to an even value when the current date is the 31st day of a month.
A second call sets the correct value.
Comment 3 rgunnyon 2012-08-02 09:04:23 PDT
I poked at it a bit more, this appears to be a 'gotcha' with date normalization.
From the 31st, setting the month to one that doesn't have a 31st day triggers the shift to 1st, 2nd or 3rd of the next month. The second call to setmonth sets it to the 1st, 2nd or 3rd of the correct month.