fix(logbook): reject invalid 12-hour analysis clocks (#107191)

* fix(logbook): reject invalid meridiem clocks

* test(logbook): cover invalid meridiem card output

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
qingminlong
2026-07-15 00:43:10 +08:00
committed by GitHub
parent c1191cdf2f
commit 04e523a73b
2 changed files with 6 additions and 1 deletions
+3 -1
View File
@@ -31,6 +31,8 @@ describe("clockToMs", () => {
it("rejects malformed input", () => {
expect(clockToMs(DAY, "25:00:00")).toBeNull();
expect(clockToMs(DAY, "13:05 pm")).toBeNull();
expect(clockToMs(DAY, "00:05 am")).toBeNull();
expect(clockToMs(DAY, "half past nine")).toBeNull();
expect(clockToMs("not-a-day", "10:00:00")).toBeNull();
});
@@ -160,7 +162,7 @@ describe("parseCardsJson", () => {
it("reports actionable errors for the correction round-trip", () => {
const result = parseCardsJson({
raw: JSON.stringify([card({ startTime: "later that day" })]),
raw: JSON.stringify([card({ startTime: "13:05 pm" })]),
day: DAY,
windowStartMs,
windowEndMs,
+3
View File
@@ -24,6 +24,9 @@ export function clockToMs(day: string, clock: string): number | null {
const minutes = Number(match[2]);
const seconds = Number(match[3] ?? "0");
const meridiem = match[4]?.toLowerCase();
if (meridiem && (hours < 1 || hours > 12)) {
return null;
}
if (meridiem === "pm" && hours < 12) {
hours += 12;
}