Initial public release of Warp.
Repo-Sync-Origin: warpdotdev/warp-internal@12af1d983b
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
pub mod time;
|
||||
pub type Time = time::ServerTimestamp;
|
||||
@@ -0,0 +1,32 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub struct ServerTimestamp(DateTime<Utc>);
|
||||
impl ServerTimestamp {
|
||||
pub fn new(time: DateTime<Utc>) -> Self {
|
||||
Self(time)
|
||||
}
|
||||
|
||||
/// General-purpose function for converting from an i64 (representing microseconds) to a ServerTimestamp.
|
||||
pub fn from_unix_timestamp_micros(ms_since_epoch: i64) -> Result<Self> {
|
||||
let date_time = DateTime::from_timestamp_micros(ms_since_epoch)
|
||||
.ok_or_else(|| anyhow!("Unable to convert microseconds into NaiveDateTime"))?;
|
||||
Ok(ServerTimestamp::new(date_time))
|
||||
}
|
||||
|
||||
pub fn timestamp_micros(&self) -> i64 {
|
||||
self.0.timestamp_micros()
|
||||
}
|
||||
|
||||
pub fn utc(&self) -> DateTime<Utc> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DateTime<Utc>> for ServerTimestamp {
|
||||
fn from(value: DateTime<Utc>) -> Self {
|
||||
ServerTimestamp::new(value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user