From 7b0de98e0bae7f912b31db04edfd9156c8672c21 Mon Sep 17 00:00:00 2001 From: Cory Smith Date: Fri, 21 Jan 2022 21:22:20 -0900 Subject: [PATCH] Fix effectiveStartDate being after effectiveEndDate --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 06de66e..e296d45 100644 --- a/index.js +++ b/index.js @@ -307,9 +307,16 @@ const parseEffectiveDates = str => { const [ year, _ ] = yearAndCycle.split('[') const effectiveStartDate = new Date(`${startMonthDay.trim()} ${year}`) - effectiveStartDate.setUTCHours(0,0,0,0) - const effectiveEndDate = new Date(`${endMonthDay.trim()} ${year}`) + + // If effectiveStartDate does not have a year specified, + // it will default to the same year as effectiveEndDate. + // So if the date range spans Jan 1, roll effectiveStartDate back one year. + if (effectiveStartDate > effectiveEndDate) { + effectiveStartDate.setFullYear(effectiveStartDate.getFullYear() - 1 ); + } + + effectiveStartDate.setUTCHours(0,0,0,0) effectiveEndDate.setUTCHours(0,0,0,0) return { effectiveStartDate, effectiveEndDate }