pub struct Timestamp(/* private fields */);
Expand description
RFC3339 timestamp
Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn new<S: Into<String> + AsRef<str>>(
s: S,
) -> Result<Self, <Timestamp as Validator>::Error>
pub fn new<S: Into<String> + AsRef<str>>( s: S, ) -> Result<Self, <Timestamp as Validator>::Error>
Constructs a new Timestamp if it conforms to Timestamp
Sourcepub unsafe fn new_unchecked<S: Into<String>>(s: S) -> Self
pub unsafe fn new_unchecked<S: Into<String>>(s: S) -> Self
Sourcepub fn into_boxed_ref(self) -> Box<TimestampRef>
pub fn into_boxed_ref(self) -> Box<TimestampRef>
Converts this Timestamp
into a Box
<
TimestampRef
>
This will drop any excess capacity.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Unwraps the underlying String
value
Methods from Deref<Target = TimestampRef>§
Sourcepub fn normalize(&self) -> Result<Cow<'_, TimestampRef>, TimestampParseError>
pub fn normalize(&self) -> Result<Cow<'_, TimestampRef>, TimestampParseError>
Normalize the timestamp into UTC time.
§Examples
use twitch_api2::types::Timestamp;
let time = Timestamp::new("2021-07-01T13:37:00Z").unwrap();
assert_eq!(time.normalize()?.as_ref(), &time);
let time2 = Timestamp::new("2021-07-01T13:37:00-01:00").unwrap();
assert_ne!(time2.normalize()?.as_ref(), &time2);
Sourcepub fn is_before<T>(&self, other: &T) -> boolwhere
Self: PartialOrd<T>,
pub fn is_before<T>(&self, other: &T) -> boolwhere
Self: PartialOrd<T>,
Compare another time and return self < other
.
§Examples
use twitch_api2::types::Timestamp;
let time2021 = Timestamp::new("2021-07-01T13:37:00Z").unwrap();
let time2020 = Timestamp::new("2020-07-01T13:37:00Z").unwrap();
assert!(time2020.is_before(&time2021));
Sourcepub fn to_day(&self) -> Timestamp
pub fn to_day(&self) -> Timestamp
Make a timestamp with the time component set to 00:00:00.
§Examples
use twitch_api2::types::Timestamp;
let time = Timestamp::new("2021-07-01T13:37:00Z").unwrap();
assert_eq!(time.to_day().as_str(), "2021-07-01T00:00:00Z")
Sourcepub fn to_utc(&self) -> OffsetDateTime
Available on crate feature time
only.
pub fn to_utc(&self) -> OffsetDateTime
time
only.Construct into a OffsetDateTime
time with a guaranteed UTC offset.
§Panics
This method assumes the timestamp is a valid rfc3339 timestamp, and panics if not.
Sourcepub fn to_fixed_offset(&self) -> OffsetDateTime
Available on crate feature time
only.
pub fn to_fixed_offset(&self) -> OffsetDateTime
time
only.Construct into a OffsetDateTime
time.
§Panics
This method assumes the timestamp is a valid rfc3339 timestamp, and panics if not.
Trait Implementations§
Source§impl AsRef<TimestampRef> for Timestamp
impl AsRef<TimestampRef> for Timestamp
Source§fn as_ref(&self) -> &TimestampRef
fn as_ref(&self) -> &TimestampRef
Converts this type into a shared reference of the (usually inferred) input type.
Source§impl Borrow<TimestampRef> for Timestamp
impl Borrow<TimestampRef> for Timestamp
Source§fn borrow(&self) -> &TimestampRef
fn borrow(&self) -> &TimestampRef
Immutably borrows from an owned value. Read more
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>
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<&TimestampRef> for Timestamp
impl From<&TimestampRef> for Timestamp
Source§fn from(s: &TimestampRef) -> Self
fn from(s: &TimestampRef) -> Self
Converts to this type from the input type.
Source§impl From<Box<TimestampRef>> for Timestamp
impl From<Box<TimestampRef>> for Timestamp
Source§fn from(r: Box<TimestampRef>) -> Self
fn from(r: Box<TimestampRef>) -> Self
Converts to this type from the input type.
Source§impl<'a> From<Cow<'a, TimestampRef>> for Timestamp
impl<'a> From<Cow<'a, TimestampRef>> for Timestamp
Source§fn from(r: Cow<'a, TimestampRef>) -> Self
fn from(r: Cow<'a, TimestampRef>) -> Self
Converts to this type from the input type.
Source§impl PartialEq<&TimestampRef> for Timestamp
impl PartialEq<&TimestampRef> for Timestamp
Source§impl PartialEq<OffsetDateTime> for Timestamp
Available on crate feature time
only.
impl PartialEq<OffsetDateTime> for Timestamp
Available on crate feature
time
only.Source§impl PartialEq<Timestamp> for &TimestampRef
impl PartialEq<Timestamp> for &TimestampRef
Source§impl PartialEq<Timestamp> for TimestampRef
impl PartialEq<Timestamp> for TimestampRef
Source§impl PartialEq<TimestampRef> for Timestamp
impl PartialEq<TimestampRef> for Timestamp
Source§impl PartialOrd<OffsetDateTime> for Timestamp
Available on crate feature time
only.
impl PartialOrd<OffsetDateTime> for Timestamp
Available on crate feature
time
only.Source§impl PartialOrd<Timestamp> for TimestampRef
impl PartialOrd<Timestamp> for TimestampRef
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl TryFrom<OffsetDateTime> for Timestamp
Available on crate feature time
only.
impl TryFrom<OffsetDateTime> for Timestamp
Available on crate feature
time
only.impl Eq 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.