[][src]Struct datetime_string::common::TimeNumOffsetColonString

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

Owned string for a time offset in +hh:mm or -hh:mm format, such as +09:00 and -00:00.

This is also an RFC 3339 time-numoffset string.

This is a fixed length string, and implements Copy trait.

To create a value of this type, use str::parse method or std::convert::TryFrom trait, or convert from &TimeNumOffsetColonStr.

Examples

use datetime_string::common::TimeNumOffsetColonStr;
use std::convert::TryFrom;

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

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

let to_owned = TimeNumOffsetColonStr::from_str("-12:34")?.to_owned();
let into: TimeNumOffsetColonString = TimeNumOffsetColonStr::from_str("-12:34")?.into();

Implementations

impl TimeNumOffsetColonString[src]

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

Returns +00:00.

Examples

let utc = TimeNumOffsetColonString::utc();
assert_eq!(utc.as_str(), "+00:00");

#[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 = TimeNumOffsetColonString::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 time = TimeNumOffsetColonString::from_minutes(9 * 60)?;
assert_eq!(time.as_str(), "+09:00");

assert!(TimeNumOffsetColonString::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 time = TimeNumOffsetColonString::from_sign_and_hm(TimeOffsetSign::Positive, 9, 30)?;
assert_eq!(time.as_str(), "+09:30");

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

assert!(
    TimeNumOffsetColonString::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 = TimeNumOffsetColonString::from_hm_signed(-9, 0)?;
assert_eq!(offset.as_str(), "-09:00");

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

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

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

Returns a &TimeNumOffsetColonStr for the string.

Examples

use datetime_string::common::TimeNumOffsetColonStr;

let offset = "-12:34".parse::<TimeNumOffsetColonString>()?;

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

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

Returns a &mut TimeNumOffsetColonStr for the string.

Examples

use datetime_string::common::TimeNumOffsetColonStr;

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

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

Methods from Deref<Target = TimeNumOffsetColonStr>

pub fn assign(&mut self, v: &Self)[src]

Assigns the given value.

Examples

let mut buf: [u8; 6] = *b"+09:00";
let offset = TimeNumOffsetColonStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(offset.as_str(), "+09:00");

let newoffset = TimeNumOffsetColonStr::from_str("-00:00")?;

offset.assign(newoffset);
assert_eq!(offset.as_str(), "-00:00");
assert_eq!(buf, *b"-00:00");

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

Returns a string slice.

Examples

let offset = TimeNumOffsetColonStr::from_str("-12:34")?;

assert_eq!(offset.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 offset = TimeNumOffsetColonStr::from_bytes(b"-12:34")?;

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

#[must_use]pub fn as_bytes_fixed_len(&self) -> &[u8; 6][src]

Returns a fixed length byte slice.

Examples

let offset = TimeNumOffsetColonStr::from_str("-12:34")?;

let fixed_len: &[u8; 6] = offset.as_bytes_fixed_len();
assert_eq!(fixed_len, b"-12:34");

#[must_use]pub fn sign(&self) -> TimeOffsetSign[src]

Returns the time offset sign.

Examples

use datetime_string::common::TimeOffsetSign;

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

let negative = TimeNumOffsetColonStr::from_str("-12:34")?;
assert_eq!(negative.sign(), TimeOffsetSign::Negative);

Note that signs are preserved for +00:00 and -00:00.

use datetime_string::common::TimeOffsetSign;

let positive0 = TimeNumOffsetColonStr::from_str("+00:00")?;
assert_eq!(positive0.sign(), TimeOffsetSign::Positive);

let negative0 = TimeNumOffsetColonStr::from_str("-00:00")?;
assert_eq!(negative0.sign(), TimeOffsetSign::Negative);

pub fn set_sign(&mut self, sign: TimeOffsetSign)[src]

Sets the given sign.

use datetime_string::common::TimeOffsetSign;

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

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

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

Returns the absolute hour as a string slice.

Examples

let offset = TimeNumOffsetColonStr::from_str("-12:34")?;

assert_eq!(offset.hour_abs_str(), "12");

#[must_use]pub fn hour_abs_bytes_fixed_len(&self) -> &[u8; 2][src]

Returns the absolute hour as a fixed length byte slice.

Examples

let offset = TimeNumOffsetColonStr::from_str("-12:34")?;

let hour_fixed_len: &[u8; 2] = offset.hour_abs_bytes_fixed_len();
assert_eq!(hour_fixed_len, b"12");

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

Returns the absolute hour as an integer.

Examples

let offset = TimeNumOffsetColonStr::from_str("-12:34")?;

assert_eq!(offset.hour_abs(), 12);

pub fn set_hour_abs(&mut self, hour_abs: u8) -> Result<(), Error>[src]

Sets the given absolute hour value to the string.

Failures

  • Fails if the time after modification is invalid.

Examples

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

time.set_hour_abs(0)?;
assert_eq!(time.as_str(), "-00:34");

assert!(time.set_hour_abs(24).is_err(), "-24:34 is invalid");

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

Returns the signed hour as a string slice.

Examples

let offset = TimeNumOffsetColonStr::from_str("-12:34")?;

assert_eq!(offset.hour_signed_str(), "-12");

#[must_use]pub fn hour_signed_bytes_fixed_len(&self) -> &[u8; 3][src]

Returns the signed hour as a fixed length byte slice.

Examples

let offset = TimeNumOffsetColonStr::from_str("-12:34")?;

let hour_fixed_len: &[u8; 3] = offset.hour_signed_bytes_fixed_len();
assert_eq!(hour_fixed_len, b"-12");

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

Returns the signed hour as an integer.

Examples

let offset = TimeNumOffsetColonStr::from_str("-12:34")?;

assert_eq!(offset.hour_signed(), -12);

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

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

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

pub fn set_sign_and_hour_abs(
    &mut self,
    sign: TimeOffsetSign,
    hour_abs: u8
) -> Result<(), Error>
[src]

Sets the given absolute hour value and sign to the string.

Failures

  • Fails if the time after modification is invalid.

Examples

use datetime_string::common::TimeOffsetSign;

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

time.set_sign_and_hour_abs(TimeOffsetSign::Positive, 23)?;
assert_eq!(time.as_str(), "+23:34");

assert!(time.set_sign_and_hour_abs(TimeOffsetSign::Negative, 24).is_err(), "-24:34 is invalid");

pub fn set_hour_signed(&mut self, hour: i8) -> Result<(), Error>[src]

Sets the given signed hour value to the string.

If 0 is passed, it is always considered as positive 0.

Failures

  • Fails if the time after modification is invalid.

Examples

use datetime_string::common::TimeOffsetSign;

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

time.set_hour_signed(0)?;
assert_eq!(time.as_str(), "+00:34");

time.set_hour_signed(-1)?;
assert_eq!(time.as_str(), "-01:34");

assert!(time.set_hour_signed(24).is_err(), "+24:34 is invalid");

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

Returns the minute as a string slice.

Examples

let offset = TimeNumOffsetColonStr::from_str("-12:34")?;

assert_eq!(offset.minute_str(), "34");

#[must_use]pub fn minute_bytes_fixed_len(&self) -> &[u8; 2][src]

Returns the minute as a fixed length byte slice.

Examples

let offset = TimeNumOffsetColonStr::from_str("-12:34")?;

let minute_fixed_len: &[u8; 2] = offset.minute_bytes_fixed_len();
assert_eq!(minute_fixed_len, b"34");

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

Returns the minute as an integer.

Examples

let offset = TimeNumOffsetColonStr::from_str("-12:34")?;

assert_eq!(offset.minute(), 34);

pub fn set_minute(&mut self, minute: u8) -> Result<(), Error>[src]

Sets the given minute value to the string.

Failures

  • Fails if the time after modification is invalid.

Examples

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

time.set_minute(01)?;
assert_eq!(time.as_str(), "-12:01");

assert!(time.set_minute(60).is_err(), "-12:60 is invalid");

pub fn set_time_signed(&mut self, hour: i8, minute: u8) -> Result<(), Error>[src]

Sets the given signed hour and minute value to the string.

If 0 is passed, it is always considered as positive 0.

Failures

  • Fails if the time after modification is invalid.

Examples

use datetime_string::common::TimeOffsetSign;

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

time.set_time_signed(0, 56)?;
assert_eq!(time.as_str(), "+00:56");

time.set_time_signed(-1, 23)?;
assert_eq!(time.as_str(), "-01:23");

assert!(time.set_time_signed(24, 00).is_err(), "+24:00 is invalid");

pub fn set_sign_and_time(
    &mut self,
    sign: TimeOffsetSign,
    hour_abs: u8,
    minute: u8
) -> Result<(), Error>
[src]

Sets the given sign, absolute hour, and minute value to the string.

If 0 is passed, it is always considered as positive 0.

Failures

  • Fails if the time after modification is invalid.

Examples

use datetime_string::common::TimeOffsetSign;

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

time.set_sign_and_time(TimeOffsetSign::Negative, 0, 56)?;
assert_eq!(time.as_str(), "-00:56");

time.set_sign_and_time(TimeOffsetSign::Positive, 1, 23)?;
assert_eq!(time.as_str(), "+01:23");

assert!(time.set_sign_and_time(TimeOffsetSign::Positive, 24, 00).is_err(), "+24:00 is invalid");

#[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 = TimeNumOffsetColonStr::from_str("-12:34")?;

assert_eq!(offset.in_minutes(), -(12 * 60 + 34));

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

use datetime_string::common::TimeOffsetSign;

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

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

pub fn set_in_minutes(&mut self, v: i16) -> Result<(), Error>[src]

Sets the time offset for the given offset in minutes.

Failures

  • Fails if the value is invalid as time offset, i.e. it is not between -1440 and 1440.

Examples

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

time.set_in_minutes(9 * 60)?;
assert_eq!(time.as_str(), "+09:00");

time.set_in_minutes(0)?;
assert_eq!(time.as_str(), "+00:00");

assert!(time.set_in_minutes(-24 * 60).is_err(), "-24:00 is invalid");

#[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 = TimeNumOffsetColonStr::from_str("+00:00")?;
assert!(!positive0.is_unknown_local_offset(), "0 minutes time offset");

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

Trait Implementations

impl AsMut<TimeNumOffsetColonStr> for TimeNumOffsetColonString[src]

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

impl AsRef<TimeNumOffsetColonStr> for TimeNumOffsetColonString[src]

impl AsRef<str> for TimeNumOffsetColonString[src]

impl Borrow<TimeNumOffsetColonStr> for TimeNumOffsetColonString[src]

impl BorrowMut<TimeNumOffsetColonStr> for TimeNumOffsetColonString[src]

impl Clone for TimeNumOffsetColonString[src]

impl Copy for TimeNumOffsetColonString[src]

impl Debug for TimeNumOffsetColonString[src]

impl Deref for TimeNumOffsetColonString[src]

type Target = TimeNumOffsetColonStr

The resulting type after dereferencing.

impl DerefMut for TimeNumOffsetColonString[src]

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

impl Display for TimeNumOffsetColonString[src]

impl Eq for TimeNumOffsetColonString[src]

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

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

impl From<TimeNumOffsetColonString> for String[src]

impl From<TimeNumOffsetColonString> for TimeOffsetString[src]

impl FromStr for TimeNumOffsetColonString[src]

type Err = Error

The associated error which can be returned from parsing.

impl Hash for TimeNumOffsetColonString[src]

impl Ord for TimeNumOffsetColonString[src]

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

impl<'_> PartialEq<&'_ TimeNumOffsetColonStr> for TimeNumOffsetColonString[src]

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

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

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

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

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

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

impl PartialEq<TimeNumOffsetColonStr> for TimeNumOffsetColonString[src]

impl PartialEq<TimeNumOffsetColonString> for TimeNumOffsetColonString[src]

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

impl PartialEq<TimeNumOffsetColonString> for TimeNumOffsetColonStr[src]

impl<'_> PartialEq<TimeNumOffsetColonString> for &'_ TimeNumOffsetColonStr[src]

impl PartialEq<TimeNumOffsetColonString> for str[src]

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

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

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

impl PartialEq<str> for TimeNumOffsetColonString[src]

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

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

impl<'_> PartialOrd<&'_ TimeNumOffsetColonStr> for TimeNumOffsetColonString[src]

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

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

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

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

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

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

impl PartialOrd<TimeNumOffsetColonStr> for TimeNumOffsetColonString[src]

impl PartialOrd<TimeNumOffsetColonString> for TimeNumOffsetColonString[src]

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

impl PartialOrd<TimeNumOffsetColonString> for TimeNumOffsetColonStr[src]

impl<'_> PartialOrd<TimeNumOffsetColonString> for &'_ TimeNumOffsetColonStr[src]

impl PartialOrd<TimeNumOffsetColonString> for str[src]

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

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

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

impl PartialOrd<str> for TimeNumOffsetColonString[src]

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

impl Serialize for TimeNumOffsetColonString[src]

impl StructuralEq for TimeNumOffsetColonString[src]

impl StructuralPartialEq for TimeNumOffsetColonString[src]

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

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ FixedOffset> for TimeNumOffsetColonString[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(v: &FixedOffset) -> Result<Self, Self::Error>[src]

Converts the given offset into TimeNumOffsetColonString.

Failures

Fails when the second is not zero (for example, +00:00:30).

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

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<[u8; 6]> for TimeNumOffsetColonString[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> 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.