Function relay_common::time::chrono_to_positive_millis
source · pub fn chrono_to_positive_millis(duration: Duration) -> f64
Expand description
Returns the positive number of milliseconds contained by this Duration
as f64
.
The returned value does include the fractional (nanosecond) part of the duration. If the
duration is negative, this returns 0.0
;
§Example
use chrono::Duration;
let duration = Duration::nanoseconds(2_125_000);
let millis = relay_common::time::chrono_to_positive_millis(duration);
assert_eq!(millis, 2.125);
Negative durations are clamped to 0.0
:
use chrono::Duration;
let duration = Duration::nanoseconds(-2_125_000);
let millis = relay_common::time::chrono_to_positive_millis(duration);
assert_eq!(millis, 0.0);