pub struct Timestamp { /* private fields */ }Expand description
Timestamp representing a time to be formatted based on a client’s current local timezone and locale.
Timestamps can be compared based on their unix value.
§Examples
Compare two timestamps to determine which is more recent:
use twilight_mention::timestamp::Timestamp;
let old = Timestamp::new(1_500_000_000, None);
let new = Timestamp::new(1_600_000_000, None);
assert!(new > old);Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub const fn new(unix: u64, style: Option<TimestampStyle>) -> Self
pub const fn new(unix: u64, style: Option<TimestampStyle>) -> Self
Create a new timestamp with a Unix timestamp and optionally a style.
The Unix timestamp is in seconds.
§Examples
Create a timestamp without a display modifier and format it as a mention:
use twilight_mention::{Mention, timestamp::Timestamp};
let timestamp = Timestamp::new(1624044388, None);
assert_eq!("<t:1624044388>", timestamp.mention().to_string());Sourcepub const fn style(&self) -> Option<TimestampStyle>
pub const fn style(&self) -> Option<TimestampStyle>
Style representing the display modifier.
use twilight_mention::timestamp::{Timestamp, TimestampStyle};
// When leaving a style unspecified a default is not provided.
assert!(Timestamp::new(1624044388, None).style().is_none());
// The same style is returned when a style is specified.
let timestamp = Timestamp::new(1_624_044_388, Some(TimestampStyle::ShortDateTime));
assert_eq!(Some(TimestampStyle::ShortDateTime), timestamp.style());Trait Implementations§
impl Copy for Timestamp
impl Eq for Timestamp
Source§impl Mention<Timestamp> for Timestamp
Mention a timestamp. This will format as <t:UNIX> if a style is not
specified or <t:UNIX:STYLE> if a style is specified.
impl Mention<Timestamp> for Timestamp
Mention a timestamp. This will format as <t:UNIX> if a style is not
specified or <t:UNIX:STYLE> if a style is specified.
Source§fn mention(&self) -> MentionFormat<Self>
fn mention(&self) -> MentionFormat<Self>
Mention a resource by using its ID.
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,
Compares and returns the maximum of two values. Read more
Source§impl ParseMention for Timestamp
impl ParseMention for Timestamp
Source§fn parse(buf: &str) -> Result<Self, ParseMentionError<'_>>where
Self: Sized,
fn parse(buf: &str) -> Result<Self, ParseMentionError<'_>>where
Self: Sized,
Parse a timestamp from a string slice.
§Examples
Returns ParseMentionErrorType::TimestampStyleInvalid if the
timestamp style value is invalid.
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
Mutably borrows from an owned value. Read more