Struct twitch_types::time::TimestampRef
source · pub struct TimestampRef(/* private fields */);
timestamp
only.Expand description
RFC3339 timestamp
Implementations§
source§impl TimestampRef
impl TimestampRef
sourcepub fn from_str(raw: &str) -> Result<&Self, TimestampParseError>
pub fn from_str(raw: &str) -> Result<&Self, TimestampParseError>
Transparently reinterprets the string slice as a strongly-typed TimestampRef if it conforms to Timestamp
sourcepub const unsafe fn from_str_unchecked(raw: &str) -> &Self
pub const unsafe fn from_str_unchecked(raw: &str) -> &Self
Transparently reinterprets the string slice as a strongly-typed TimestampRef without validating
sourcepub fn from_static(raw: &'static str) -> &'static Self
pub fn from_static(raw: &'static str) -> &'static Self
sourcepub fn into_owned(self: Box<TimestampRef>) -> Timestamp
pub fn into_owned(self: Box<TimestampRef>) -> Timestamp
Converts a Box<TimestampRef>
into a Timestamp
without copying or allocating
source§impl TimestampRef
impl TimestampRef
sourcepub fn as_cow(&self) -> Cow<'_, TimestampRef>
pub fn as_cow(&self) -> Cow<'_, TimestampRef>
Get a
Cow<'_, TimestampRef>
source§impl TimestampRef
impl 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_types::Timestamp;
let time = Timestamp::try_from("2021-07-01T13:37:00Z")?;
assert_eq!(time.normalize()?.as_ref(), &time);
let time2 = Timestamp::try_from("2021-07-01T13:37:00-01:00")?;
assert_ne!(time2.normalize()?.as_ref(), &time2);
sourcepub fn is_before<T: ?Sized>(&self, other: &T) -> boolwhere
Self: PartialOrd<T>,
pub fn is_before<T: ?Sized>(&self, other: &T) -> boolwhere
Self: PartialOrd<T>,
Compare another time and return self < other
.
§Examples
use twitch_types::Timestamp;
let time2021 = Timestamp::try_from("2021-07-01T13:37:00Z").unwrap();
let time2020 = Timestamp::try_from("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_types::Timestamp;
let time = Timestamp::try_from("2021-07-01T13:37:00Z").unwrap();
assert_eq!(time.to_day().as_str(), "2021-07-01T00:00:00Z");
sourcepub fn year(&self) -> &str
pub fn year(&self) -> &str
Get the year
§Examples
use twitch_types::Timestamp;
let time = Timestamp::try_from("2021-07-01T13:37:00Z").unwrap();
assert_eq!(time.year(), "2021");
sourcepub fn month(&self) -> &str
pub fn month(&self) -> &str
Get the month
§Examples
use twitch_types::Timestamp;
let time = Timestamp::try_from("2021-07-01T13:37:00Z").unwrap();
assert_eq!(time.month(), "07");
sourcepub fn day(&self) -> &str
pub fn day(&self) -> &str
Get the day
§Examples
use twitch_types::Timestamp;
let time = Timestamp::try_from("2021-07-01T13:37:00Z").unwrap();
assert_eq!(time.day(), "01");
sourcepub fn hour(&self) -> &str
pub fn hour(&self) -> &str
Get the hour
§Examples
use twitch_types::Timestamp;
let time = Timestamp::try_from("2021-07-01T13:37:00Z").unwrap();
assert_eq!(time.hour(), "13");
sourcepub fn minute(&self) -> &str
pub fn minute(&self) -> &str
Get the minute
§Examples
use twitch_types::Timestamp;
let time = Timestamp::try_from("2021-07-01T13:37:00Z").unwrap();
assert_eq!(time.minute(), "37");
sourcepub fn second(&self) -> &str
pub fn second(&self) -> &str
Get the second
§Examples
use twitch_types::Timestamp;
let time = Timestamp::try_from("2021-07-01T13:37:00Z").unwrap();
assert_eq!(time.second(), "00");
sourcepub fn millis(&self) -> Option<&str>
pub fn millis(&self) -> Option<&str>
Get the millis
§Examples
use twitch_types::Timestamp;
let time = Timestamp::try_from("2021-07-01T13:37:00.123Z").unwrap();
assert_eq!(time.millis(), Some("123"));
let time = Timestamp::try_from("2021-07-01T13:37:00Z").unwrap();
assert_eq!(time.millis(), None);
source§impl TimestampRef
impl TimestampRef
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
source§impl AsRef<str> for TimestampRef
impl AsRef<str> for TimestampRef
source§impl Borrow<TimestampRef> for Timestamp
impl Borrow<TimestampRef> for Timestamp
source§fn borrow(&self) -> &TimestampRef
fn borrow(&self) -> &TimestampRef
source§impl Borrow<str> for TimestampRef
impl Borrow<str> for TimestampRef
source§impl Debug for TimestampRef
impl Debug for TimestampRef
source§impl<'de: 'a, 'a> Deserialize<'de> for &'a TimestampRef
Available on crate feature serde
only.
impl<'de: 'a, 'a> Deserialize<'de> for &'a TimestampRef
serde
only.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<'de> Deserialize<'de> for Box<TimestampRef>
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for Box<TimestampRef>
serde
only.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 TimestampRef
impl Display for TimestampRef
source§impl<'a, 'b: 'a> From<&'a Cow<'b, TimestampRef>> for &'a TimestampRef
impl<'a, 'b: 'a> From<&'a Cow<'b, TimestampRef>> for &'a TimestampRef
source§fn from(r: &'a Cow<'b, TimestampRef>) -> &'a TimestampRef
fn from(r: &'a Cow<'b, TimestampRef>) -> &'a TimestampRef
source§impl<'a> From<&'a Timestamp> for &'a TimestampRef
impl<'a> From<&'a Timestamp> for &'a TimestampRef
source§impl From<&TimestampRef> for Arc<TimestampRef>
impl From<&TimestampRef> for Arc<TimestampRef>
source§fn from(r: &TimestampRef) -> Self
fn from(r: &TimestampRef) -> Self
source§impl<'a> From<&'a TimestampRef> for Cow<'a, TimestampRef>
impl<'a> From<&'a TimestampRef> for Cow<'a, TimestampRef>
source§fn from(r: &'a TimestampRef) -> Self
fn from(r: &'a TimestampRef) -> Self
source§impl From<&TimestampRef> for Rc<TimestampRef>
impl From<&TimestampRef> for Rc<TimestampRef>
source§fn from(r: &TimestampRef) -> Self
fn from(r: &TimestampRef) -> Self
source§impl From<&TimestampRef> for Timestamp
impl From<&TimestampRef> for Timestamp
source§fn from(s: &TimestampRef) -> Self
fn from(s: &TimestampRef) -> Self
source§impl Hash for TimestampRef
impl Hash for TimestampRef
source§impl<'a> IntoCow<'a, TimestampRef> for &'a Timestamp
impl<'a> IntoCow<'a, TimestampRef> for &'a Timestamp
source§fn into_cow(self) -> Cow<'a, TimestampRef>
fn into_cow(self) -> Cow<'a, TimestampRef>
source§impl<'a> IntoCow<'a, TimestampRef> for &'a TimestampRef
impl<'a> IntoCow<'a, TimestampRef> for &'a TimestampRef
source§fn into_cow(self) -> Cow<'a, TimestampRef>
fn into_cow(self) -> Cow<'a, TimestampRef>
source§impl<'a> IntoCow<'a, TimestampRef> for Timestamp
impl<'a> IntoCow<'a, TimestampRef> for Timestamp
source§fn into_cow(self) -> Cow<'a, TimestampRef>
fn into_cow(self) -> Cow<'a, TimestampRef>
source§impl PartialEq<&TimestampRef> for Timestamp
impl PartialEq<&TimestampRef> for Timestamp
source§fn eq(&self, other: &&TimestampRef) -> bool
fn eq(&self, other: &&TimestampRef) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<OffsetDateTime> for TimestampRef
Available on crate feature time
only.
impl PartialEq<OffsetDateTime> for TimestampRef
time
only.source§fn eq(&self, other: &OffsetDateTime) -> bool
fn eq(&self, other: &OffsetDateTime) -> bool
self
and other
values to be equal, and is used
by ==
.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§fn eq(&self, other: &TimestampRef) -> bool
fn eq(&self, other: &TimestampRef) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq for TimestampRef
impl PartialEq for TimestampRef
source§fn eq(&self, other: &TimestampRef) -> bool
fn eq(&self, other: &TimestampRef) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<OffsetDateTime> for TimestampRef
Available on crate feature time
only.
impl PartialOrd<OffsetDateTime> for TimestampRef
time
only.source§fn partial_cmp(&self, other: &OffsetDateTime) -> Option<Ordering>
fn partial_cmp(&self, other: &OffsetDateTime) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<Timestamp> for TimestampRef
impl PartialOrd<Timestamp> for TimestampRef
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd for TimestampRef
impl PartialOrd for TimestampRef
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Serialize for TimestampRef
Available on crate feature serde
only.
impl Serialize for TimestampRef
serde
only.source§impl ToOwned for TimestampRef
impl ToOwned for TimestampRef
source§impl<'a> TryFrom<&'a String> for &'a TimestampRef
impl<'a> TryFrom<&'a String> for &'a TimestampRef
§type Error = TimestampParseError
type Error = TimestampParseError
source§impl<'a> TryFrom<&'a str> for &'a TimestampRef
impl<'a> TryFrom<&'a str> for &'a TimestampRef
§type Error = TimestampParseError
type Error = TimestampParseError
source§impl<'zf> ZeroFrom<'zf, Timestamp> for &'zf TimestampRef
Available on crate feature zerofrom
only.
impl<'zf> ZeroFrom<'zf, Timestamp> for &'zf TimestampRef
zerofrom
only.source§impl<'zf> ZeroFrom<'zf, TimestampRef> for &'zf TimestampRef
Available on crate feature zerofrom
only.
impl<'zf> ZeroFrom<'zf, TimestampRef> for &'zf TimestampRef
zerofrom
only.source§fn zero_from(other: &'zf TimestampRef) -> Self
fn zero_from(other: &'zf TimestampRef) -> Self
C
into a struct that may retain references into C
.