From 52d22cc68a57dc678541f5dcb9359ee50914102b Mon Sep 17 00:00:00 2001 From: Carson Full Date: Fri, 20 Dec 2024 12:26:52 -0600 Subject: [PATCH] Fix CalendarDate.fromJSDate mistakenly applying timezone conversions --- src/common/temporal/calendar-date.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/temporal/calendar-date.ts b/src/common/temporal/calendar-date.ts index 24635134f5..76ae5616ab 100644 --- a/src/common/temporal/calendar-date.ts +++ b/src/common/temporal/calendar-date.ts @@ -5,6 +5,7 @@ import { DateTimeOptions, DateTimeUnit, DurationLike, + FixedOffsetZone, LocaleOptions, ToISOTimeOptions, Zone, @@ -60,7 +61,12 @@ export class CalendarDate } static fromJSDate(date: Date, options?: DateTimeJSOptions): CalendarDate { - return CalendarDate.fromDateTime(super.fromJSDate(date, options)); + const d = super + .fromJSDate(date, options) + // Undo the conversion to the local timezone and restore the original one + // This way pulling the year/month/day below ignores timezone differences. + .setZone(FixedOffsetZone.instance(date.getTimezoneOffset())); + return CalendarDate.local(d.year, d.month, d.day); } static fromMillis(ms: number, options?: DateTimeOptions): CalendarDate {