From 002ac8ca4c782cd351c0f10943c1aa501fbb9930 Mon Sep 17 00:00:00 2001 From: Alexandr Nikitin Date: Thu, 26 Mar 2015 21:40:46 +0200 Subject: [PATCH 1/2] Add field report tests for bug in %U in #56 --- test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test.js b/test.js index 0b0a974..5b6fd62 100755 --- a/test.js +++ b/test.js @@ -115,6 +115,9 @@ assert.format('%z', null, '+0000'); assert.format('%:z', null, '+00:00'); assert.format('%%', '%'); // any other char assert.format('%F %T', null, '1970-01-01 00:00:00', new Date(0)); +assert.format('%U', '13', "12", (new Date('03-26-2017 00:00:00'))); +assert.format('%U', '13', null, (new Date('03-27-2017 00:00:00'))); +assert.format('%U', '14', "13", (new Date('04-02-2017 00:00:00'))); ok('GMT'); From 067ae77ad962bf5b45ea72a3d4fa90a266a157a1 Mon Sep 17 00:00:00 2001 From: Alexandr Nikitin Date: Thu, 26 Mar 2015 21:43:57 +0200 Subject: [PATCH 2/2] 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);