MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / parse_duration_to_ms

Function parse_duration_to_ms

crates/openshell-cli/src/run.rs:6137–6157  ·  view source on GitHub ↗

Parse a duration string like "5m", "1h", "30s" into milliseconds.

(s: &str)

Source from the content-addressed store, hash-verified

6135
6136/// Parse a duration string like "5m", "1h", "30s" into milliseconds.
6137fn parse_duration_to_ms(s: &str) -> Result<i64> {
6138 let s = s.trim();
6139 if s.is_empty() {
6140 return Err(miette::miette!("empty duration string"));
6141 }
6142 let (num_str, unit) = s.split_at(s.len() - 1);
6143 let num: i64 = num_str
6144 .parse()
6145 .map_err(|_| miette::miette!("invalid duration: {s} (expected e.g. 5m, 1h, 30s)"))?;
6146 let multiplier = match unit {
6147 "s" => 1_000,
6148 "m" => 60_000,
6149 "h" => 3_600_000,
6150 _ => {
6151 return Err(miette::miette!(
6152 "unknown duration unit: {unit} (use s, m, or h)"
6153 ));
6154 }
6155 };
6156 Ok(num * multiplier)
6157}
6158
6159fn confirm_global_setting_takeover(key: &str, yes: bool) -> Result<()> {
6160 if yes {

Callers 1

sandbox_logsFunction · 0.85

Calls 3

lenMethod · 0.80
is_emptyMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected