From 8eaa3fb57d7d5161c1eaaa80df11e299f189c952 Mon Sep 17 00:00:00 2001 From: Benedicte Raae Date: Sun, 5 Dec 2021 12:31:37 +0100 Subject: [PATCH] fix: season bug, closes #26 (#27) * test: add failing test * fix: add 1 year to date and check within interval --- plugin/gatsby-browser.js | 9 +++++++-- plugin/gatsby-browser.test.js | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/plugin/gatsby-browser.js b/plugin/gatsby-browser.js index 42cffb6..2ca6225 100644 --- a/plugin/gatsby-browser.js +++ b/plugin/gatsby-browser.js @@ -22,10 +22,15 @@ export const isSeason = (date, { start, end }) => { endDate = addYears(endDate, 1); } - return isWithinInterval(date, { + const interval = { start: startDate, end: endDate, - }); + }; + + return ( + isWithinInterval(date, interval) || + isWithinInterval(addYears(date, 1), interval) + ); } catch (error) { console.warn( "Problem with @raae/gatsby-plugin-let-it-snow season configuration:", diff --git a/plugin/gatsby-browser.test.js b/plugin/gatsby-browser.test.js index 455670a..0943694 100644 --- a/plugin/gatsby-browser.test.js +++ b/plugin/gatsby-browser.test.js @@ -8,6 +8,20 @@ describe("isSeason", () => { end: "2026-01-10", }) ).toBe(true); + + expect( + isSeason(new Date("January 1"), { + start: "2021-12-01", + end: "2026-01-10", + }) + ).toBe(true); + + expect( + isSeason(new Date("May 17"), { + start: "2021-05-01", + end: "2026-06-10", + }) + ).toBe(true); }); it("outside season even with mismatching years", () => {