Struct icu_timezone::UtcOffset

source ·
pub struct UtcOffset(/* private fields */);
Expand description

An offset from Coordinated Universal Time (UTC)

Implementations§

source§

impl UtcOffset

source

pub fn try_from_seconds(seconds: i32) -> Result<Self, InvalidOffsetError>

Attempt to create a UtcOffset from a seconds input.

Returns InvalidOffsetError if the seconds are out of bounds.

source

pub const fn from_eighths_of_hour(eighths_of_hour: i8) -> Self

Creates a UtcOffset from eighths of an hour.

This is chosen because eighths of an hour cover all current time zones and all values of i8 are within range of this type.

§Examples
use icu::timezone::UtcOffset;

assert_eq!(
    UtcOffset::try_from_str("-0600").unwrap(),
    UtcOffset::from_eighths_of_hour(-6 * 8),
);
source

pub const fn zero() -> Self

Creates a UtcOffset of zero.

source

pub fn try_from_str(s: &str) -> Result<Self, InvalidOffsetError>

Parse a UtcOffset from bytes.

The offset must range from UTC-12 to UTC+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::UtcOffset;

let offset0: UtcOffset = UtcOffset::try_from_str("Z").unwrap();
let offset1: UtcOffset = UtcOffset::try_from_str("+05").unwrap();
let offset2: UtcOffset = UtcOffset::try_from_str("+0500").unwrap();
let offset3: UtcOffset = UtcOffset::try_from_str("-05:00").unwrap();

let offset_err0 =
    UtcOffset::try_from_str("0500").expect_err("Invalid input");
let offset_err1 =
    UtcOffset::try_from_str("+05000").expect_err("Invalid input");

assert_eq!(offset0.to_seconds(), 0);
assert_eq!(offset1.to_seconds(), 18000);
assert_eq!(offset2.to_seconds(), 18000);
assert_eq!(offset3.to_seconds(), -18000);
source

pub fn try_from_utf8(code_units: &[u8]) -> Result<Self, InvalidOffsetError>

source

pub fn from_seconds_unchecked(seconds: i32) -> Self

Create a UtcOffset from a seconds input without checking bounds.

source

pub fn to_seconds(self) -> i32

Returns the raw offset value in seconds.

source

pub fn to_eighths_of_hour(self) -> i8

Returns the raw offset value in eights of an hour (7.5 minute units).

source

pub fn is_non_negative(self) -> bool

Whether the UtcOffset is non-negative.

source

pub fn is_zero(self) -> bool

Whether the UtcOffset is zero.

source

pub fn hours_part(self) -> i32

Returns the hours part of if the UtcOffset

source

pub fn minutes_part(self) -> u32

Returns the minutes part of if the UtcOffset.

source

pub fn seconds_part(self) -> u32

Returns the seconds part of if the UtcOffset.

Trait Implementations§

source§

impl Clone for UtcOffset

source§

fn clone(&self) -> UtcOffset

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 UtcOffset

source§

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

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

impl Default for UtcOffset

source§

fn default() -> UtcOffset

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

impl FromStr for UtcOffset

source§

type Err = InvalidOffsetError

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

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

Parses a string s to return a value of this type. Read more
source§

impl IntoOption<UtcOffset> for UtcOffset

source§

fn into_option(self) -> Option<Self>

Return self as an Option<T>
source§

impl PartialEq for UtcOffset

source§

fn eq(&self, other: &UtcOffset) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for UtcOffset

source§

impl Eq for UtcOffset

source§

impl StructuralPartialEq for UtcOffset

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
§

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

§

impl<T> MaybeSendSync for T
where T: Send + Sync,