use crate::ffi::time_v1 as ffi;
pub use ffi::TimeFormat;
#[doc(hidden)]
pub use ffi::API as FFI_API;
#[derive(Copy, Clone)]
pub struct Time {}
#[derive(Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "with_speedy", derive(speedy::Writable, speedy::Readable))]
pub struct Instant(i64);
impl std::fmt::Debug for Instant {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Time {}
.format_instant_for_display(*self, TimeFormat::ISODateTimeUTC)
.fmt(f)
}
}
impl Instant {
pub fn from_nanos_since_epoch(ns_since_epoch: i64) -> Self {
Self(ns_since_epoch)
}
pub fn as_nanos_since_epoch(self) -> i64 {
self.0
}
}
impl Time {
pub fn now(self) -> Instant {
Instant(ffi::time_utc())
}
pub fn format_instant_for_display(self, i: Instant, format: TimeFormat) -> String {
ffi::format_time_for_display(i.0, format)
}
}