From decdf8724c302bea10676237e92d5a3a39589bf8 Mon Sep 17 00:00:00 2001 From: Sophie Kirschner Date: Tue, 31 Dec 2019 10:39:34 +0200 Subject: [PATCH] Ah, that's why it broke - update changlog, documenting comments --- changelog.md | 2 +- src/parse.js | 4 ++-- test/canary-test.js | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/changelog.md b/changelog.md index e57f5a8..6e5c509 100644 --- a/changelog.md +++ b/changelog.md @@ -2,7 +2,7 @@ Fourth release. 31 December 2019. -- Workaround for issue related to Date.setUTCMonth causing misbehavior on New Year's Eve. +- Fix issue related to calling Date.setUTCMonth on the 31st day of the month. # v1.1.1 diff --git a/src/parse.js b/src/parse.js index ff12122..c3d81e9 100644 --- a/src/parse.js +++ b/src/parse.js @@ -202,9 +202,9 @@ class TimestampParser{ date.setUTCFullYear(this.year); } if(this.month !== undefined){ - // Workaround fixes New Year's Eve issue for some reason // https://github.com/pineapplemachine/strtime-js/issues/5 - date.setUTCMonth(1); + // https://stackoverflow.com/questions/26681313/javascript-setutcmonth-does-not-work-for-november + date.setUTCMonth(0, 1); date.setUTCMonth(this.month - 1); } if(this.dayOfMonth !== undefined){ diff --git a/test/canary-test.js b/test/canary-test.js index 2b75b2f..cbc11ed 100644 --- a/test/canary-test.js +++ b/test/canary-test.js @@ -8,9 +8,9 @@ const dayjs = require("dayjs"); function getDate(options){ const date = new Date(); date.setFullYear(options.year !== undefined ? options.year : 2000); - // Workaround fixes New Year's Eve issue for some reason // https://github.com/pineapplemachine/strtime-js/issues/5 - date.setMonth(1); + // https://stackoverflow.com/questions/26681313/javascript-setutcmonth-does-not-work-for-november + date.setUTCMonth(0, 1); date.setMonth((options.month || 1) - 1); date.setDate(options.day || 1); date.setHours(options.hour || 0); @@ -23,9 +23,9 @@ function getDate(options){ function getUTCDate(options){ const date = new Date(); date.setUTCFullYear(options.year !== undefined ? options.year : 2000); - // Workaround fixes New Year's Eve issue for some reason // https://github.com/pineapplemachine/strtime-js/issues/5 - date.setUTCMonth(1); + // https://stackoverflow.com/questions/26681313/javascript-setutcmonth-does-not-work-for-november + date.setUTCMonth(0, 1); date.setUTCMonth((options.month || 1) - 1); date.setUTCDate(options.day || 1); date.setUTCHours(options.hour || 0);