Fix day number calculation taking DST into account

Based on the SO answer http://stackoverflow.com/a/15289883/974487
This commit is contained in:
Alexandr Nikitin 2015-03-26 21:43:57 +02:00
parent 002ac8ca4c
commit 067ae77ad9

View file

@ -595,8 +595,10 @@
else
weekday--;
}
var firstDayOfYear = new Date(date.getFullYear(), 0, 1),
yday = (date - firstDayOfYear) / 86400000,
var firstDayOfYearUtc = Date.UTC(date.getFullYear(), 0, 1),
dateUtc = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()),
yday = Math.floor((dateUtc - firstDayOfYearUtc) / 86400000),
weekNum = (yday + 7 - weekday) / 7;
return Math.floor(weekNum);