The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | import * as DateTime from "effect/DateTime"; |
| 3 | |
| 4 | import { isSameSchedule, nextScheduledRunAt } from "./Schedule.ts"; |
| 5 | |
| 6 | describe("scheduled task schedule calculation", () => { |
| 7 | it("skips to the next matching fixed-time weekday", () => { |
| 8 | const next = nextScheduledRunAt( |
| 9 | { type: "fixed_time", timeOfDay: "09:00", weekdays: [1, 2, 3, 4, 5] }, |
| 10 | DateTime.makeZonedUnsafe( |
| 11 | { |
| 12 | year: 2026, |
| 13 | month: 7, |
| 14 | day: 3, |
| 15 | hour: 10, |
| 16 | minute: 0, |
| 17 | second: 0, |
| 18 | millisecond: 0, |
| 19 | }, |
| 20 | { timeZone: "America/Los_Angeles", adjustForTimeZone: true }, |
| 21 | ), |
| 22 | ); |
| 23 | const parts = next ? DateTime.toParts(next) : null; |
| 24 | expect(parts?.weekDay).toBe(1); |
| 25 | expect(parts?.hour).toBe(9); |
| 26 | expect(parts?.minute).toBe(0); |
| 27 | }); |
| 28 | |
| 29 | it("compares schedules structurally", () => { |
| 30 | expect( |
| 31 | isSameSchedule( |
| 32 | { type: "once", runAt: "2026-11-01T03:00:00-05:00" }, |
| 33 | { type: "once", runAt: "2026-11-01T08:00:00.000Z" }, |
| 34 | ), |
| 35 | ).toBe(true); |
| 36 | expect( |
| 37 | isSameSchedule({ type: "interval", everyMs: 60_000 }, { type: "interval", everyMs: 60_000 }), |
| 38 | ).toBe(true); |
| 39 | expect( |
| 40 | isSameSchedule({ type: "interval", everyMs: 60_000 }, { type: "interval", everyMs: 30_000 }), |
| 41 | ).toBe(false); |
| 42 | expect( |
| 43 | isSameSchedule( |
| 44 | { type: "fixed_time", timeOfDay: "09:00", weekdays: [1, 2] }, |
| 45 | { type: "fixed_time", timeOfDay: "09:00", weekdays: [1, 2] }, |
| 46 | ), |
| 47 | ).toBe(true); |
| 48 | expect( |
| 49 | isSameSchedule( |
| 50 | { type: "fixed_time", timeOfDay: "09:00", weekdays: [5, 1] }, |
| 51 | { type: "fixed_time", timeOfDay: "09:00", weekdays: [1, 5, 5] }, |
| 52 | ), |
| 53 | ).toBe(true); |
| 54 | expect( |
| 55 | isSameSchedule( |
| 56 | { type: "fixed_time", timeOfDay: "09:00" }, |
| 57 | { type: "fixed_time", timeOfDay: "09:00", weekdays: [0, 1, 2, 3, 4, 5, 6] }, |
| 58 | ), |
| 59 | ).toBe(true); |
| 60 | expect( |
| 61 | isSameSchedule( |
| 62 | { type: "fixed_time", timeOfDay: "09:00", weekdays: [] }, |
| 63 | { type: "fixed_time", timeOfDay: "09:00" }, |
| 64 | ), |
| 65 | ).toBe(true); |
| 66 | expect( |
| 67 | isSameSchedule( |
| 68 | { type: "fixed_time", timeOfDay: "09:00", weekdays: [1, 2] }, |
| 69 | { type: "fixed_time", timeOfDay: "09:00", weekdays: [1, 3] }, |
| 70 | ), |
| 71 | ).toBe(false); |
| 72 | expect( |
| 73 | isSameSchedule( |
| 74 | { type: "fixed_time", timeOfDay: "09:00" }, |
| 75 | { type: "fixed_time", timeOfDay: "09:30" }, |
| 76 | ), |
| 77 | ).toBe(false); |
| 78 | expect( |
| 79 | isSameSchedule( |
| 80 | { type: "interval", everyMs: 60_000 }, |
| 81 | { type: "fixed_time", timeOfDay: "09:00" }, |
| 82 | ), |
| 83 | ).toBe(false); |
| 84 | }); |
| 85 | }); |