huncent / datejs

Automatically exported from code.google.com/p/datejs
Other
0 stars 0 forks source link

setWeek produces incorrect results on the last week of the year #139

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Date.today().toString()
"Wed Dec 28 2011 00:00:00 GMT+0400"

Date.today().setWeek(52).toString()
"Mon Dec 24 2012 00:00:00 GMT+0400"

To fix this issue, replace setWeek function code with following (not 100% 
tested):

return this.addDays( (1 - this.getDay() ) % 7).addWeeks(n-this.getWeek());

Date.today().setWeek(52).toString()
"Mon Dec 26 2011 00:00:00 GMT+0400"

Original issue reported on code.google.com by d.chekanov on 28 Dec 2011 at 9:03

GoogleCodeExporter commented 8 years ago
Fixed in the current build in my fork: https://github.com/abritinthebay/datejs/

Used the following btw (using the optional direction flag of moveToDayOfWeek).
return this.addWeeks(n - this.getWeek()).moveToDayOfWeek(1, (this.getDay() > 1 
? -1 : 1));

Original comment by darkcr...@gmail.com on 16 Sep 2013 at 2:10