common: Implement Debug manually for [Milli]SecondsSinceUnixEpoch
This commit is contained in:
parent
19006cd047
commit
1249dda583
@ -1,10 +1,13 @@
|
|||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::{
|
||||||
|
fmt,
|
||||||
|
time::{Duration, SystemTime, UNIX_EPOCH},
|
||||||
|
};
|
||||||
|
|
||||||
use js_int::{uint, UInt};
|
use js_int::{uint, UInt};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// A timestamp represented as the number of milliseconds since the unix epoch.
|
/// A timestamp represented as the number of milliseconds since the unix epoch.
|
||||||
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct MilliSecondsSinceUnixEpoch(pub UInt);
|
pub struct MilliSecondsSinceUnixEpoch(pub UInt);
|
||||||
@ -43,8 +46,16 @@ impl MilliSecondsSinceUnixEpoch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for MilliSecondsSinceUnixEpoch {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
// The default Debug impl would put the inner value on its own line if the formatter's
|
||||||
|
// alternate mode is enabled, which bloats debug strings unnecessarily
|
||||||
|
write!(f, "MilliSecondsSinceUnixEpoch({})", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A timestamp represented as the number of seconds since the unix epoch.
|
/// A timestamp represented as the number of seconds since the unix epoch.
|
||||||
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct SecondsSinceUnixEpoch(pub UInt);
|
pub struct SecondsSinceUnixEpoch(pub UInt);
|
||||||
@ -78,6 +89,14 @@ impl SecondsSinceUnixEpoch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for SecondsSinceUnixEpoch {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
// The default Debug impl would put the inner value on its own line if the formatter's
|
||||||
|
// alternate mode is enabled, which bloats debug strings unnecessarily
|
||||||
|
write!(f, "SecondsSinceUnixEpoch({})", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(target_arch = "wasm32", target_os = "unknown", feature = "js"))]
|
#[cfg(all(target_arch = "wasm32", target_os = "unknown", feature = "js"))]
|
||||||
fn f64_to_uint(val: f64) -> UInt {
|
fn f64_to_uint(val: f64) -> UInt {
|
||||||
// UInt::MAX milliseconds is ~285 616 years, we do not account for that
|
// UInt::MAX milliseconds is ~285 616 years, we do not account for that
|
||||||
|
Loading…
x
Reference in New Issue
Block a user