(s: &str, min: u8, max: u8)
| 220 | } |
| 221 | |
| 222 | fn parse_range(s: &str, min: u8, max: u8) -> crate::Result<(u8, u8)> { |
| 223 | let (lo_str, hi_str) = s.split_once('-').ok_or_else(|| crate::Error::BadRequest { |
| 224 | detail: format!("invalid range: '{s}'"), |
| 225 | })?; |
| 226 | let lo: u8 = lo_str.parse().map_err(|_| crate::Error::BadRequest { |
| 227 | detail: format!("invalid range start: '{lo_str}'"), |
| 228 | })?; |
| 229 | let hi: u8 = hi_str.parse().map_err(|_| crate::Error::BadRequest { |
| 230 | detail: format!("invalid range end: '{hi_str}'"), |
| 231 | })?; |
| 232 | if lo < min || hi > max || lo > hi { |
| 233 | return Err(crate::Error::BadRequest { |
| 234 | detail: format!("range {lo}-{hi} out of bounds {min}-{max}"), |
| 235 | }); |
| 236 | } |
| 237 | Ok((lo, hi)) |
| 238 | } |
| 239 | |
| 240 | /// Convert Unix epoch seconds to (minute, hour, day, month, weekday). |
| 241 | /// weekday: 0=Sunday, 1=Monday, ..., 6=Saturday. |
no test coverage detected