Fix parse_schedule_interval to handle unit attached to number

The function was incorrectly splitting on whitespace, which failed for
inputs like "every 6h" where the unit is directly attached to the number.
Now it correctly parses by finding the first non-digit character.

Fixes tests:
- test_parse_schedule_interval_hours
- test_parse_schedule_interval_minutes
- test_parse_schedule_interval_seconds
- test_parse_schedule_case_insensitive
- test_worker_config_from_schedule

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
jedarden 2026-05-23 07:59:37 -04:00
parent 9d0ffe1201
commit 91584333dd

View file

@ -70,17 +70,30 @@ fn parse_schedule_interval(schedule: &str) -> Option<u64> {
return None;
}
let parts = schedule[6..].trim().split_whitespace().collect::<Vec<_>>();
if parts.is_empty() {
let rest = schedule[6..].trim();
if rest.is_empty() {
return None;
}
let num_str = parts[0];
let unit = parts.get(1).unwrap_or(&"");
// Find the first non-digit character to split number from unit
let mut num_end = 0;
for (i, c) in rest.chars().enumerate() {
if !c.is_ascii_digit() {
num_end = i;
break;
}
}
if num_end == 0 {
return None;
}
let num_str = &rest[..num_end];
let unit = &rest[num_end..];
let value: u64 = num_str.parse().ok()?;
match *unit {
match unit {
"s" | "sec" | "second" | "seconds" => Some(value),
"m" | "min" | "minute" | "minutes" => Some(value * 60),
"h" | "hour" | "hours" => Some(value * 3600),