Skip to content

Commit

Permalink
fix: season bug, closes #26 (#27)
Browse files Browse the repository at this point in the history
* test: add failing test

* fix: add 1 year to date and check within interval
  • Loading branch information
raae authored Dec 5, 2021
1 parent b22a4b2 commit 8eaa3fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions plugin/gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:",
Expand Down
14 changes: 14 additions & 0 deletions plugin/gatsby-browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit 8eaa3fb

Please sign in to comment.