pub struct UtcOffset {
hours: RangedI8<-25, 25>,
minutes: RangedI8<{ _ }, { _ }>,
seconds: RangedI8<{ _ }, { _ }>,
}
Expand description
An offset from UTC.
This struct can store values up to ±25:59:59. If you need support outside this range, please file an issue with your use case.
Fields§
§hours: RangedI8<-25, 25>
§minutes: RangedI8<{ _ }, { _ }>
§seconds: RangedI8<{ _ }, { _ }>
Implementations§
Source§impl UtcOffset
impl UtcOffset
Source#[doc(hidden)] pub const unsafe fn __from_hms_unchecked(
hours: i8,
minutes: i8,
seconds: i8,
) -> Self
#[doc(hidden)] pub const unsafe fn __from_hms_unchecked( hours: i8, minutes: i8, seconds: i8, ) -> Self
Create a UtcOffset
representing an offset of the hours, minutes, and seconds provided, the
validity of which must be guaranteed by the caller. All three parameters must have the same
sign.
§Safety
- Hours must be in the range
-25..=25
. - Minutes must be in the range
-59..=59
. - Seconds must be in the range
-59..=59
.
While the signs of the parameters are required to match to avoid bugs, this is not a safety invariant.
Sourcepub const fn from_hms(
hours: i8,
minutes: i8,
seconds: i8,
) -> Result<Self, ComponentRange>
pub const fn from_hms( hours: i8, minutes: i8, seconds: i8, ) -> Result<Self, ComponentRange>
Create a UtcOffset
representing an offset by the number of hours, minutes, and seconds
provided.
The sign of all three components should match. If they do not, all smaller components will have their signs flipped.
Sourcepub(crate) const fn from_hms_ranged_unchecked(
hours: RangedI8<-25, 25>,
minutes: RangedI8<{ _ }, { _ }>,
seconds: RangedI8<{ _ }, { _ }>,
) -> Self
pub(crate) const fn from_hms_ranged_unchecked( hours: RangedI8<-25, 25>, minutes: RangedI8<{ _ }, { _ }>, seconds: RangedI8<{ _ }, { _ }>, ) -> Self
Create a UtcOffset
representing an offset of the hours, minutes, and seconds provided. All
three parameters must have the same sign.
While the signs of the parameters are required to match, this is not a safety invariant.
Sourcepub(crate) const fn from_hms_ranged(
hours: RangedI8<-25, 25>,
minutes: RangedI8<{ _ }, { _ }>,
seconds: RangedI8<{ _ }, { _ }>,
) -> Self
pub(crate) const fn from_hms_ranged( hours: RangedI8<-25, 25>, minutes: RangedI8<{ _ }, { _ }>, seconds: RangedI8<{ _ }, { _ }>, ) -> Self
Create a UtcOffset
representing an offset by the number of hours, minutes, and seconds
provided.
The sign of all three components should match. If they do not, all smaller components will have their signs flipped.
Sourcepub const fn from_whole_seconds(seconds: i32) -> Result<Self, ComponentRange>
pub const fn from_whole_seconds(seconds: i32) -> Result<Self, ComponentRange>
Sourcepub(crate) const fn from_whole_seconds_ranged(
seconds: RangedI32<{ _ }, { _ }>,
) -> Self
pub(crate) const fn from_whole_seconds_ranged( seconds: RangedI32<{ _ }, { _ }>, ) -> Self
Create a UtcOffset
representing an offset by the number of seconds provided.
assert_eq!(
UtcOffset::from_whole_seconds_ranged(RangedI32::new_static::<3_723>()).as_hms(),
(1, 2, 3)
);
Sourcepub(crate) const fn as_hms_ranged(
self,
) -> (RangedI8<-25, 25>, RangedI8<{ _ }, { _ }>, RangedI8<{ _ }, { _ }>)
Available on crate feature quickcheck
only.
pub(crate) const fn as_hms_ranged( self, ) -> (RangedI8<-25, 25>, RangedI8<{ _ }, { _ }>, RangedI8<{ _ }, { _ }>)
quickcheck
only.Obtain the UTC offset as its hours, minutes, and seconds. The sign of all three components will always match. A positive value indicates an offset to the east; a negative to the west.
Sourcepub const fn whole_hours(self) -> i8
pub const fn whole_hours(self) -> i8
Sourcepub const fn whole_minutes(self) -> i16
pub const fn whole_minutes(self) -> i16
Sourcepub const fn minutes_past_hour(self) -> i8
pub const fn minutes_past_hour(self) -> i8
Sourcepub const fn whole_seconds(self) -> i32
pub const fn whole_seconds(self) -> i32
Sourcepub const fn seconds_past_minute(self) -> i8
pub const fn seconds_past_minute(self) -> i8
Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Sourcepub fn local_offset_at(
datetime: OffsetDateTime,
) -> Result<Self, IndeterminateOffset>
Available on crate feature local-offset
only.
pub fn local_offset_at( datetime: OffsetDateTime, ) -> Result<Self, IndeterminateOffset>
local-offset
only.Sourcepub fn current_local_offset() -> Result<Self, IndeterminateOffset>
Available on crate feature local-offset
only.
pub fn current_local_offset() -> Result<Self, IndeterminateOffset>
local-offset
only.Source§impl UtcOffset
impl UtcOffset
Sourcepub fn format_into(
self,
output: &mut impl Write,
format: &(impl Formattable + ?Sized),
) -> Result<usize, Format>
Available on crate feature formatting
only.
pub fn format_into( self, output: &mut impl Write, format: &(impl Formattable + ?Sized), ) -> Result<usize, Format>
formatting
only.Format the UtcOffset
using the provided format description.
Sourcepub fn format(
self,
format: &(impl Formattable + ?Sized),
) -> Result<String, Format>
Available on crate feature formatting
only.
pub fn format( self, format: &(impl Formattable + ?Sized), ) -> Result<String, Format>
formatting
only.Format the UtcOffset
using the provided format description.
Trait Implementations§
Source§impl<'a> Deserialize<'a> for UtcOffset
Available on crate feature serde
only.
impl<'a> Deserialize<'a> for UtcOffset
serde
only.Source§fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>
Source§#[doc(hidden)] fn deserialize_in_place<D>(
deserializer: D,
place: &mut Self,
) -> Result<(), <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
#[doc(hidden)] fn deserialize_in_place<D>(
deserializer: D,
place: &mut Self,
) -> Result<(), <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
self
from the given Deserializer. Read moreSource§impl Distribution<UtcOffset> for Standard
Available on crate feature rand
only.
impl Distribution<UtcOffset> for Standard
rand
only.