[][src]Struct datetime_string::rfc3339::TimeOffsetString

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

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

Available when alloc feature is enabled.

Examples

use datetime_string::rfc3339::TimeOffsetStr;
use std::convert::TryFrom;

let try_from = TimeOffsetString::try_from("-12:34")?;

let parse = "-12:34".parse::<TimeOffsetString>()?;
let parse2: TimeOffsetString = "-12:34".parse()?;

let to_owned = TimeOffsetStr::from_str("-12:34")?.to_owned();
let into: TimeOffsetString = TimeOffsetStr::from_str("-12:34")?.into();

Implementations

impl TimeOffsetString[src]

#[must_use]pub fn z() -> Self[src]

Returns Z.

Examples

let z = TimeOffsetString::z();

assert_eq!(z.as_str(), "Z");

#[must_use]pub fn unknown_local_offset() -> Self[src]

Returns -00:00, which is defined in RFC 3339 to indicate "unknown local offset".

Examples

let unknown_local_offset = TimeOffsetString::unknown_local_offset();
assert_eq!(unknown_local_offset.as_str(), "-00:00");

pub fn from_minutes(minutes: i16) -> Result<Self, Error>[src]

Creates a new TimeNumOffsetColonStr from the given minutes.

Examples

let offset = TimeOffsetString::from_minutes(9 * 60)?;
assert_eq!(offset.as_str(), "+09:00");

assert!(TimeOffsetString::from_minutes(-24 * 60).is_err(), "-24:00 is invaild time");

pub fn from_sign_and_hm(
    sign: TimeOffsetSign,
    hour_abs: u8,
    minute: u8
) -> Result<Self, Error>
[src]

Creates a new TimeNumOffsetColonStr from the given minutes.

Examples

use datetime_string::common::TimeOffsetSign;
let offset = TimeOffsetString::from_sign_and_hm(TimeOffsetSign::Positive, 9, 30)?;
assert_eq!(offset.as_str(), "+09:30");

let unknown_local_offset = TimeOffsetString::from_sign_and_hm(TimeOffsetSign::Negative, 0, 0)?;
assert_eq!(unknown_local_offset.as_str(), "-00:00");

assert!(
    TimeOffsetString::from_sign_and_hm(TimeOffsetSign::Negative, 24, 0).is_err(),
    "-24:00 is invaild time"
);

pub fn from_hm_signed(hour: i8, minute: u8) -> Result<Self, Error>[src]

Creates a new TimeNumOffsetColonStr from the given minutes.

Examples

let offset = TimeOffsetString::from_hm_signed(-9, 0)?;
assert_eq!(offset.as_str(), "-09:00");

let unknown_local_offset = TimeOffsetString::from_hm_signed(0, 0)?;
assert_eq!(unknown_local_offset.as_str(), "+00:00");

assert!( TimeOffsetString::from_hm_signed(-24, 0).is_err(), "-24:00 is invaild time");

#[must_use]pub fn as_deref(&self) -> &TimeOffsetStr[src]

Returns a &TimeOffsetStr for the string.

Examples

use datetime_string::rfc3339::TimeOffsetStr;

let secfrac = "-12:34".parse::<TimeOffsetString>()?;

// Usually you don't need to call `as_deref()` explicitly, because
// `Deref<Target = TimeOffsetStr>` trait is implemented.
let _: &TimeOffsetStr = secfrac.as_deref();

#[must_use]pub fn as_deref_mut(&mut self) -> &mut TimeOffsetStr[src]

Returns a &mut TimeOffsetStr for the string.

Examples

use datetime_string::rfc3339::TimeOffsetStr;

let mut secfrac = "-12:34".parse::<TimeOffsetString>()?;

// Usually you don't need to call `as_deref_mut()` explicitly, because
// `DerefMut` trait is implemented.
let _: &mut TimeOffsetStr = secfrac.as_deref_mut();

Methods from Deref<Target = TimeOffsetStr>

#[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 AsRef<[u8]> for TimeOffsetString[src]

impl AsRef<TimeOffsetStr> for TimeOffsetString[src]

impl AsRef<str> for TimeOffsetString[src]

impl Borrow<TimeOffsetStr> for TimeOffsetString[src]

impl BorrowMut<TimeOffsetStr> for TimeOffsetString[src]

impl Clone for TimeOffsetString[src]

impl Debug for TimeOffsetString[src]

impl Deref for TimeOffsetString[src]

type Target = TimeOffsetStr

The resulting type after dereferencing.

impl DerefMut for TimeOffsetString[src]

impl<'de> Deserialize<'de> for TimeOffsetString[src]

impl Display for TimeOffsetString[src]

impl Eq for TimeOffsetString[src]

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

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

impl From<TimeNumOffsetColonString> for TimeOffsetString[src]

impl From<TimeOffsetString> for Vec<u8>[src]

impl From<TimeOffsetString> for String[src]

impl FromStr for TimeOffsetString[src]

type Err = Error

The associated error which can be returned from parsing.

impl Hash for TimeOffsetString[src]

impl Ord for TimeOffsetString[src]

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

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

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

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

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

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

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

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

impl PartialEq<TimeOffsetStr> for TimeOffsetString[src]

impl PartialEq<TimeOffsetString> for TimeOffsetString[src]

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

impl PartialEq<TimeOffsetString> for TimeOffsetStr[src]

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

impl PartialEq<TimeOffsetString> for str[src]

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

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

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

impl PartialEq<str> for TimeOffsetString[src]

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

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

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

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

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

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

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

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

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

impl PartialOrd<TimeOffsetStr> for TimeOffsetString[src]

impl PartialOrd<TimeOffsetString> for TimeOffsetString[src]

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

impl PartialOrd<TimeOffsetString> for TimeOffsetStr[src]

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

impl PartialOrd<TimeOffsetString> for str[src]

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

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

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

impl PartialOrd<str> for TimeOffsetString[src]

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

impl Serialize for TimeOffsetString[src]

impl StructuralEq for TimeOffsetString[src]

impl StructuralPartialEq for TimeOffsetString[src]

impl<'_> TryFrom<&'_ [u8]> for TimeOffsetString[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ str> for TimeOffsetString[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<String> for TimeOffsetString[src]

type Error = ConversionError<String>

The type returned in the event of a conversion error.

impl TryFrom<Vec<u8>> for TimeOffsetString[src]

type Error = ConversionError<Vec<u8>>

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> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[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]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.