Bug 92782

Summary: Error in Date.setMonth()
Product: WebKit Reporter: rgunnyon
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED INVALID    
Severity: Normal CC: ap
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Demonstrates the failure in setMonth() none

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.