Document limitation of getTimezoneOffsetMinutes helper
This commit is contained in:
@@ -2,9 +2,14 @@
|
|||||||
// HAFAS returns times in Vienna (CET/CEST). This module provides correct parsing
|
// HAFAS returns times in Vienna (CET/CEST). This module provides correct parsing
|
||||||
// regardless of the server or browser timezone.
|
// regardless of the server or browser timezone.
|
||||||
|
|
||||||
// Helper: get the offset (in minutes) from UTC for a given instant in a specific IANA timezone.
|
// Helper: get the offset (in minutes) from UTC for a given instant in a specific
|
||||||
// Reads the hour via Intl.DateTimeFormat in both UTC and the target timezone, then
|
// IANA timezone.
|
||||||
// computes the difference. Handles midnight wraparound (e.g. UTC 23:xx → TZ 01:xx).
|
//
|
||||||
|
// CAVEAT — Hour-level precision only. This helper reads the hour via
|
||||||
|
// Intl.DateTimeFormat (hour part only), so it returns incorrect results for
|
||||||
|
// timezones with fractional-hour offsets (e.g. India +05:30, Nepal +05:45).
|
||||||
|
// It is designed exclusively for "Europe/Vienna" (CET/CEST), which only uses
|
||||||
|
// full-hour offsets (+01:00 / +02:00). Do not reuse for other timezones.
|
||||||
function getTimezoneOffsetMinutes(instant: Date, tz: string): number {
|
function getTimezoneOffsetMinutes(instant: Date, tz: string): number {
|
||||||
const getHour = (timeZone: string) => {
|
const getHour = (timeZone: string) => {
|
||||||
const parts = new Intl.DateTimeFormat("en-US", {
|
const parts = new Intl.DateTimeFormat("en-US", {
|
||||||
|
|||||||
Reference in New Issue
Block a user