Struct twilight_mention::timestamp::Timestamp
source · 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::{timestamp::Timestamp, Mention};
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§
source§impl Mention<Timestamp> for Timestamp
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
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 PartialEq for Timestamp
impl PartialEq for Timestamp
source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Timestamp
impl Eq 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 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