From eb315dc5da42bb1f2b437774b36eea9b927ae790 Mon Sep 17 00:00:00 2001 From: Justin Schroeder Date: Wed, 26 Jun 2024 16:54:07 -0400 Subject: [PATCH] fix: timezone offsets in 1904 (#59) --- src/format.ts | 8 +++++++- src/offset.ts | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/format.ts b/src/format.ts index c2a8ddf..7777b14 100644 --- a/src/format.ts +++ b/src/format.ts @@ -1,7 +1,13 @@ import { date } from "./date" import { parts } from "./parts" import { fill, getOffsetFormat } from "./common" -import type { DateInput, Format, FormatOptions, FormatStyle, Part } from "./types" +import type { + DateInput, + Format, + FormatOptions, + FormatStyle, + Part, +} from "./types" import { offset } from "./offset" import { removeOffset } from "./removeOffset" import { deviceLocale } from "./deviceLocale" diff --git a/src/offset.ts b/src/offset.ts index 939d394..1f2f484 100644 --- a/src/offset.ts +++ b/src/offset.ts @@ -50,12 +50,14 @@ export function offset( utcTime: DateInput, tzA = "UTC", tzB = "device", - timeZoneToken: TimezoneToken = "Z" , + timeZoneToken: TimezoneToken = "Z" ): string { tzB = tzB === "device" ? deviceTZ() ?? "utc" : tzB const d = date(utcTime) const timeA = relativeTime(d, tzA) const timeB = relativeTime(d, tzB) - const timeDiffInMins = (timeB.getTime() - timeA.getTime()) / 1000 / 60 + const timeDiffInMins = Math.round( + (timeB.getTime() - timeA.getTime()) / 1000 / 60 + ) return minsToOffset(timeDiffInMins, timeZoneToken) }