diff --git a/src/rules/validators/end-time.ts b/src/rules/validators/end-time.ts index 5514ba9..7e88881 100644 --- a/src/rules/validators/end-time.ts +++ b/src/rules/validators/end-time.ts @@ -8,10 +8,10 @@ export const validateEndTime: RuleValidator = (rule) => { } if (typeof rule.endTime !== "string") { - throw new Error("endTime must be a string in HH:mm format"); + throw new Error("endTime must be a string in HH:mm or HH:mm:ss format"); } - if (!isMatch(rule.endTime, "HH:mm")) { - throw new Error(`endTime must be in HH:mm format (e.g., "09:30", "23:45"), got: "${rule.endTime}"`); + if (!isMatch(rule.endTime, "HH:mm") && !isMatch(rule.endTime, "HH:mm:ss")) { + throw new Error(`endTime must be in HH:mm or HH:mm:ss format (e.g., "09:30", "23:45:00"), got: "${rule.endTime}"`); } }; diff --git a/src/rules/validators/start-time.ts b/src/rules/validators/start-time.ts index bf9d9fb..0da7434 100644 --- a/src/rules/validators/start-time.ts +++ b/src/rules/validators/start-time.ts @@ -8,10 +8,12 @@ export const validateStartTime: RuleValidator = (rule) => { } if (typeof rule.startTime !== "string") { - throw new Error("startTime must be a string in HH:mm format"); + throw new Error("startTime must be a string in HH:mm or HH:mm:ss format"); } - if (!isMatch(rule.startTime, "HH:mm")) { - throw new Error(`startTime must be in HH:mm format (e.g., "09:30", "23:45"), got: "${rule.startTime}"`); + if (!isMatch(rule.startTime, "HH:mm") && !isMatch(rule.startTime, "HH:mm:ss")) { + throw new Error( + `startTime must be in HH:mm or HH:mm:ss format (e.g., "09:30", "23:45:00"), got: "${rule.startTime}"`, + ); } }; diff --git a/test/utils.spec.ts b/test/utils.spec.ts index 0c78e43..49bb234 100644 --- a/test/utils.spec.ts +++ b/test/utils.spec.ts @@ -132,4 +132,11 @@ describe("timeStringToMinutes", () => { it("should handle end of day", () => { expect(timeStringToMinutes("23:59")).to.equal(1439); }); + + it("should accept HH:mm:ss but ignore seconds in calculation", () => { + expect(timeStringToMinutes("00:00:30")).to.equal(0); + expect(timeStringToMinutes("12:30:30")).to.equal(750); + expect(timeStringToMinutes("09:30:00")).to.equal(570); + expect(timeStringToMinutes("23:59:59")).to.equal(1439); + }); });