Part 1: Add {From,To}Millis.
I think this is just oversight. Generally, we should anticipate what our consumers need to do to interact with Mentat, and producing milli- and micro-second timestamps is part of that need.
This commit is contained in:
parent
3744982cd9
commit
1c0602fa00
2 changed files with 24 additions and 0 deletions
|
@ -57,9 +57,11 @@ pub use parse::ParseError;
|
||||||
pub use uuid::ParseError as UuidParseError;
|
pub use uuid::ParseError as UuidParseError;
|
||||||
pub use types::{
|
pub use types::{
|
||||||
FromMicros,
|
FromMicros,
|
||||||
|
FromMillis,
|
||||||
Span,
|
Span,
|
||||||
SpannedValue,
|
SpannedValue,
|
||||||
ToMicros,
|
ToMicros,
|
||||||
|
ToMillis,
|
||||||
Value,
|
Value,
|
||||||
ValueAndSpan,
|
ValueAndSpan,
|
||||||
};
|
};
|
||||||
|
|
|
@ -649,6 +649,28 @@ impl ToMicros for DateTime<Utc> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait FromMillis {
|
||||||
|
fn from_millis(ts: i64) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromMillis for DateTime<Utc> {
|
||||||
|
fn from_millis(ts: i64) -> Self {
|
||||||
|
Utc.timestamp(ts / 1_000, ((ts % 1_000).abs() as u32) * 1_000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait ToMillis {
|
||||||
|
fn to_millis(&self) -> i64;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToMillis for DateTime<Utc> {
|
||||||
|
fn to_millis(&self) -> i64 {
|
||||||
|
let major: i64 = self.timestamp() * 1_000;
|
||||||
|
let minor: i64 = self.timestamp_subsec_millis() as i64;
|
||||||
|
major + minor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
|
|
Loading…
Reference in a new issue