Struct pavex::time::UtcOffset

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

pub const UTC: UtcOffset = _

A UtcOffset that is UTC.

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

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>

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)

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

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

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

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

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

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

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

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

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

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>

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 Clone for UtcOffset

§

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
§

impl Debug for UtcOffset

§

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

Formats the value using the given formatter. Read more
§

impl<'a> Deserialize<'a> for UtcOffset

§

fn deserialize<D>( deserializer: D, ) -> Result<UtcOffset, <D as Deserializer<'a>>::Error>
where D: Deserializer<'a>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Display for UtcOffset

§

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

Formats the value using the given formatter. Read more
§

impl Hash for UtcOffset

§

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

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
§

impl Neg for UtcOffset

§

type Output = UtcOffset

The resulting type after applying the - operator.
§

fn neg(self) -> <UtcOffset as Neg>::Output

Performs the unary - operation. Read more
§

impl Ord for UtcOffset

§

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
§

impl PartialEq for UtcOffset

§

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

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

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

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

impl PartialOrd for UtcOffset

§

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

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

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

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

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

impl Serialize for UtcOffset

§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl SmartDisplay for UtcOffset

§

type Metadata = UtcOffsetMetadata

User-provided metadata type.
§

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

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
§

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

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
§

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

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

impl Copy for UtcOffset

§

impl Eq for UtcOffset

§

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§

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

source§

type Output = T

Should always be Self
source§

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

source§

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>,

source§

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>,

source§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,