Skip to content

Commit d95f65e

Browse files
committed
Fix for zero durations
1 parent 50052a9 commit d95f65e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

apps/webapp/app/utils/timeGranularity.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import parseDuration from "parse-duration";
44
const DurationString = z
55
.string()
66
.refine(
7-
(val) => parseDuration(val) !== null,
8-
(val) => ({ message: `Invalid duration string: "${val}"` })
7+
(val) => {
8+
const ms = parseDuration(val);
9+
return ms !== null && ms > 0;
10+
},
11+
(val) => ({ message: `Invalid or non-positive duration string: "${val}"` })
912
);
1013

1114
const BracketSchema = z.object({
@@ -26,8 +29,8 @@ type ParsedBracket = {
2629

2730
function requireParsedDuration(input: string): number {
2831
const ms = parseDuration(input);
29-
if (ms === null) {
30-
throw new Error(`Failed to parse duration string: "${input}"`);
32+
if (ms === null || ms <= 0) {
33+
throw new Error(`Duration must be strictly positive, got "${input}" (${ms}ms)`);
3134
}
3235
return ms;
3336
}

0 commit comments

Comments
 (0)