Files
gacha-event-tracker/test/dates.test.ts
T
Lucas WintherandClaude Opus 5 d8b539bce1 feat(p5x): track Persona 5: The Phantom X
Adds the game and its Game8 events page, the second of the games named in
the release thread. `parseAdjacentFullRange` reads the shape this page
uses: two full dates divided by an `<hr>` rather than a dash, so a
tag-stripping reader sees only whitespace between them. It is anchored at
both ends and needs a year on each half, because without that "August 12,
2026 Day 3 rewards" reads "Day 3" as an end.

Three of the four live rows publish. "Take Your Heart" ends 30 days after
each player makes an account, so it has no calendar date and no honest
place on a calendar. "Login Campaigns" names two candidate ends
("July 16/30, 2026") — it keeps its real start and takes no end, and the
leftover is not shown as a summary either, since a date the parser
refused to trust must not reappear dressed as information.

The page lists each live event twice: once in a bare Event|Duration table
and again under its own heading with Start Date / End Date rows and a
paragraph of prose. The second copy corroborates the dates, so deduping
now fills a missing summary from the copy it drops. Dates are still taken
wholesale from the better-dated copy and never blended.

Verified by re-extracting the page independently of the parser: 4 rows,
3 events, the fourth correctly skipped.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
2026-08-17 17:21:10 +02:00

201 lines
7.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, test } from "bun:test";
import {
parseAdjacentFullRange,
parseFullRange,
parseLabelledStartEnd,
parseMonthDayRange,
parseMonthDayYear,
parseOpenRange,
parseSlashDateTimeRange,
} from "../src/ingest/dates.ts";
describe("parseMonthDayYear", () => {
test("parses a full date at day precision", () => {
expect(parseMonthDayYear("August 12, 2026")).toEqual({
iso: "2026-08-12T00:00:00.000Z",
precision: "day",
});
});
test("accepts abbreviated months with and without a period", () => {
expect(parseMonthDayYear("Apr. 29, 2026")?.iso).toBe(
"2026-04-29T00:00:00.000Z",
);
expect(parseMonthDayYear("Sept 3, 2026")?.iso).toBe(
"2026-09-03T00:00:00.000Z",
);
});
test("returns null rather than guessing a missing year", () => {
expect(parseMonthDayYear("August 12")).toBeNull();
});
test("rejects impossible calendar dates", () => {
expect(parseMonthDayYear("February 30, 2026")).toBeNull();
});
test("rejects an unknown month name", () => {
expect(parseMonthDayYear("Smarch 3, 2026")).toBeNull();
});
});
describe("parseMonthDayRange", () => {
test("applies the stated year to both ends", () => {
expect(parseMonthDayRange("August 12 - September 21, 2026")).toEqual({
start: { iso: "2026-08-12T00:00:00.000Z", precision: "day" },
end: { iso: "2026-09-21T00:00:00.000Z", precision: "day" },
});
});
test("rolls the start back a year when the range crosses New Year", () => {
// "December 28 - January 4, 2027" — the stated year belongs to the end.
const r = parseMonthDayRange("December 28 - January 4, 2027");
expect(r?.start.iso).toBe("2026-12-28T00:00:00.000Z");
expect(r?.end.iso).toBe("2027-01-04T00:00:00.000Z");
});
test("handles en dash and abbreviated months", () => {
const r = parseMonthDayRange("Apr. 29 May 13, 2026");
expect(r?.start.iso).toBe("2026-04-29T00:00:00.000Z");
expect(r?.end.iso).toBe("2026-05-13T00:00:00.000Z");
});
test("returns null for a year-less range", () => {
// Game8 summary tables render "08/12 - 08/24". Guessing the year here is
// exactly the failure the product exists to prevent.
expect(parseMonthDayRange("08/12 - 08/24")).toBeNull();
});
});
describe("parseSlashDateTimeRange", () => {
test("parses a timed range at exact precision", () => {
expect(
parseSlashDateTimeRange("2021/01/16 04:00 - 2021/01/31 03:59"),
).toEqual({
start: { iso: "2021-01-16T04:00:00.000Z", precision: "exact" },
end: { iso: "2021-01-31T03:59:00.000Z", precision: "exact" },
});
});
test("ignores trailing prose after the range", () => {
const r = parseSlashDateTimeRange(
"2021/01/16 04:00 - 2021/01/31 03:59 Currently Unavailable",
);
expect(r?.end.iso).toBe("2021-01-31T03:59:00.000Z");
});
test("returns null for non-date prose", () => {
expect(parseSlashDateTimeRange("Permanently Available")).toBeNull();
});
});
describe("parseFullRange", () => {
test("reads a year from each side", () => {
expect(parseFullRange("Aug. 14, 2026 - Aug. 24, 2026")).toEqual({
start: { iso: "2026-08-14T00:00:00.000Z", precision: "day" },
end: { iso: "2026-08-24T00:00:00.000Z", precision: "day" },
});
});
test("ignores prose trailing the range", () => {
const r = parseFullRange(
"July 30, 2026 - August 13, 2026 Reach Union Level 8 to unlock",
);
expect(r?.end.iso).toBe("2026-08-13T00:00:00.000Z");
});
test("does not fire on a range with the year only at the end", () => {
// That shape belongs to parseMonthDayRange, which rolls the start year.
expect(parseFullRange("August 12 - September 21, 2026")).toBeNull();
});
});
describe("parseOpenRange", () => {
test("keeps a real start when the end is not a date", () => {
// "End of 4.6" and "Permanent" are honest unknowns, not parse failures.
for (const input of [
"Jul. 24, 2026 - End of 4.6",
"July 10, 2026 - Permanent",
"August 3, 2026",
]) {
const r = parseOpenRange(input);
expect(r?.end).toBeNull();
expect(r?.start.iso.slice(0, 4)).toBe("2026");
}
});
test("returns null when there is no full date at all", () => {
expect(parseOpenRange("08/12 - 08/24")).toBeNull();
expect(parseOpenRange("Releases in Version 3.6")).toBeNull();
});
});
describe("parseAdjacentFullRange", () => {
test("reads two dates separated by nothing but whitespace", () => {
// Persona 5 separates the halves of a duration cell with an <hr>, which a
// tag-stripping reader flattens to a single space.
expect(parseAdjacentFullRange("July 30, 2026 August 13, 2026")).toEqual({
start: { iso: "2026-07-30T00:00:00.000Z", precision: "day" },
end: { iso: "2026-08-13T00:00:00.000Z", precision: "day" },
});
});
test("requires a year on both halves", () => {
expect(parseAdjacentFullRange("July 30, 2026 August 13")).toBeNull();
});
test("refuses a second half that is only partly a date", () => {
// "July 16/30" names two candidate ends. Reading either as the end would
// be a coin flip presented as a fact.
expect(parseAdjacentFullRange("June 25, 2026 July 16/30, 2026")).toBeNull();
});
test("is anchored, so prose after a date is not read as an end", () => {
// Without the anchors, "Day 3" parses as a month and a day.
expect(
parseAdjacentFullRange("August 12, 2026 Day 3 rewards are doubled"),
).toBeNull();
expect(parseAdjacentFullRange("Starts August 12, 2026")).toBeNull();
});
test("rejects an impossible calendar date rather than rolling it over", () => {
expect(parseAdjacentFullRange("February 30, 2026 March 4, 2026")).toBeNull();
});
});
describe("parseLabelledStartEnd", () => {
test("reads a labelled cell", () => {
expect(
parseLabelledStartEnd("Start: April 28, 2025 End: June 12, 2025"),
).toEqual({
start: { iso: "2025-04-28T00:00:00.000Z", precision: "day" },
end: { iso: "2025-06-12T00:00:00.000Z", precision: "day" },
});
});
test("reports no end when the end half is not a date", () => {
// "Permanent" is the source telling us there is no deadline. Inventing one
// is the failure this codebase exists to prevent.
const permanent = parseLabelledStartEnd(
"Start: January 24, 2025 End: Permanent",
);
expect(permanent?.start.iso).toBe("2025-01-24T00:00:00.000Z");
expect(permanent?.end).toBeNull();
expect(parseLabelledStartEnd("Start: January 24, 2025 End: TBD")?.end).toBeNull();
expect(parseLabelledStartEnd("Start: January 24, 2025")?.end).toBeNull();
});
test("returns null when the start half is not a date", () => {
expect(parseLabelledStartEnd("Start: After maintenance End: TBD")).toBeNull();
expect(parseLabelledStartEnd("Ends after 30 days of making your account.")).toBeNull();
});
test("requires the colons, so prose containing 'end' does not split", () => {
// Without them, any sentence mentioning an end would look like a boundary.
expect(
parseLabelledStartEnd("Start the quest before August 12, 2026 to end the arc"),
).toBeNull();
});
});