The startDateTime default in the Missions collection and the weekly generate-mission bin both forced the date at least a week out by adding 7 days to the offset to the next Saturday. Generated midweek that landed on the Saturday AFTER the coming one (a Tuesday generation went 11 days out instead of 4), which also pushed the bot's roll-call (posted within 3 days of start) days into the future and read as a missing roll-call. Add nextSaturdayStart() to the unit-timezone date helpers: the nearest upcoming Saturday at 20:00 America/New_York, rolling a week only once today's 20:00 has passed. Use it for the collection default and the generator, derive the generator codeName datestamp in unit time, and cover the boundary cases in tests/int/next-saturday-start.int.spec.ts.
48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
nextSaturdayStart,
|
|
wallTimeToInstant,
|
|
zonedDateKey,
|
|
zonedParts,
|
|
} from "@/lib/intelligence/fridayTime";
|
|
|
|
// 2026-10-10 is a Saturday, so: Oct 6 = Tuesday, Oct 9 = Friday, Oct 11 = Sunday.
|
|
const et = (y: number, m: number, d: number, h: number, min = 0): Date =>
|
|
wallTimeToInstant(y, m, d, h, min);
|
|
|
|
describe("nextSaturdayStart", () => {
|
|
it("returns the coming Saturday for every day of the week before 20:00", () => {
|
|
const cases: Array<[Date, string]> = [
|
|
[et(2026, 10, 6, 10), "2026-10-10"], // Tuesday -> the same coming Saturday
|
|
[et(2026, 10, 9, 23), "2026-10-10"], // Friday night
|
|
[et(2026, 10, 11, 0, 30), "2026-10-17"], // Sunday just after midnight
|
|
];
|
|
for (const [now, expectedKey] of cases) {
|
|
const result = nextSaturdayStart(now);
|
|
expect(zonedDateKey(result)).toBe(expectedKey);
|
|
expect(zonedParts(result).hour).toBe(20);
|
|
expect(result.getTime()).toBeGreaterThan(now.getTime());
|
|
}
|
|
});
|
|
|
|
it("uses today when it is Saturday but 20:00 has not passed yet", () => {
|
|
const result = nextSaturdayStart(et(2026, 10, 10, 15));
|
|
expect(zonedDateKey(result)).toBe("2026-10-10");
|
|
expect(zonedParts(result).hour).toBe(20);
|
|
});
|
|
|
|
it("rolls to the following Saturday once today's 20:00 has passed", () => {
|
|
const result = nextSaturdayStart(et(2026, 10, 10, 21));
|
|
expect(zonedDateKey(result)).toBe("2026-10-17");
|
|
expect(zonedParts(result).hour).toBe(20);
|
|
});
|
|
|
|
it("never skips a week when today is midweek", () => {
|
|
// Regression: the old "+7" always landed on the Saturday AFTER the coming
|
|
// one, so a Tuesday generation jumped 11 days out instead of 4.
|
|
const now = et(2026, 10, 6, 12);
|
|
const daysOut =
|
|
(nextSaturdayStart(now).getTime() - now.getTime()) / (24 * 60 * 60 * 1000);
|
|
expect(daysOut).toBeLessThan(7);
|
|
});
|
|
});
|