fix: count down to a game's reset, not to UTC midnight

A source that prints "August 19, 2026" and no time is stored at 00:00Z,
which is a placeholder for "somewhere in this day" rather than a claim
about when the day opens. The countdown read it literally, which turns it
into exactly that claim — and the UTC day is nobody's. Wuthering Waves
events dated the 19th were still running three hours after we had retired
them, because a European player's day opens at 04:00 on a UTC+1 server;
Asia was four hours out the other way and America nine. Sixty-two of the
eighty-six published events were affected, across ten of thirteen games,
so the reader was reading a wrong number far more often than a right one.

A day-precision boundary now resolves to the reset that opens that
game-day on the reader's server — the same grid daily.ts keys every tick
by, and the only clock we hold for a game. That is a reading of the date
the source printed, not a time invented for it: nothing stored moves, no
event ID moves, and the parsers still refuse to guess.

Two boundaries are never re-anchored. A regionEnds value is already the
instant a source stated per server, so anchoring it would throw a fact
away. And an event the reader typed in was resolved by readerInstant in
their own timezone, which is a stated time too — theirs.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
Lucas Winther
2026-08-18 21:48:29 +02:00
co-authored by Claude Opus 5
parent 00c3f5e2da
commit 4334988ecf
6 changed files with 248 additions and 13 deletions
+112 -2
View File
@@ -1,8 +1,10 @@
import { describe, expect, test } from "bun:test";
import type { GachaEvent } from "../src/shared/schema.ts";
import { dailyDays, dayKey } from "../src/shared/daily.ts";
import {
clockFor,
DAY,
dayStartMs,
endingSoonestFirst,
formatRemaining,
HOUR,
@@ -59,10 +61,13 @@ describe("urgency", () => {
describe("clockFor", () => {
test("reports progress through the window", () => {
// Both boundaries are day-precision, so both land on the Europe reset
// (04:00 on a UTC+1 server = 03:00Z) rather than on UTC midnight. The
// window is still ten days; it just starts and finishes three hours later.
const c = clockFor(event(), "europe", NOW);
expect(c.live).toBe(true);
expect(c.progress).toBeCloseTo(0.55, 2);
expect(c.msRemaining).toBe(Date.parse("2026-08-20T00:00:00.000Z") - NOW);
expect(c.progress).toBeCloseTo(0.5375, 3);
expect(c.msRemaining).toBe(Date.parse("2026-08-20T03:00:00.000Z") - NOW);
});
test("an unannounced end is never urgent and has no progress", () => {
@@ -80,6 +85,9 @@ describe("clockFor", () => {
});
test("resolves a region-scoped end to the reader's region", () => {
// Note the event is day-precision: a `regionEnds` value is still taken
// verbatim, because the map only exists when a source printed a timer per
// server. Re-anchoring it to a reset would throw that instant away.
const c = clockFor(
event({
regionScoped: true,
@@ -122,3 +130,105 @@ describe("endingSoonestFirst", () => {
]);
});
});
describe("a day-precision boundary", () => {
/**
* The bug this describes: a source that prints "August 19, 2026" and no time
* is stored as 00:00Z, and counting down to that literally expires the event
* at the moment the *UTC* day opens. A European Wuthering Waves player's day
* opens at 04:00 on a UTC+1 server, so the app called an event over three
* hours before the game did — and the game was the one the reader believed.
*/
const dated = (endsAt: string, overrides: Partial<GachaEvent> = {}) =>
event({ endsAt, endPrecision: "day", ...overrides });
test("resolves to the game's reset, not to UTC midnight", () => {
const c = clockFor(dated("2026-08-19T00:00:00.000Z"), "europe", NOW);
expect(c.endsMs).toBe(Date.parse("2026-08-19T03:00:00.000Z"));
expect(c.endsMs! - Date.parse("2026-08-19T00:00:00.000Z")).toBe(3 * HOUR);
});
test("lands on a different instant in each region, from the same date", () => {
const at = (region: "asia" | "america" | "europe") =>
clockFor(dated("2026-08-19T00:00:00.000Z"), region, NOW).endsMs;
// 04:00 local on UTC+8, UTC-5 and UTC+1 servers respectively. Reading the
// printed date as UTC is wrong for all three, and by up to nine hours.
expect(at("asia")).toBe(Date.parse("2026-08-18T20:00:00.000Z"));
expect(at("america")).toBe(Date.parse("2026-08-19T09:00:00.000Z"));
expect(at("europe")).toBe(Date.parse("2026-08-19T03:00:00.000Z"));
});
test("follows a game that states its own server map or reset hour", () => {
// Endfield serves Europe off the Americas machine (UTC-5), and Reverse:
// 1999 rolls at 05:00 on a single UTC-5 server. Both already move day keys;
// an end date printed for those games moves with them.
const end = "2026-08-19T00:00:00.000Z";
expect(clockFor(dated(end, { game: "endfield" }), "europe", NOW).endsMs).toBe(
Date.parse("2026-08-19T09:00:00.000Z"),
);
expect(clockFor(dated(end, { game: "r1999" }), "europe", NOW).endsMs).toBe(
Date.parse("2026-08-19T10:00:00.000Z"),
);
});
test("leaves an exact boundary exactly where the source put it", () => {
const c = clockFor(
event({
startsAt: "2026-08-10T11:00:00.000Z",
startPrecision: "exact",
endsAt: "2026-08-19T10:59:59.000Z",
endPrecision: "exact",
}),
"europe",
NOW,
);
expect(c.startsMs).toBe(Date.parse("2026-08-10T11:00:00.000Z"));
expect(c.endsMs).toBe(Date.parse("2026-08-19T10:59:59.000Z"));
});
test("leaves an event the reader typed in alone", () => {
// `readerInstant` already resolved this to the instant they meant, in their
// own timezone — the end of the day they named, not a parser declining to
// guess a time. Anchoring it would move a date they stated themselves.
const typed = "2026-08-19T21:59:59.000Z";
const c = clockFor(
dated(typed, { extractionMethod: "manual", sourceId: "you" }),
"europe",
NOW,
);
expect(c.endsMs).toBe(Date.parse(typed));
});
test("an unannounced end is still unannounced", () => {
const c = clockFor(event({ endsAt: null, endPrecision: "unknown" }), "asia", NOW);
expect(c.endsMs).toBeNull();
});
test("puts the checklist on the days the reader can actually claim", () => {
// The window now starts on a reset, so the first pip is the day the source
// named. Read as UTC midnight it opened three hours early, which put a
// phantom pip on the day *before* the event for every region ahead of UTC.
const c = clockFor(
event({ startsAt: "2026-08-10T00:00:00.000Z", endsAt: "2026-08-13T00:00:00.000Z" }),
"europe",
NOW,
);
expect(dailyDays(c.startsMs, c.endsMs, "europe", "genshin")).toEqual([
"2026-08-10",
"2026-08-11",
"2026-08-12",
]);
});
});
describe("dayStartMs", () => {
test("is the instant dayKey names, for every region and game", () => {
for (const region of ["asia", "america", "europe"] as const) {
for (const game of [undefined, "genshin", "endfield", "r1999"] as const) {
const start = dayStartMs("2026-08-19", region, game);
expect(dayKey(start, region, game)).toBe("2026-08-19");
expect(dayKey(start - 1, region, game)).toBe("2026-08-18");
}
}
});
});