Skip to content

Instantly share code, notes, and snippets.

@megasmack
Created March 27, 2023 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save megasmack/734455e0f6cfd0bcaf5cf71ab90c9d74 to your computer and use it in GitHub Desktop.
Save megasmack/734455e0f6cfd0bcaf5cf71ab90c9d74 to your computer and use it in GitHub Desktop.
Daylight Savings JavaScript Test
const stdTimezoneOffset = (date) => {
const jan = new Date(date.getFullYear(), 0, 1);
const jul = new Date(date.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
};
const isDstObserved = (date) => date.getTimezoneOffset() < stdTimezoneOffset(date);
const offset = start.getTimezoneOffset();
const start = new Date(start.getTime() - (offset*60*1000));
console.log('isDstObserved(start)', isDstObserved(start));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment