Struct icu_timezone::types::GmtOffset

source ·
pub struct GmtOffset(i32);
Expand description

The GMT offset in seconds for a timezone

Tuple Fields§

§0: i32

Implementations§

source§

impl GmtOffset

source

pub fn try_from_offset_seconds(seconds: i32) -> Result<Self, TimeZoneError>

Attempt to create a GmtOffset from a seconds input. It returns TimeZoneError::OffsetOutOfBounds when the seconds are out of bounds.

source

pub const fn utc() -> Self

Creates a GmtOffset at UTC.

source

pub fn try_from_bytes(chars: &[u8]) -> Result<Self, TimeZoneError>

Parse a GmtOffset from bytes.

The offset must range from GMT-12 to GMT+14. The string must be an ISO-8601 time zone designator: e.g. Z e.g. +05 e.g. +0500 e.g. +05:00

§Examples
use icu::timezone::GmtOffset;
use icu::timezone::TimeZoneError;

let offset0: GmtOffset =
    GmtOffset::try_from_bytes(b"Z").expect("Failed to parse a time zone");
let offset1: GmtOffset =
    GmtOffset::try_from_bytes(b"+05").expect("Failed to parse a time zone");
let offset2: GmtOffset = GmtOffset::try_from_bytes(b"+0500")
    .expect("Failed to parse a time zone");
let offset3: GmtOffset = GmtOffset::try_from_bytes(b"-05:00")
    .expect("Failed to parse a time zone");
let offset_err0: TimeZoneError =
    GmtOffset::try_from_bytes(b"0500").expect_err("Invalid input");
let offset_err1: TimeZoneError =
    GmtOffset::try_from_bytes(b"+05000").expect_err("Invalid input");

assert_eq!(offset0.offset_seconds(), 0);
assert_eq!(offset1.offset_seconds(), 18000);
assert_eq!(offset2.offset_seconds(), 18000);
assert_eq!(offset3.offset_seconds(), -18000);
assert_eq!(offset_err0, TimeZoneError::InvalidOffset);
assert_eq!(offset_err1, TimeZoneError::InvalidOffset);
source

pub unsafe fn from_offset_seconds_unchecked(seconds: i32) -> Self

Create a GmtOffset from a seconds input without checking bounds.

§Safety

The seconds must be a valid value as returned by Self::offset_seconds.

source

pub fn offset_seconds(self) -> i32

Returns the raw offset value in seconds.

source

pub fn is_positive(self) -> bool

Returns true if the GmtOffset is positive, otherwise false.

source

pub fn is_zero(self) -> bool

Returns true if the GmtOffset is zero, otherwise false.

source

pub fn has_minutes(self) -> bool

Returns true if the GmtOffset has non-zero minutes, otherwise false.

source

pub fn has_seconds(self) -> bool

Returns true if the GmtOffset has non-zero seconds, otherwise false.

Trait Implementations§

source§

impl Clone for GmtOffset

source§

fn clone(&self) -> GmtOffset

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for GmtOffset

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for GmtOffset

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl FromStr for GmtOffset

source§

fn from_str(input: &str) -> Result<Self, Self::Err>

Parse a GmtOffset from a string.

The offset must range from GMT-12 to GMT+14. The string must be an ISO 8601 time zone designator: e.g. Z e.g. +05 e.g. +0500 e.g. +05:00

§Examples
use icu::timezone::GmtOffset;

let offset0: GmtOffset = "Z".parse().expect("Failed to parse a GMT offset");
let offset1: GmtOffset =
    "-09".parse().expect("Failed to parse a GMT offset");
let offset2: GmtOffset =
    "-0930".parse().expect("Failed to parse a GMT offset");
let offset3: GmtOffset =
    "-09:30".parse().expect("Failed to parse a GMT offset");
source§

type Err = TimeZoneError

The associated error which can be returned from parsing.
source§

impl Copy for GmtOffset

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T