pub struct UtcOffset(/* private fields */);Expand description
An offset from Coordinated Universal Time (UTC).
Supports ±18:00:00.
The primary definition of this type is in the icu_time crate. Other ICU4X crates re-export it for convenience.
Implementations§
Source§impl UtcOffset
 
impl UtcOffset
Sourcepub fn try_from_seconds(seconds: i32) -> Result<Self, InvalidOffsetError>
 
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.
Sourcepub fn try_from_str(s: &str) -> Result<Self, InvalidOffsetError>
 
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::time::zone::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);Sourcepub fn try_from_utf8(code_units: &[u8]) -> Result<Self, InvalidOffsetError>
 
pub fn try_from_utf8(code_units: &[u8]) -> Result<Self, InvalidOffsetError>
Sourcepub fn from_seconds_unchecked(seconds: i32) -> Self
 
pub fn from_seconds_unchecked(seconds: i32) -> Self
Create a UtcOffset from a seconds input without checking bounds.
Sourcepub fn to_seconds(self) -> i32
 
pub fn to_seconds(self) -> i32
Returns the raw offset value in seconds.
Sourcepub fn is_non_negative(self) -> bool
 
pub fn is_non_negative(self) -> bool
Whether the UtcOffset is non-negative.
Sourcepub fn hours_part(self) -> i32
 
pub fn hours_part(self) -> i32
Returns the hours part of if the UtcOffset
Sourcepub fn minutes_part(self) -> u32
 
pub fn minutes_part(self) -> u32
Returns the minutes part of if the UtcOffset.
Sourcepub fn seconds_part(self) -> u32
 
pub fn seconds_part(self) -> u32
Returns the seconds part of if the UtcOffset.
Trait Implementations§
Source§impl IntoOption<UtcOffset> for UtcOffset
 
impl IntoOption<UtcOffset> for UtcOffset
Source§fn into_option(self) -> Option<Self>
 
fn into_option(self) -> Option<Self>
Return 
self as an Option<T>Source§impl Ord for UtcOffset
 
impl Ord for UtcOffset
Source§impl PartialOrd for UtcOffset
 
impl PartialOrd for UtcOffset
impl Copy for UtcOffset
impl Eq for UtcOffset
impl StructuralPartialEq for UtcOffset
Auto Trait Implementations§
impl Freeze for UtcOffset
impl RefUnwindSafe for UtcOffset
impl Send for UtcOffset
impl Sync for UtcOffset
impl Unpin for UtcOffset
impl UnwindSafe for UtcOffset
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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