Struct discord_flows::model::Timestamp
source · pub struct Timestamp(/* private fields */);
Expand description
Representation of a Unix timestamp.
The struct implements the std::fmt::Display
trait to format the underlying type as
an RFC 3339 date and string such as 2016-04-30T11:18:25.796Z
.
let timestamp: Timestamp = GuildId(175928847299117063).created_at();
assert_eq!(timestamp.unix_timestamp(), 1462015105);
assert_eq!(timestamp.to_string(), "2016-04-30T11:18:25.796Z");
Implementations§
source§impl Timestamp
impl Timestamp
sourcepub fn from_unix_timestamp(secs: i64) -> Result<Timestamp, InvalidTimestamp>
pub fn from_unix_timestamp(secs: i64) -> Result<Timestamp, InvalidTimestamp>
Create a new Timestamp
from a UNIX timestamp.
Errors
Returns Err
if the value is invalid. The valid range of the value may vary depending on
the feature flags enabled (time
with large-dates
).
sourcepub fn unix_timestamp(&self) -> i64
pub fn unix_timestamp(&self) -> i64
Returns the number of non-leap seconds since January 1, 1970 0:00:00 UTC
sourcepub fn parse(input: &str) -> Result<Timestamp, ParseError>
pub fn parse(input: &str) -> Result<Timestamp, ParseError>
Parse a timestamp from an RFC 3339 date and time string.
Examples
let timestamp = Timestamp::parse("2016-04-30T11:18:25Z").unwrap();
let timestamp = Timestamp::parse("2016-04-30T11:18:25+00:00").unwrap();
let timestamp = Timestamp::parse("2016-04-30T11:18:25.796Z").unwrap();
assert!(Timestamp::parse("2016-04-30T11:18:25").is_err());
assert!(Timestamp::parse("2016-04-30T11:18").is_err());
Errors
Returns Err
if the string is not a valid RFC 3339 date and time string.
Methods from Deref<Target = OffsetDateTime>§
pub const UNIX_EPOCH: OffsetDateTime = _
Trait Implementations§
source§impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Timestamp, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>( __deserializer: __D ) -> Result<Timestamp, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for Timestamp
impl Ord for Timestamp
source§impl PartialEq<Timestamp> for Timestamp
impl PartialEq<Timestamp> for Timestamp
source§impl PartialOrd<Timestamp> for Timestamp
impl PartialOrd<Timestamp> 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 moresource§impl Serialize for Timestamp
impl Serialize for Timestamp
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where __S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Copy for Timestamp
impl Eq for Timestamp
impl StructuralEq for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations§
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