Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/rules/validators/end-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`);
}
};
8 changes: 5 additions & 3 deletions src/rules/validators/start-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`,
);
}
};
7 changes: 7 additions & 0 deletions test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});