Skip to content

Commit 42a0a9f

Browse files
Copilottsmarvin
andcommitted
refactor: replace legacy Date usage with proper Temporal API implementation
Co-authored-by: tsmarvin <[email protected]>
1 parent ab8d79b commit 42a0a9f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/scripts/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,9 +1329,11 @@ function initializeTimezoneData(year: number = Temporal.Now.plainDateISO().year)
13291329
// Get all supported timezones (comprehensive list)
13301330
const allTimezones = Intl.supportedValuesOf('timeZone');
13311331

1332-
// Create dates for June 1st and December 31st to capture DST variations
1333-
const juneDate = new Date(year, 5, 1); // June 1st
1334-
const decemberDate = new Date(year, 11, 31); // December 31st
1332+
// Create dates for June 1st and December 31st to capture DST variations using Temporal
1333+
const junePlainDate = Temporal.PlainDate.from({ year, month: 6, day: 1 });
1334+
const decemberPlainDate = Temporal.PlainDate.from({ year, month: 12, day: 31 });
1335+
const juneDate = new Date(junePlainDate.toZonedDateTime(Temporal.Now.timeZoneId()).epochMilliseconds);
1336+
const decemberDate = new Date(decemberPlainDate.toZonedDateTime(Temporal.Now.timeZoneId()).epochMilliseconds);
13351337

13361338
console.log(`Processing ${allTimezones.length} timezones for June and December variants...`);
13371339

@@ -1499,9 +1501,13 @@ export function getAllTimezonesOrdered(date?: Date): TimeZone[] {
14991501
function getTimezoneVariations(iana: string, year: number = Temporal.Now.plainDateISO().year): TimeZone[] {
15001502
const variations: TimeZone[] = [];
15011503

1502-
// Use June 1st for summer time and December 31st for winter time
1503-
const summerDate = new Date(year, 5, 1); // June 1st
1504-
const winterDate = new Date(year, 11, 31); // December 31st
1504+
// Use June 1st for summer time and December 31st for winter time using Temporal
1505+
const summerPlainDate = Temporal.PlainDate.from({ year, month: 6, day: 1 });
1506+
const winterPlainDate = Temporal.PlainDate.from({ year, month: 12, day: 31 });
1507+
1508+
// Convert to Date objects for Intl.DateTimeFormat compatibility
1509+
const summerDate = new Date(summerPlainDate.toZonedDateTime(Temporal.Now.timeZoneId()).epochMilliseconds);
1510+
const winterDate = new Date(winterPlainDate.toZonedDateTime(Temporal.Now.timeZoneId()).epochMilliseconds);
15051511

15061512
for (const date of [summerDate, winterDate]) {
15071513
const formatter = new Intl.DateTimeFormat('en', {

0 commit comments

Comments
 (0)