I'm working with javascript Date objects and seeing very odd behavior. If I keep setting a date object to another date object + an offset, it starts adding 30 days or so. If I reset the date object in between attempts or if I do the date math on the same object it works as expected.
Probably easier to see the test bed I'm running in the latest chrome/ff:
var date = new Date(); console.log("start:", date); var test = new Date(); test.setDate( date.getDate() + 1 ); console.log("test1:", date, test); test.setDate( date.getDate() + 1 ); console.log("test2:", date, test); test.setDate( date.getDate() + 1 ); console.log("test3:", date, test); test = new Date(); test.setDate( date.getDate() + 1 ); console.log("test reset 1:", date, test); test = new Date(); test.setDate( date.getDate() + 1 ); console.log("test reset 2:", date, test); test = new Date(); test.setDate( date.getDate() + 2 ); console.log("test reset 3:", date, test); test = new Date(); test.setDate( test.getDate() + 1 ); console.log("test selfref 1:", test); test.setDate( test.getDate() + 1 ); console.log("test selfref 2:", test); And the output I get:
"start:" Tue May 31 2011 13:09:13 GMT-0400 (EDT) "test1:" Tue May 31 2011 13:09:13 GMT-0400 (EDT) Wed Jun 01 2011 13:09:13 GMT-0400 (EDT) "test2:" Tue May 31 2011 13:09:13 GMT-0400 (EDT) Sat Jul 02 2011 13:09:13 GMT-0400 (EDT) "test3:" Tue May 31 2011 13:09:13 GMT-0400 (EDT) Mon Aug 01 2011 13:09:13 GMT-0400 (EDT) "test reset 1:" Tue May 31 2011 13:09:13 GMT-0400 (EDT) Wed Jun 01 2011 13:09:13 GMT-0400 (EDT) "test reset 2:" Tue May 31 2011 13:09:13 GMT-0400 (EDT) Wed Jun 01 2011 13:09:13 GMT-0400 (EDT) "test reset 3:" Tue May 31 2011 13:09:13 GMT-0400 (EDT) Thu Jun 02 2011 13:09:13 GMT-0400 (EDT) "test selfref 1:" Wed Jun 01 2011 13:09:13 GMT-0400 (EDT) "test selfref 2:" Thu Jun 02 2011 13:09:13 GMT-0400 (EDT) So you can see that test1-3 the original date object remains the same, but the test object which should always be the original date + 1 day - goes all over the place.
Subsequently the reset tests and the selfref tests seem to work as expected.
Is this a bug or am I misunderstanding something?
felix