Skip to content

Commit

Permalink
Better Timezone Handling (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinFullerNYT authored Aug 3, 2024
1 parent 9a197a8 commit 26bf823
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ async function main() {

core.debug(`Parsed Config: ${JSON.stringify(config, null, 2)}`);

dayjs.tz.setDefault(config.timeZone || "America/New_York");
process(dayjs(), config, logger);
} catch (error) {
core.setFailed(error.message);
Expand Down
4 changes: 2 additions & 2 deletions process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ export function process(

for (const date of schedule.dates) {
const start = dayjs(date, validDateFormats, true /* strict parsing */)
.tz(config.timeZone)
.tz(config.timeZone, true)
.add(schedule.startHour, "hour")
.add(schedule.startMinute || 0, "minute")
.add(schedule.startSecond || 0, "second");

const end = dayjs(date, validDateFormats, true /* strict parsing */)
.tz(config.timeZone)
.tz(config.timeZone, true)
.add(schedule.endHour, "hour")
.add(schedule.endMinute || 0, "minute")
.add(schedule.endSecond || 0, "second");
Expand Down
15 changes: 15 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dayjs.extend(customParseFormat);
dayjs.extend(isSameOrBefore);
dayjs.extend(isSameOrAfter);

dayjs.tz.setDefault("America/New_York");

type Test = {
name: string;
now: dayjs.Dayjs;
Expand Down Expand Up @@ -99,6 +101,19 @@ const tests: Test[] = [
expected: true,
wantScheduleMatch: "LOCK_EARLY_DISMISSAL",
},
{
name: "matches early dismissal in GMT",
now: dayjs()
.year(2024)
.month(7)
.date(9)
.hour(18)
.minute(0)
.second(0)
.tz("GMT", true),
expected: true,
wantScheduleMatch: "LOCK_EARLY_DISMISSAL",
},
];

let failed = false;
Expand Down

0 comments on commit 26bf823

Please sign in to comment.