WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
3381
Date.prototype.setDate() incorrect for values >=128
https://bugs.webkit.org/show_bug.cgi?id=3381
Summary
Date.prototype.setDate() incorrect for values >=128
Gavin Kistner
Reported
2005-06-09 07:01:21 PDT
var d = new Date; var out = "Today: " + d + "\n"; d.setDate( d.getDate() + 280 ) out += "Future: " + d; Should result in a date 280 days in the future. This works on Firefox and IE: Today: Thu Jun 09 2005 07:59:31 GMT-0600 (MDT) Future: Thu Mar 16 2006 07:59:31 GMT-0700 (MST) but fails on the latest version of Safari (2.0.412): Today: Thu Jun 09 2005 08:00:45 GMT-0600 Future: Sun Jul 03 2005 08:00:45 GMT-0600
Attachments
Patch
(621 bytes, patch)
2005-07-23 11:43 PDT
,
Geoffrey Garen
darin
: review+
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Gavin Kistner
Comment 1
2005-06-12 17:21:11 PDT
The failure seems to be with date values greater than 127. This test code: var out = ''; for ( var i=1; i<300; ++i ) { var theDate = new Date; var theValue = theDate.getDate( ) + i; theDate.setDate( theValue ); out += theValue + '::' + theDate + '\n'; } produces the following output (values from 1..120 are contiguous from the current date): 121::Thu Sep 29 2005 18:19:59 GMT-0600 122::Fri Sep 30 2005 18:19:59 GMT-0600 123::Sat Oct 01 2005 18:19:59 GMT-0600 124::Sun Oct 02 2005 18:19:59 GMT-0600 125::Mon Oct 03 2005 18:19:59 GMT-0600 126::Tue Oct 04 2005 18:19:59 GMT-0600 127::Wed Oct 05 2005 18:19:59 GMT-0600 128::Sun Jan 23 2005 18:19:59 GMT-0700 129::Mon Jan 24 2005 18:19:59 GMT-0700 130::Tue Jan 25 2005 18:19:59 GMT-0700 131::Wed Jan 26 2005 18:19:59 GMT-0700 132::Thu Jan 27 2005 18:19:59 GMT-0700 133::Fri Jan 28 2005 18:19:59 GMT-0700
Geoffrey Garen
Comment 2
2005-07-23 11:43:27 PDT
Created
attachment 3067
[details]
Patch The problem is overflow. CFGregorianDate is only an 8-bit signed value. This patch fixes setDate, but setMonth, setYear, and setFullYear still have the same problem.
Geoffrey Garen
Comment 3
2005-07-23 11:46:33 PDT
(In reply to
comment #2
) [ Should read: } In CFGregorianDate, month, day, hour, and minute are 8-bit signed values. SetMonth still has the same problem.
Darin Adler
Comment 4
2005-07-25 11:56:22 PDT
Comment on
attachment 3067
[details]
Patch Looks good, r=me.
William Coldwell (Cryo)
Comment 5
2005-08-07 10:04:01 PDT
For some reason the code is thinking my current date is epoch instead of Sun Aug 7 13:02:14 EDT 2005 so the check fails because the year is wrong? This test checks for regression against: 3381 Date.prototype.setDate() incorrect for values >=128. If the test passes, all the dates below will be sequential. setDate(120): Mon Mar 30 1970 19:00:00 GMT-0500 setDate(121): Tue Mar 31 1970 19:00:00 GMT-0500 setDate(122): Wed Apr 01 1970 19:00:00 GMT-0500 setDate(123): Thu Apr 02 1970 19:00:00 GMT-0500 setDate(124): Fri Apr 03 1970 19:00:00 GMT-0500 setDate(125): Sat Apr 04 1970 19:00:00 GMT-0500 setDate(126): Sun Apr 05 1970 19:00:00 GMT-0500 setDate(127): Mon Apr 06 1970 19:00:00 GMT-0500 setDate(128): Tue Apr 07 1970 19:00:00 GMT-0500 setDate(129): Wed Apr 08 1970 19:00:00 GMT-0500
Geoffrey Garen
Comment 6
2005-08-07 12:56:50 PDT
The output doesn't look like a failure -- all the dates are sequential, as they should be. The test also has nothing to do with your current date. The year should be 1970, since the constructor call is new Date(0). Subsequently, setDate(120) gives the 120th day in 1970, which is Mar 30. This test also doesn't fail when I execute run-webkit-tests. Changing resolution to FIXED.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug