Last active
September 23, 2024 09:59
-
-
Save liam-jones-lucout/1c8b19ad6fcaf4103bb4b6af97877cd7 to your computer and use it in GitHub Desktop.
Is British Summer time BST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function isBritishSummerInEffect(date: Date) { | |
const possibleBstHour = parseInt( | |
date | |
.toLocaleTimeString("en-GB", { timeZone: "Europe/London" }) | |
.split(":")[0], | |
); | |
const utcHour = date.getUTCHours(); | |
return possibleBstHour !== utcHour; | |
} | |
export function isCurrentlyBritishSummerTime() { | |
return isBritishSummerInEffect(new Date()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice spot! Where I initially used this just checked if BST was currently in effect. I added the date argument as a quick upgrade, but forgot to update that line. Cheers 👍