pub struct Timestamp { /* private fields */ }Expand description
A point in time, as sent by Discord in ISO 8601 format.
Discord timestamps look like 2026-11-10T19:42:07.123000+00:00. They are stored here as a
single i64 of microseconds since the Unix epoch (8 bytes, Copy), which is the
precision Discord uses. Parsing and formatting are implemented without any date/time
dependency.
Timestamps are ordered chronologically.
discord.js counterpart: none (discord.js turns timestamps into Dates).
§Examples
use djs_model::util::Timestamp;
let ts: Timestamp = "2021-01-01T12:30:00.5+00:00".parse().unwrap();
assert_eq!(ts.as_unix_millis(), 1_609_504_200_500);
assert_eq!(ts.to_string(), "2021-01-01T12:30:00.500000+00:00");
// Offsets are normalised to UTC.
let same: Timestamp = "2021-01-01T14:30:00.500+02:00".parse().unwrap();
assert_eq!(ts, same);Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub const fn from_unix_micros(unix_micros: i64) -> Self
pub const fn from_unix_micros(unix_micros: i64) -> Self
Creates a timestamp from microseconds since the Unix epoch.
discord.js counterpart: new Date(ms).
Sourcepub const fn from_unix_millis(unix_millis: i64) -> Option<Self>
pub const fn from_unix_millis(unix_millis: i64) -> Option<Self>
Creates a timestamp from milliseconds since the Unix epoch.
Returns None if the value overflows the microsecond representation.
discord.js counterpart: new Date(ms).
Sourcepub const fn from_unix_secs(unix_secs: i64) -> Option<Self>
pub const fn from_unix_secs(unix_secs: i64) -> Option<Self>
Creates a timestamp from seconds since the Unix epoch.
Returns None if the value overflows the microsecond representation.
discord.js counterpart: new Date(seconds * 1000).
Sourcepub fn now() -> Self
pub fn now() -> Self
Returns the current system time.
discord.js counterpart: Date.now().
§Panics
Panics if the system clock is set before 1970 or after the year 294 247.
Sourcepub const fn as_unix_micros(self) -> i64
pub const fn as_unix_micros(self) -> i64
Returns the number of microseconds since the Unix epoch.
discord.js counterpart: Date#getTime.
Sourcepub const fn as_unix_millis(self) -> i64
pub const fn as_unix_millis(self) -> i64
Returns the number of whole milliseconds since the Unix epoch (rounded towards negative infinity).
discord.js counterpart: Date#getTime.
Sourcepub const fn as_unix_secs(self) -> i64
pub const fn as_unix_secs(self) -> i64
Returns the number of whole seconds since the Unix epoch (rounded towards negative infinity).
This is the value expected by Discord’s <t:…> timestamp markdown.
discord.js counterpart: Date#getTime.
Sourcepub fn parse(input: &str) -> Result<Self, ParseTimestampError>
pub fn parse(input: &str) -> Result<Self, ParseTimestampError>
Parses an ISO 8601 / RFC 3339 timestamp such as 2026-11-10T19:42:07.123000+00:00.
Accepted format: YYYY-MM-DDTHH:MM:SS, an optional fraction of 1–9 digits (digits
beyond microseconds are truncated), and a Z or ±HH:MM offset. A space is accepted in
place of T.
discord.js counterpart: new Date(string), as discord.js parses timestamps.
§Errors
Returns ParseTimestampError if the input is not in that format or contains an
out-of-range component (for example month 13 or February 30).
Trait Implementations§
impl Copy for Timestamp
Source§impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Display for Timestamp
Formats as YYYY-MM-DDTHH:MM:SS.ffffff+00:00, the format Discord itself uses.
impl Display for Timestamp
Formats as YYYY-MM-DDTHH:MM:SS.ffffff+00:00, the format Discord itself uses.
impl Eq for Timestamp
Source§impl Ord for Timestamp
impl Ord for Timestamp
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations§
impl Freeze for Timestamp
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnsafeUnpin for Timestamp
impl UnwindSafe for Timestamp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString]. Read more