Struct gpui2::UtcOffset

pub struct UtcOffset { /* private fields */ }
Expand description

An offset from UTC.

This struct can store values up to ±23:59:59. If you need support outside this range, please file an issue with your use case.

Implementations§

§

impl UtcOffset

pub const UTC: UtcOffset = unsafe { Self::__from_hms_unchecked(0, 0, 0) }

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

impl UtcOffset

pub fn parse( input: &str, description: &(impl Parsable + ?Sized) ) -> Result<UtcOffset, Parse>

Parse a UtcOffset from the input using the provided format description.

let format = format_description!("[offset_hour]:[offset_minute]");
assert_eq!(UtcOffset::parse("-03:42", &format)?, offset!(-3:42));

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) -> Selfwhere Self: Sized,

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

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

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

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

Restrict a value to a certain interval. Read more
§

impl PartialEq<UtcOffset> for UtcOffset

§

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

impl PartialOrd<UtcOffset> 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

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
§

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 TryFrom<Parsed> for UtcOffset

§

type Error = TryFromParsed

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

fn try_from( parsed: Parsed ) -> Result<UtcOffset, <UtcOffset as TryFrom<Parsed>>::Error>

Performs the conversion.
§

impl Copy for UtcOffset

§

impl Eq for UtcOffset

§

impl StructuralEq for UtcOffset

§

impl StructuralPartialEq for UtcOffset

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

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

§

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

Compare self to key and return their ordering.
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Qwhere 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 Qwhere 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.

source§

impl<T> Instrument for T

source§

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

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

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

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

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

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> Serialize for Twhere T: Serialize + ?Sized,

source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>

source§

impl<T> ToOwned for Twhere 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 Twhere 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 Twhere 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 Twhere 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.
§

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

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> WithSubscriber for T

source§

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

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 Twhere T: for<'de> Deserialize<'de>,