Struct icu_timezone::UtcOffset
source · pub struct UtcOffset(/* private fields */);
Expand description
An offset from Coordinated Universal Time (UTC)
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 const fn from_eighths_of_hour(eighths_of_hour: i8) -> Self
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),
);
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::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);
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 to_eighths_of_hour(self) -> i8
pub fn to_eighths_of_hour(self) -> i8
Returns the raw offset value in eights of an hour (7.5 minute units).
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>
self
as an Option<T>
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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>
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>
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