The task is to check if a certain date is a statutory holiday, by comparing a date against a list of known statutory holiday dates.
Here is the JSON list of stat holidays:
{
"provinces": [
{
"name": "Ontario",
"statutory": [
{
"name": "Christmas",
"date": "2025-12-25"
},
]
...
Here is the test:
describe("statHoliday", () => {
test("should identify statutory holiday", () => {
const statDay = new Date("2025-12-25T10:00:00.000");
expect(isStatHoliday(statDay)).toBe(true);
});
});
Here is the function to test the date:
function isStatHoliday(date) {
const dateObject = new Date(date);
const dateString = dateObject.toLocaleDateString();
// "theProvince" here is set to Ontario
return !!theProvince.statutory.find(holiday => holiday.date === dateString);
}
When testing locally, this works fine. When I upload to GitHub, and the tests are run there, it fails:
Expected: true
Received: false
I assume this has something to do with time zones, specifically the routine toLocaleDateString()
, but I'm not sure how to correct this. Locally, I am GMT-4
, and I assume the GitHub server is in UTC?
This issue is likely caused by .toLocaleDateString()
producing different results depending on the machine's locale settings.
The format in your JSON is "YYYY-MM-DD"
, which matches the en-CA
(Canadian English) locale. If you want to keep using .toLocaleDateString()
, you can make the output consistent across machines by explicitly specifying the locale:
const dateString = dateObject.toLocaleDateString("en-CA")
I tested this myself, and it produced the same result as in your json regardless of my system's locale.