Struct UtcOffset
#[repr(C)]
pub struct UtcOffset { /* private fields */ }
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
const UTC: Self = _;A
UtcOffsetthat is UTC.# use time::UtcOffset; # use time_macros::offset; assert_eq!(UtcOffset::UTC, offset!(UTC));const fn from_hms(hours: i8, minutes: i8, seconds: i8) -> Result<Self, ComponentRange>Create a
UtcOffsetrepresenting 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.
# use time::UtcOffset; 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)); # Ok::<_, time::Error>(())const fn from_whole_seconds(seconds: i32) -> Result<Self, ComponentRange>Create a
UtcOffsetrepresenting an offset by the number of seconds provided.# use time::UtcOffset; assert_eq!(UtcOffset::from_whole_seconds(3_723)?.as_hms(), (1, 2, 3)); # Ok::<_, time::Error>(())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.
# use time_macros::offset; assert_eq!(offset!(+1:02:03).as_hms(), (1, 2, 3)); assert_eq!(offset!(-1:02:03).as_hms(), (-1, -2, -3));const fn whole_hours(self) -> i8Obtain the number of whole hours the offset is from UTC. A positive value indicates an offset to the east; a negative to the west.
# use time_macros::offset; assert_eq!(offset!(+1:02:03).whole_hours(), 1); assert_eq!(offset!(-1:02:03).whole_hours(), -1);const fn whole_minutes(self) -> i16Obtain the number of whole minutes the offset is from UTC. A positive value indicates an offset to the east; a negative to the west.
# use time_macros::offset; assert_eq!(offset!(+1:02:03).whole_minutes(), 62); assert_eq!(offset!(-1:02:03).whole_minutes(), -62);const fn minutes_past_hour(self) -> i8Obtain 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.
# use time_macros::offset; assert_eq!(offset!(+1:02:03).minutes_past_hour(), 2); assert_eq!(offset!(-1:02:03).minutes_past_hour(), -2);const fn whole_seconds(self) -> i32Obtain the number of whole seconds the offset is from UTC. A positive value indicates an offset to the east; a negative to the west.
# use time_macros::offset; assert_eq!(offset!(+1:02:03).whole_seconds(), 3723); assert_eq!(offset!(-1:02:03).whole_seconds(), -3723);const fn seconds_past_minute(self) -> i8Obtain 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.
# use time_macros::offset; assert_eq!(offset!(+1:02:03).seconds_past_minute(), 3); assert_eq!(offset!(-1:02:03).seconds_past_minute(), -3);const fn is_utc(self) -> boolCheck if the offset is exactly UTC.
# use time_macros::offset; assert!(!offset!(+1:02:03).is_utc()); assert!(!offset!(-1:02:03).is_utc()); assert!(offset!(UTC).is_utc());const fn is_positive(self) -> boolCheck if the offset is positive, or east of UTC.
# use time_macros::offset; assert!(offset!(+1:02:03).is_positive()); assert!(!offset!(-1:02:03).is_positive()); assert!(!offset!(UTC).is_positive());const fn is_negative(self) -> boolCheck if the offset is negative, or west of UTC.
# use time_macros::offset; assert!(!offset!(+1:02:03).is_negative()); assert!(offset!(-1:02:03).is_negative()); assert!(!offset!(UTC).is_negative());
Trait Implementations
impl Clone for UtcOffset
fn clone(&self) -> Self
impl Copy for UtcOffset
impl Debug for UtcOffset
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Display for UtcOffset
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for UtcOffset
impl Hash for UtcOffset
fn hash<H>(&self, state: &mut H) where H: Hasher,
impl Neg for UtcOffset
type Output = UtcOffset;fn neg(self) -> Self::Output
impl Ord for UtcOffset
fn cmp(&self, other: &Self) -> Ordering
impl PartialEq for UtcOffset
fn eq(&self, other: &Self) -> bool
impl PartialOrd for UtcOffset
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
impl SmartDisplay for UtcOffset
type Metadata = ();fn metadata(&self, FormatterOptions) -> Metadata<'_, Self>fn fmt(&self, f: &mut Formatter<'_>) -> Result