This commit is contained in:
Dominik Werder
2024-09-06 22:11:57 +02:00
parent f5909ea03c
commit 2c523810c1
6 changed files with 70 additions and 38 deletions
+25
View File
@@ -1760,11 +1760,22 @@ impl DtMs {
1000000 * self.0
}
pub const fn dt_ns(&self) -> DtNano {
DtNano::from_ms(self.0)
}
pub const fn to_i64(&self) -> i64 {
self.0 as i64
}
}
impl fmt::Display for DtMs {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let dur = Duration::from_millis(self.ms());
write!(fmt, "{}", humantime::format_duration(dur))
}
}
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord)]
pub struct TsNano(u64);
@@ -1866,6 +1877,10 @@ impl TsNano {
TsMs::from_ms_u64(self.ms())
}
pub const fn to_dt_ms(self) -> DtMs {
DtMs::from_ms_u64(self.ms())
}
pub fn from_system_time(st: SystemTime) -> Self {
let tsunix = st.duration_since(UNIX_EPOCH).unwrap_or(Duration::ZERO);
let x = tsunix.as_secs() * 1_000_000_000 + tsunix.subsec_nanos() as u64;
@@ -2378,6 +2393,16 @@ impl BinnedRange<TsNano> {
pub fn to_nano_range(&self) -> NanoRange {
self.full_range()
}
pub fn from_nano_range(range: NanoRange, bin_len: DtMs) -> Self {
let off1 = range.beg() / bin_len.ns();
let off2 = (bin_len.ns() - 1 + range.end()) / bin_len.ns();
Self {
bin_len: TsNano::from_ns(bin_len.ns()),
bin_off: off1,
bin_cnt: off2 - off1,
}
}
}
impl<T> BinnedRange<T>