From 067ae77ad962bf5b45ea72a3d4fa90a266a157a1 Mon Sep 17 00:00:00 2001 From: Alexandr Nikitin Date: Thu, 26 Mar 2015 21:43:57 +0200 Subject: [PATCH] Fix day number calculation taking DST into account Based on the SO answer http://stackoverflow.com/a/15289883/974487 --- strftime.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/strftime.js b/strftime.js index 37635ab..c05c3f0 100644 --- a/strftime.js +++ b/strftime.js @@ -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);