Skip to content

Commit c8aedf9

Browse files
The activity log filter covers the days it names, so 截止日期 2026-10-24 keeps that day's events (#1420)
Signed-off-by: Rudy Celekli <rudy@gradiahq.com> Co-authored-by: WaylandYang <145302500+WaylandYang@users.noreply.github.com>
1 parent 2eb32b6 commit c8aedf9

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎web/src/pages/KbSettings.tsx‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,19 @@ function auditDetailName(e: AuditEvent): string {
509509

510510
const AUDIT_PAGE = 50;
511511

512+
/** 两个日期框说的是读者日历上的几天:起始那天零点起、截止那天过完为止。服务端的区间
513+
* 含起点不含终点、按时刻比,所以截止日要送下一天的零点,零点也按本地时区换成时刻 */
514+
export function auditBounds(since: string, until: string) {
515+
const midnight = (day: string, later: number) => {
516+
const [y, m, d] = day.split("-").map(Number);
517+
return new Date(y, m - 1, d + later).toISOString();
518+
};
519+
return {
520+
since: since ? midnight(since, 0) : undefined,
521+
until: until ? midnight(until, 1) : undefined,
522+
};
523+
}
524+
512525
function KbActivity({ kbId }: { kbId: string }) {
513526
// 筛选按真实查法来:查一类动作、查一个人、查一段时间。
514527
// 动作前缀匹配——`entity.` 就能把 retyped / renamed 一族一起捞出来
@@ -521,8 +534,7 @@ function KbActivity({ kbId }: { kbId: string }) {
521534
queryFn: () =>
522535
api.kbAudit(kbId, {
523536
action: action || undefined,
524-
since: since || undefined,
525-
until: until || undefined,
537+
...auditBounds(since, until),
526538
limit: AUDIT_PAGE,
527539
offset: page * AUDIT_PAGE,
528540
}),

‎web/src/pages/auditBounds.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { beforeAll, expect, it } from "vitest";
2+
import { auditBounds } from "./KbSettings";
3+
4+
// 上海的 10 月 24 日是 UTC 的 23 日 16:00 到 24 日 16:00
5+
beforeAll(() => {
6+
process.env.TZ = "Asia/Shanghai";
7+
});
8+
9+
it("filters the activity log by the days the reader picked, end day included", () => {
10+
expect(auditBounds("2026-10-24", "2026-10-24")).toEqual({
11+
since: "2026-10-23T16:00:00.000Z",
12+
until: "2026-10-24T16:00:00.000Z",
13+
});
14+
// 截止日是月末:下一天是下个月的 1 日
15+
expect(auditBounds("", "2026-10-31").until).toBe("2026-10-31T16:00:00.000Z");
16+
expect(auditBounds("", "")).toEqual({ since: undefined, until: undefined });
17+
});

0 commit comments

Comments
 (0)