Calculating week numbers in JS is surprisingly complex
It might be complex because week numbering itself is complicated.
// Round the number of days to the nearest integer // because the number of milliseconds in a week is not constant // (e.g. it's different in the week of the daylight saving time clock shift) return Math.round(diff / MILLISECONDS_IN_WEEK) + 1
I'm glad I haven't had to deal with date stuff much in the past.