mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
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:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user