MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / parse_duration

Function parse_duration

src/user_config.rs:229–244  ·  view source on GitHub ↗

Parse a human-readable duration string like "15s" or "1m" into a Duration.

(s: &str)

Source from the content-addressed store, hash-verified

227
228/// Parse a human-readable duration string like "15s" or "1m" into a Duration.
229pub fn parse_duration(s: &str) -> Option<std::time::Duration> {
230 let s = s.trim();
231 if let Some(secs) = s.strip_suffix('s') {
232 secs.trim()
233 .parse::<u64>()
234 .ok()
235 .map(std::time::Duration::from_secs)
236 } else if let Some(mins) = s.strip_suffix('m') {
237 mins.trim()
238 .parse::<u64>()
239 .ok()
240 .map(|m| std::time::Duration::from_secs(m * 60))
241 } else {
242 s.parse::<u64>().ok().map(std::time::Duration::from_secs)
243 }
244}
245
246#[cfg(test)]
247#[allow(

Callers 1

patch_user_settingsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected