pub struct UtcOffset { /* private fields */ }
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.
Implementations§
§impl UtcOffset
impl UtcOffset
pub const fn from_hms(
hours: i8,
minutes: i8,
seconds: i8,
) -> Result<UtcOffset, ComponentRange>
pub const fn from_hms( hours: i8, minutes: i8, seconds: i8, ) -> Result<UtcOffset, 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.
assert_eq!(UtcOffset::from_hms(1, 2, 3)?.as_hms(), (1, 2, 3));
assert_eq!(UtcOffset::from_hms(1, -2, -3)?.as_hms(), (1, 2, 3));
pub const fn from_whole_seconds(
seconds: i32,
) -> Result<UtcOffset, ComponentRange>
pub const fn from_whole_seconds( seconds: i32, ) -> Result<UtcOffset, ComponentRange>
Create a UtcOffset
representing an offset by the number of seconds provided.
assert_eq!(UtcOffset::from_whole_seconds(3_723)?.as_hms(), (1, 2, 3));
pub const fn as_hms(self) -> (i8, i8, i8)
pub const fn as_hms(self) -> (i8, i8, i8)
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.
assert_eq!(offset!(+1:02:03).as_hms(), (1, 2, 3));
assert_eq!(offset!(-1:02:03).as_hms(), (-1, -2, -3));
pub const fn whole_hours(self) -> i8
pub const fn whole_hours(self) -> i8
Obtain the number of whole hours the offset is from UTC. A positive value indicates an offset to the east; a negative to the west.
assert_eq!(offset!(+1:02:03).whole_hours(), 1);
assert_eq!(offset!(-1:02:03).whole_hours(), -1);
pub const fn whole_minutes(self) -> i16
pub const fn whole_minutes(self) -> i16
Obtain the number of whole minutes the offset is from UTC. A positive value indicates an offset to the east; a negative to the west.
assert_eq!(offset!(+1:02:03).whole_minutes(), 62);
assert_eq!(offset!(-1:02:03).whole_minutes(), -62);
pub const fn minutes_past_hour(self) -> i8
pub const fn minutes_past_hour(self) -> i8
Obtain the number of minutes past the hour the offset is from UTC. A positive value indicates an offset to the east; a negative to the west.
assert_eq!(offset!(+1:02:03).minutes_past_hour(), 2);
assert_eq!(offset!(-1:02:03).minutes_past_hour(), -2);
pub const fn whole_seconds(self) -> i32
pub const fn whole_seconds(self) -> i32
Obtain the number of whole seconds the offset is from UTC. A positive value indicates an offset to the east; a negative to the west.
assert_eq!(offset!(+1:02:03).whole_seconds(), 3723);
assert_eq!(offset!(-1:02:03).whole_seconds(), -3723);
pub const fn seconds_past_minute(self) -> i8
pub const fn seconds_past_minute(self) -> i8
Obtain the number of seconds past the minute the offset is from UTC. A positive value indicates an offset to the east; a negative to the west.
assert_eq!(offset!(+1:02:03).seconds_past_minute(), 3);
assert_eq!(offset!(-1:02:03).seconds_past_minute(), -3);
pub const fn is_utc(self) -> bool
pub const fn is_utc(self) -> bool
Check if the offset is exactly UTC.
assert!(!offset!(+1:02:03).is_utc());
assert!(!offset!(-1:02:03).is_utc());
assert!(offset!(UTC).is_utc());
pub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Check if the offset is positive, or east of UTC.
assert!(offset!(+1:02:03).is_positive());
assert!(!offset!(-1:02:03).is_positive());
assert!(!offset!(UTC).is_positive());
pub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Check if the offset is negative, or west of UTC.
assert!(!offset!(+1:02:03).is_negative());
assert!(offset!(-1:02:03).is_negative());
assert!(!offset!(UTC).is_negative());
§impl UtcOffset
impl UtcOffset
pub fn format_into(
self,
output: &mut impl Write,
format: &(impl Formattable + ?Sized),
) -> Result<usize, Format>
pub fn format_into( self, output: &mut impl Write, format: &(impl Formattable + ?Sized), ) -> Result<usize, Format>
Format the UtcOffset
using the provided format description.
pub fn format(
self,
format: &(impl Formattable + ?Sized),
) -> Result<String, Format>
pub fn format( self, format: &(impl Formattable + ?Sized), ) -> Result<String, Format>
Format the UtcOffset
using the provided format description.
let format = format_description::parse("[offset_hour sign:mandatory]:[offset_minute]")?;
assert_eq!(offset!(+1).format(&format)?, "+01:00");
Trait Implementations§
§impl<'a> Deserialize<'a> for UtcOffset
impl<'a> Deserialize<'a> for UtcOffset
§fn deserialize<D>(
deserializer: D,
) -> Result<UtcOffset, <D as Deserializer<'a>>::Error>where
D: Deserializer<'a>,
fn deserialize<D>(
deserializer: D,
) -> Result<UtcOffset, <D as Deserializer<'a>>::Error>where
D: Deserializer<'a>,
§impl Ord for UtcOffset
impl Ord for UtcOffset
§impl PartialOrd for UtcOffset
impl PartialOrd for UtcOffset
§impl Serialize for UtcOffset
impl Serialize for UtcOffset
§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
§impl SmartDisplay for UtcOffset
impl SmartDisplay for UtcOffset
§fn metadata(&self, _: FormatterOptions) -> Metadata<'_, UtcOffset>
fn metadata(&self, _: FormatterOptions) -> Metadata<'_, UtcOffset>
§fn fmt_with_metadata(
&self,
f: &mut Formatter<'_>,
metadata: Metadata<'_, UtcOffset>,
) -> Result<(), Error>
fn fmt_with_metadata( &self, f: &mut Formatter<'_>, metadata: Metadata<'_, UtcOffset>, ) -> Result<(), Error>
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
)§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.