-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Ensure waiting executions account for workflow timezone (#…
- Loading branch information
Showing
5 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { DateTime } from 'luxon'; | ||
|
||
export function toUtcDate(datetime: Date, tz: string) { | ||
return DateTime.fromISO(datetime.toISOString().slice(0, -1), { zone: tz }).toUTC().toJSDate(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { toUtcDate } from '@/utils'; | ||
|
||
describe('utils', () => { | ||
describe('toUtcDate()', () => { | ||
test('should convert to UTC date by adding', () => { | ||
const originalDate = new Date('2020-01-01T00:00:00.000Z'); | ||
const timezone = 'America/New_York'; // +5 to reach Z | ||
|
||
const utcDate = toUtcDate(originalDate, timezone); | ||
|
||
expect(utcDate).toBeInstanceOf(Date); | ||
expect(utcDate.toISOString()).toBe('2020-01-01T05:00:00.000Z'); | ||
}); | ||
|
||
test('should convert to UTC date by subtracting', () => { | ||
const originalDate = new Date('2020-01-01T00:00:00.000Z'); | ||
const timezone = 'Europe/Paris'; // -1 to reach Z | ||
|
||
const utcDate = toUtcDate(originalDate, timezone); | ||
|
||
expect(utcDate).toBeInstanceOf(Date); | ||
expect(utcDate.toISOString()).toBe('2019-12-31T23:00:00.000Z'); | ||
}); | ||
|
||
test('should convert to UTC date when already UTC', () => { | ||
const originalDate = new Date('2020-01-01T00:00:00.000Z'); | ||
const timezone = 'UTC'; // already at Z | ||
|
||
const utcDate = toUtcDate(originalDate, timezone); | ||
|
||
expect(utcDate).toBeInstanceOf(Date); | ||
expect(utcDate.toISOString()).toBe('2020-01-01T00:00:00.000Z'); | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.