MCPcopy Create free account
hub / github.com/cel-rust/cel-rust / duration

Function duration

cel/src/functions.rs:316–323  ·  view source on GitHub ↗

Duration parses the provided argument into a [`Value::Duration`] value. The argument must be string, and must be in the format of a duration. See the [`crate::duration::parse_duration`] documentation for more information on the supported formats. # Examples - `1h` parses as 1 hour - `1.5h` parses as 1 hour and 30 minutes - `1h30m` parses as 1 hour and 30 minutes - `1h30m1s` parses as 1 hour, 30

(value: Arc<String>)

Source from the content-addressed store, hash-verified

314 /// - `1ns` parses as 1 nanosecond
315 /// - `1.5ns` parses as 1 nanosecond (sub-nanosecond durations not supported)
316 pub fn duration(value: Arc<String>) -> crate::functions::Result<Value> {
317 Ok(Value::Duration({
318 let i = value.as_str();
319 let (_, duration) = crate::duration::parse_duration(i)
320 .map_err(|e| ExecutionError::function_error("duration", e.to_string()))?;
321 Ok(duration)
322 }?))
323 }
324
325 fn _timestamp(i: &str) -> Result<chrono::DateTime<chrono::FixedOffset>> {
326 chrono::DateTime::parse_from_rfc3339(i)

Callers

nothing calls this directly

Calls 2

parse_durationFunction · 0.85
DurationClass · 0.70

Tested by

no test coverage detected