arshaw / xdate

A Modern JavaScript Date Library
http://arshaw.com/xdate/
GNU General Public License v2.0
681 stars 81 forks source link

Fix set utc week 53 #18

Closed timruffles closed 11 years ago

timruffles commented 11 years ago

Hello. Thanks for the library. Came across an edge case in setUTCWeek. If we're on 2009-W53-07 (Sun 3 Jan 2010) and we call getUTCWeek() we get 53, as we should.

However, if we then call setUTCWeek(53) we'll get a totally different date back - Mon, 03 Jan 2011 00:00:00 GMT.

I changed setUTCWeek to use a new function getUTCWeekNumberingYear() (nomenclature source) which'll return 2009 for UTC(2010,1,3). This then gets us to 2009-W53-01 as the documentation states.

There's 2 commits in the PR - the first that fails, the second that passes with the new code.

arshaw commented 11 years ago

i rebased this onto master. afterwards, i restructured things a little so that getWeek/setWeek shared the common logic calculating the current week's year. thanks for finding this bug and providing a fix.