Skip to content

Commit

Permalink
Fix CalendarDate.fromJSDate mistakenly applying timezone conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed Dec 20, 2024
1 parent ec30c04 commit 52d22cc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/common/temporal/calendar-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DateTimeOptions,
DateTimeUnit,
DurationLike,
FixedOffsetZone,
LocaleOptions,
ToISOTimeOptions,
Zone,
Expand Down Expand Up @@ -60,7 +61,12 @@ export class CalendarDate<IsValid extends boolean = DefaultValidity>
}

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 {
Expand Down

0 comments on commit 52d22cc

Please sign in to comment.