Skip to content

Commit 5234e2e

Browse files
committed
fix: group reset history by UTC date
1 parent 86bb037 commit 5234e2e

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎src/components/codex-reset-history.test.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,20 @@ describe("CodexResetHistoryModal", () => {
121121
expect(summary.longestIntervalDays).toBe(4);
122122
expect(summary.calendarDays.find((day) => day.date.format("YYYY-MM-DD") === "2026-08-24")?.resetType).toBe("mixed");
123123
});
124+
125+
it("groups reset announcements by their UTC date", () => {
126+
const summary = buildResetHistorySummary([
127+
{
128+
id: "1",
129+
resetType: "banked",
130+
announcedAt: "2026-08-21T23:40:12.000Z",
131+
text: "A banked reset is available.",
132+
source: { author: "source", url: "https://example.com/1" },
133+
},
134+
], dayjs("2026-08-26T07:00:00.000+08:00"));
135+
136+
expect(summary.calendarDays.find((day) => day.date.format("YYYY-MM-DD") === "2026-08-21")?.resetType).toBe("banked");
137+
expect(summary.calendarDays.find((day) => day.date.format("YYYY-MM-DD") === "2026-08-22")?.resetType).toBeNull();
138+
expect([...summary.calendarDays].reverse().find((day) => day.inRange)?.date.format("YYYY-MM-DD")).toBe("2026-08-25");
139+
});
124140
});

‎src/components/codex-reset-history.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dayjs, { type Dayjs } from "dayjs";
2+
import utc from "dayjs/plugin/utc";
23
import { ChevronDown, ChevronUp, ExternalLink, RotateCcw, X } from "lucide-react";
34
import { useEffect, useMemo, useRef, useState } from "react";
45
import { useTranslation } from "react-i18next";
@@ -7,6 +8,8 @@ import { fetchCodexResetHistory, openUrl, type CodexResetAnnouncement } from "@/
78
const HISTORY_DAYS = 30;
89
const DEFAULT_VISIBLE_RESETS = 5;
910

11+
dayjs.extend(utc);
12+
1013
type CalendarDay = {
1114
date: Dayjs;
1215
inRange: boolean;
@@ -31,12 +34,13 @@ export function buildResetHistorySummary(
3134
const intervals = sortedResets.slice(0, -1).map((reset, index) =>
3235
dayjs(reset.announcedAt).diff(sortedResets[index + 1].announcedAt, "minute", true) / (60 * 24),
3336
);
34-
const startDate = now.startOf("day").subtract(HISTORY_DAYS - 1, "day");
35-
const endDate = now.endOf("day");
37+
const currentDate = now.utc();
38+
const startDate = currentDate.startOf("day").subtract(HISTORY_DAYS - 1, "day");
39+
const endDate = currentDate.endOf("day");
3640
const resetsByDate = new Map<string, CodexResetAnnouncement[]>();
3741

3842
for (const reset of sortedResets) {
39-
const key = dayjs(reset.announcedAt).format("YYYY-MM-DD");
43+
const key = dayjs.utc(reset.announcedAt).format("YYYY-MM-DD");
4044
const existing = resetsByDate.get(key);
4145
if (existing) existing.push(reset);
4246
else resetsByDate.set(key, [reset]);

0 commit comments

Comments
 (0)