Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/floppy-cobras-stick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Fix Cron.next and Cron.sequence around timezone boundaries
8 changes: 6 additions & 2 deletions packages/effect/src/internal/dateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,12 @@ export const unsafeMakeZoned = (input: DateTime.DateTime.Input, options?: {
}
let zone: DateTime.TimeZone
if (options?.timeZone === undefined) {
const offset = new Date(self.epochMillis).getTimezoneOffset() * -60 * 1000
zone = zoneMakeOffset(offset)
const zoneName = Intl.DateTimeFormat().resolvedOptions().timeZone
const parsedZone = zoneFromString(zoneName)
if (Option.isNone(parsedZone)) {
throw new IllegalArgumentException(`Invalid time zone: ${zoneName}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe fallback to a offset zone here

}
zone = parsedZone.value
} else if (isTimeZone(options?.timeZone)) {
zone = options.timeZone
} else if (typeof options?.timeZone === "number") {
Expand Down
4 changes: 4 additions & 0 deletions packages/effect/test/Cron.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@
deepStrictEqual(next().pipe(DateTime.formatIsoZoned), b.pipe(DateTime.formatIsoZoned))
deepStrictEqual(next().pipe(DateTime.formatIsoZoned), c.pipe(DateTime.formatIsoZoned))
deepStrictEqual(next().pipe(DateTime.formatIsoZoned), d.pipe(DateTime.formatIsoZoned))

const seq = Cron.sequence(Cron.unsafeParse("5 2 * * 6"), new Date("2020-11-01 0:00:01Z"))
deepStrictEqual(seq.next().value, new Date("2020-11-07T07:05:00.000Z"))

Check failure on line 178 in packages/effect/test/Cron.test.ts

View workflow job for this annotation

GitHub Actions / Test (Node 4/4)

test/Cron.test.ts > Cron > handles transition into daylight savings time

AssertionError: Expected values to be strictly deep-equal: + actual - expected + 2020-11-07T02:05:00.000Z - 2020-11-07T07:05:00.000Z - Expected + Received - 2020-11-07T07:05:00.000Z + 2020-11-07T02:05:00.000Z ❯ test/Cron.test.ts:178:5
deepStrictEqual(seq.next().value, new Date("2020-11-14T07:05:00.000Z"))
})

it("handles transition out of daylight savings time", () => {
Expand Down
Loading