Struct time::UtcOffset

source ·
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§

source§

impl UtcOffset

source

pub const UTC: Self = _

A UtcOffset that is UTC.

assert_eq!(UtcOffset::UTC, offset!(UTC));
Run
source

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.

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));
Run
source

pub const fn from_whole_seconds(seconds: i32) -> Result<Self, 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));
Run
source

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));
Run
source

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);
Run
source

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);
Run
source

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);
Run
source

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);
Run
source

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);
Run
source

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());
Run
source

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());
Run
source

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());
Run
source§

impl UtcOffset

source

pub fn format_into( self, output: &mut impl Write, format: &(impl Formattable + ?Sized), ) -> Result<usize, Format>

Format the UtcOffset using the provided format description.

source

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");
Run

Trait Implementations§

source§

impl Clone for UtcOffset

source§

fn clone(&self) -> UtcOffset

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for UtcOffset

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for UtcOffset

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for UtcOffset

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Neg for UtcOffset

§

type Output = UtcOffset

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl Ord for UtcOffset

source§

fn cmp(&self, other: &UtcOffset) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for UtcOffset

source§

fn eq(&self, other: &UtcOffset) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for UtcOffset

source§

fn partial_cmp(&self, other: &UtcOffset) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl SmartDisplay for UtcOffset

§

type Metadata = UtcOffsetMetadata

User-provided metadata type.
source§

fn metadata(&self, _: FormatterOptions) -> Metadata<'_, Self>

Compute any information needed to format the value. This must, at a minimum, determine the width of the value before any padding is added by the formatter. Read more
source§

fn fmt_with_metadata( &self, f: &mut Formatter<'_>, metadata: Metadata<'_, Self>, ) -> Result

Format the value using the given formatter and metadata. The formatted output should have the width indicated by the metadata. This is before any padding is added by the formatter. Read more
source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Format the value using the given formatter. This is the same as Display::fmt. Read more
source§

impl Copy for UtcOffset

source§

impl Eq for UtcOffset

source§

impl StructuralPartialEq for UtcOffset

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.