Skip to content

Instantly share code, notes, and snippets.

@liam-jones-lucout
Last active September 23, 2024 09:59
Show Gist options
  • Save liam-jones-lucout/1c8b19ad6fcaf4103bb4b6af97877cd7 to your computer and use it in GitHub Desktop.
Save liam-jones-lucout/1c8b19ad6fcaf4103bb4b6af97877cd7 to your computer and use it in GitHub Desktop.
Is British Summer time BST
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())
}
@Twovo
Copy link

Twovo commented Jul 16, 2024

I think this is incorrect, shouldn't line 7 be date.getUTCHours()? Instead of now.getUTCHours()?

@liam-jones-lucout
Copy link
Author

liam-jones-lucout commented Sep 23, 2024

I think this is incorrect, shouldn't line 7 be date.getUTCHours()? Instead of now.getUTCHours()?

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment