I have the following test which works locally but fails in CI
import { toDate } from "date-fns-tz"
import { parseISO } from "date-fns"
export function isDST(date) {
const january = new Date(date.getFullYear(), 0, 1).getTimezoneOffset()
const july = new Date(date.getFullYear(), 6, 1).getTimezoneOffset()
return Math.max(january, july) !== date.getTimezoneOffset()
}
// Fails
// Expected: true
// Received: false
it("returns true if dst applies", () => {
const date = toDate(parseISO("2021-03-28 02:00:00"), {
timeZone: "Europe/Amsterdam",
})
expect(isDST(date)).toEqual(true)
})
it("returns false if dst does not apply", () => {
const date = toDate(parseISO("2021-10-31 03:00:00"), {
timeZone: "Europe/Amsterdam",
})
expect(isDST(date)).toEqual(false)
})
How can I make this function work universally? I tried to apply toDate
from date-fns-tz
to the dates inside isDST
but without success, I also tried to switch to parseISO
instead