[][src]Struct datetime_string::rfc3339::TimeOffsetStr

#[repr(transparent)]pub struct TimeOffsetStr(_);

String slice for a time in RFC 3339 time-offset format, such as +09:00, -00:00, and Z.

Implementations

impl TimeOffsetStr[src]

pub fn from_str(s: &str) -> Result<&Self, Error>[src]

Creates a new &TimeOffsetStr from a string slice.

Examples

let time = TimeOffsetStr::from_str("-12:34")?;
assert_eq!(time.as_str(), "-12:34");

assert!(TimeOffsetStr::from_str("Z").is_ok());
assert!(TimeOffsetStr::from_str("+00:00").is_ok());
assert!(TimeOffsetStr::from_str("+23:59").is_ok());
assert!(TimeOffsetStr::from_str("-00:00").is_ok());
assert!(TimeOffsetStr::from_str("-23:59").is_ok());

assert!(TimeOffsetStr::from_str("z").is_err(), "lowercase Z is not allowed");
assert!(TimeOffsetStr::from_str("a").is_err(), "Invalid name");
assert!(TimeOffsetStr::from_str("+24:00").is_err(), "Invalid hour");
assert!(TimeOffsetStr::from_str("+00:60").is_err(), "Invalid minute");
assert!(TimeOffsetStr::from_str("-24:00").is_err(), "Invalid hour");
assert!(TimeOffsetStr::from_str("-00:60").is_err(), "Invalid minute");
assert!(TimeOffsetStr::from_str("?00:00").is_err(), "Invalid sign");
assert!(TimeOffsetStr::from_str("00:00").is_err(), "Sign is missing");

pub fn from_mut_str(s: &mut str) -> Result<&mut Self, Error>[src]

Creates a new &mut TimeOffsetStr from a mutable string slice.

Examples

use datetime_string::common::TimeOffsetSign;

let mut buf = "-12:34".to_owned();
let offset = TimeOffsetStr::from_mut_str(&mut buf)?;
assert_eq!(offset.as_str(), "-12:34");

offset.to_numoffset_mut().unwrap().set_sign(TimeOffsetSign::Positive);
assert_eq!(offset.as_str(), "+12:34");

pub fn from_bytes(s: &[u8]) -> Result<&Self, Error>[src]

Creates a new &TimeOffsetStr from a byte slice.

Examples

let time = TimeOffsetStr::from_bytes(b"-12:34")?;
assert_eq!(time.as_str(), "-12:34");

assert!(TimeOffsetStr::from_bytes(b"Z").is_ok());
assert!(TimeOffsetStr::from_bytes(b"+00:00").is_ok());
assert!(TimeOffsetStr::from_bytes(b"+23:59").is_ok());
assert!(TimeOffsetStr::from_bytes(b"-00:00").is_ok());
assert!(TimeOffsetStr::from_bytes(b"-23:59").is_ok());

assert!(TimeOffsetStr::from_bytes(b"z").is_err(), "lowercase Z is not allowed");
assert!(TimeOffsetStr::from_bytes(b"a").is_err(), "Invalid name");
assert!(TimeOffsetStr::from_bytes(b"+24:00").is_err(), "Invalid hour");
assert!(TimeOffsetStr::from_bytes(b"+00:60").is_err(), "Invalid minute");
assert!(TimeOffsetStr::from_bytes(b"-24:00").is_err(), "Invalid hour");
assert!(TimeOffsetStr::from_bytes(b"-00:60").is_err(), "Invalid minute");
assert!(TimeOffsetStr::from_bytes(b"?00:00").is_err(), "Invalid sign");
assert!(TimeOffsetStr::from_bytes(b"00:00").is_err(), "Sign is missing");

pub fn from_bytes_mut(s: &mut [u8]) -> Result<&mut Self, Error>[src]

Creates a new &mut TimeOffsetStr from a mutable byte slice.

Examples

use datetime_string::common::TimeOffsetSign;

let mut buf: [u8; 6] = *b"-12:34";
let offset = TimeOffsetStr::from_bytes_mut(&mut buf)?;
assert_eq!(offset.as_str(), "-12:34");

offset.to_numoffset_mut().unwrap().set_sign(TimeOffsetSign::Positive);
assert_eq!(offset.as_str(), "+12:34");

#[must_use]pub fn as_str(&self) -> &str[src]

Returns a string slice.

Examples

let time = TimeOffsetStr::from_str("-12:34")?;

assert_eq!(time.as_str(), "-12:34");

#[must_use]pub fn as_bytes(&self) -> &[u8][src]

Returns a byte slice.

If you want to use indexed access, prefer as_bytes_fixed_len.

Examples

let time = TimeOffsetStr::from_str("-12:34")?;

assert_eq!(time.as_bytes(), b"-12:34");

pub fn sign(&self) -> Option<TimeOffsetSign>[src]

Returns a sign if available.

Examples

use datetime_string::common::TimeOffsetSign;

let positive = TimeOffsetStr::from_str("+12:34")?;
assert_eq!(positive.sign(), Some(TimeOffsetSign::Positive));

let negative = TimeOffsetStr::from_str("-00:00")?;
assert_eq!(negative.sign(), Some(TimeOffsetSign::Negative));

let zulu = TimeOffsetStr::from_str("Z")?;
assert_eq!(zulu.sign(), None);

pub fn to_numoffset(&self) -> Option<&TimeNumOffsetStr>[src]

Returns a &TimeNumOffsetStr if the time offset is not Z.

Examples

let numoffset = TimeOffsetStr::from_str("+12:34")?;
assert_eq!(numoffset.to_numoffset().unwrap().hour_abs(), 12);

let zulu = TimeOffsetStr::from_str("Z")?;
assert_eq!(zulu.to_numoffset(), None);

pub fn to_numoffset_mut(&mut self) -> Option<&mut TimeNumOffsetStr>[src]

Returns a &mut TimeNumOffsetStr if the time offset is not Z.

Examples

let mut buf_num = "+12:34".to_owned();
let numoffset = TimeOffsetStr::from_mut_str(&mut buf_num)?;
numoffset.to_numoffset_mut().unwrap().set_hour_abs(23);
assert_eq!(numoffset.as_str(), "+23:34");
assert_eq!(buf_num, "+23:34");

let mut buf_zulu = "Z".to_owned();
let zulu = TimeOffsetStr::from_mut_str(&mut buf_zulu)?;
assert_eq!(zulu.to_numoffset_mut(), None);

#[must_use]pub fn hour_abs(&self) -> u8[src]

Returns the absolute hour as an integer.

Examples

let offset = TimeOffsetStr::from_str("-12:34")?;
assert_eq!(offset.hour_abs(), 12);

let zulu = TimeOffsetStr::from_str("Z")?;
assert_eq!(zulu.hour_abs(), 0);

let negative0 = TimeOffsetStr::from_str("-00:00")?;
assert_eq!(negative0.hour_abs(), 0);

#[must_use]pub fn hour_signed(&self) -> i8[src]

Returns the signed hour as an integer.

Examples

let offset = TimeOffsetStr::from_str("-12:34")?;
assert_eq!(offset.hour_signed(), -12);

let zulu = TimeOffsetStr::from_str("Z")?;
assert_eq!(zulu.hour_signed(), 0);

Note that both +00 and -00 are treaded as the same 0.

let positive = TimeOffsetStr::from_str("+00:59")?;
assert_eq!(positive.hour_signed(), 0);

let negative = TimeOffsetStr::from_str("-00:59")?;
assert_eq!(negative.hour_signed(), 0);

#[must_use]pub fn minute(&self) -> u8[src]

Returns the minute as an integer.

Examples

let offset = TimeOffsetStr::from_str("-12:34")?;
assert_eq!(offset.minute(), 34);

let zulu = TimeOffsetStr::from_str("Z")?;
assert_eq!(zulu.minute(), 0);

#[must_use]pub fn in_minutes(&self) -> i16[src]

Returns the time offset in minutes.

Note that both +00:00 and -00:00 is considered as 0 minutes offset. RFC 3339 defines semantics of -00:00 as "unknown local offset". If your application should be aware of that semantics, use is_unknown_local_offset method or sign method to distinguish them.

Examples

let offset = TimeOffsetStr::from_str("-12:34")?;
assert_eq!(offset.in_minutes(), -(12 * 60 + 34));

let zulu = TimeOffsetStr::from_str("Z")?;
assert_eq!(zulu.in_minutes(), 0);

0 is returned for both +00:00 and -00:00.

use datetime_string::common::TimeOffsetSign;

let positive0 = TimeOffsetStr::from_str("+00:00")?;
assert_eq!(positive0.in_minutes(), 0);
assert_eq!(positive0.sign(), Some(TimeOffsetSign::Positive));
assert!(!positive0.is_unknown_local_offset(), "0 minutes time offset");

let negative0 = TimeOffsetStr::from_str("-00:00")?;
assert_eq!(negative0.in_minutes(), 0);
assert_eq!(negative0.sign(), Some(TimeOffsetSign::Negative));
assert!(negative0.is_unknown_local_offset(), "unknown local offset");

#[must_use]pub fn is_unknown_local_offset(&self) -> bool[src]

Returns true if and only if the time offset means "unknown local offset" in RFC 3339.

RFC 3339 defines -00:00 as "unknown local offset".

If the time in UTC is known, but the offset to local time is unknown, this can be represented with an offset of "-00:00". This differs semantically from an offset of "Z" or "+00:00", which imply that UTC is the preferred reference point for the specified time.

--- RFC 3339, section 4.3. Unknown Local Offset Convention

This method returns true for -00:00.

Examples

use datetime_string::common::TimeOffsetSign;

let positive0 = TimeOffsetStr::from_str("+00:00")?;
assert!(!positive0.is_unknown_local_offset(), "0 minutes time offset");

let zulu = TimeOffsetStr::from_str("Z")?;
assert!(!zulu.is_unknown_local_offset(), "UTC");

let negative0 = TimeOffsetStr::from_str("-00:00")?;
assert!(negative0.is_unknown_local_offset(), "unknown local offset");

Trait Implementations

impl AsMut<TimeOffsetStr> for TimeOffsetString[src]

impl AsMut<TimeOffsetStr> for TimeOffsetStr[src]

impl AsRef<[u8]> for TimeOffsetStr[src]

impl AsRef<TimeOffsetStr> for TimeOffsetString[src]

impl AsRef<TimeOffsetStr> for TimeOffsetStr[src]

impl AsRef<str> for TimeOffsetStr[src]

impl Borrow<TimeOffsetStr> for TimeOffsetString[src]

impl BorrowMut<TimeOffsetStr> for TimeOffsetString[src]

impl Debug for TimeOffsetStr[src]

impl Deref for TimeOffsetStr[src]

type Target = str

The resulting type after dereferencing.

impl<'de> Deserialize<'de> for &'de TimeOffsetStr[src]

impl Display for TimeOffsetStr[src]

impl Eq for TimeOffsetStr[src]

impl<'_> From<&'_ TimeOffsetStr> for TimeOffsetString[src]

impl<'_> From<&'_ TimeOffsetStr> for FixedOffset[src]

impl<'a> From<&'a TimeOffsetStr> for &'a str[src]

impl Hash for TimeOffsetStr[src]

impl Ord for TimeOffsetStr[src]

impl<'_> PartialEq<&'_ [u8]> for TimeOffsetStr[src]

impl<'_> PartialEq<&'_ TimeOffsetStr> for TimeOffsetString[src]

impl<'_> PartialEq<&'_ TimeOffsetStr> for TimeOffsetStr[src]

impl<'_> PartialEq<&'_ TimeOffsetStr> for [u8][src]

impl<'_> PartialEq<&'_ TimeOffsetStr> for str[src]

impl<'_> PartialEq<&'_ str> for TimeOffsetStr[src]

impl PartialEq<[u8]> for TimeOffsetStr[src]

impl<'_> PartialEq<[u8]> for &'_ TimeOffsetStr[src]

impl PartialEq<TimeOffsetStr> for TimeOffsetString[src]

impl PartialEq<TimeOffsetStr> for TimeOffsetStr[src]

impl<'_> PartialEq<TimeOffsetStr> for &'_ TimeOffsetStr[src]

impl PartialEq<TimeOffsetStr> for [u8][src]

impl<'_> PartialEq<TimeOffsetStr> for &'_ [u8][src]

impl PartialEq<TimeOffsetStr> for str[src]

impl<'_> PartialEq<TimeOffsetStr> for &'_ str[src]

impl PartialEq<TimeOffsetString> for TimeOffsetStr[src]

impl<'_> PartialEq<TimeOffsetString> for &'_ TimeOffsetStr[src]

impl PartialEq<str> for TimeOffsetStr[src]

impl<'_> PartialEq<str> for &'_ TimeOffsetStr[src]

impl<'_> PartialOrd<&'_ [u8]> for TimeOffsetStr[src]

impl<'_> PartialOrd<&'_ TimeOffsetStr> for TimeOffsetString[src]

impl<'_> PartialOrd<&'_ TimeOffsetStr> for TimeOffsetStr[src]

impl<'_> PartialOrd<&'_ TimeOffsetStr> for [u8][src]

impl<'_> PartialOrd<&'_ TimeOffsetStr> for str[src]

impl<'_> PartialOrd<&'_ str> for TimeOffsetStr[src]

impl PartialOrd<[u8]> for TimeOffsetStr[src]

impl<'_> PartialOrd<[u8]> for &'_ TimeOffsetStr[src]

impl PartialOrd<TimeOffsetStr> for TimeOffsetString[src]

impl PartialOrd<TimeOffsetStr> for TimeOffsetStr[src]

impl<'_> PartialOrd<TimeOffsetStr> for &'_ TimeOffsetStr[src]

impl PartialOrd<TimeOffsetStr> for [u8][src]

impl<'_> PartialOrd<TimeOffsetStr> for &'_ [u8][src]

impl PartialOrd<TimeOffsetStr> for str[src]

impl<'_> PartialOrd<TimeOffsetStr> for &'_ str[src]

impl PartialOrd<TimeOffsetString> for TimeOffsetStr[src]

impl<'_> PartialOrd<TimeOffsetString> for &'_ TimeOffsetStr[src]

impl PartialOrd<str> for TimeOffsetStr[src]

impl<'_> PartialOrd<str> for &'_ TimeOffsetStr[src]

impl Serialize for TimeOffsetStr[src]

impl StructuralEq for TimeOffsetStr[src]

impl StructuralPartialEq for TimeOffsetStr[src]

impl ToOwned for TimeOffsetStr[src]

type Owned = TimeOffsetString

The resulting type after obtaining ownership.

impl<'a> TryFrom<&'a [u8]> for &'a TimeOffsetStr[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a mut [u8]> for &'a mut TimeOffsetStr[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a mut str> for &'a mut TimeOffsetStr[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a str> for &'a TimeOffsetStr[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]