apple_quant_core/time_delta_ext.rs
1use chrono::TimeDelta;
2
3pub trait TimeDeltaExt {
4 fn nanoseconds_i128(
5 nanoseconds: i128,
6 ) -> Option<Self>
7 where
8 Self: Sized;
9}
10
11impl TimeDeltaExt for TimeDelta {
12 fn nanoseconds_i128(
13 nanoseconds: i128,
14 ) -> Option<Self>
15 where
16 Self: Sized,
17 {
18 let secs = i64::try_from(nanoseconds.div_euclid(1_000_000_000)).ok()?;
19 let nanos = nanoseconds.rem_euclid(1_000_000_000) as u32;
20
21 Self::new(secs, nanos)
22 }
23}