[go: up one dir, main page]

Struct time::UtcOffset[][src]

pub struct UtcOffset { /* fields omitted */ }
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[src]

pub const UTC: Self[src]

A UtcOffset that is UTC.

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

pub const fn from_hms(
    hours: i8,
    minutes: i8,
    seconds: i8
) -> Result<Self, ComponentRange>
[src]

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

pub const fn as_hms(self) -> (i8, i8, i8)[src]

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

pub const fn whole_hours(self) -> i8[src]

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

pub const fn whole_minutes(self) -> i16[src]

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

pub const fn minutes_past_hour(self) -> i8[src]

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

pub const fn whole_seconds(self) -> i32[src]

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

pub const fn seconds_past_minute(self) -> i8[src]

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

pub const fn is_utc(self) -> bool[src]

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

pub const fn is_positive(self) -> bool[src]

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

pub const fn is_negative(self) -> bool[src]

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

pub fn local_offset_at(
    datetime: OffsetDateTime
) -> Result<Self, IndeterminateOffset>
[src]

This is supported on crate feature local-offset only.

Attempt to obtain the system’s UTC offset at a known moment in time. If the offset cannot be determined, an error is returned.

let local_offset = UtcOffset::local_offset_at(OffsetDateTime::UNIX_EPOCH);
assert!(local_offset.is_ok());
Run

Due to a soundness bug, the error value is currently always returned on Unix-like platforms.

pub fn current_local_offset() -> Result<Self, IndeterminateOffset>[src]

This is supported on crate feature local-offset only.

Attempt to obtain the system’s current UTC offset. If the offset cannot be determined, an error is returned.

let local_offset = UtcOffset::current_local_offset();
assert!(local_offset.is_ok());
Run

impl UtcOffset[src]

pub fn format_into(
    self,
    output: &mut impl Write,
    format: &impl Formattable
) -> Result<usize, Format>
[src]

This is supported on crate feature formatting only.

Format the UtcOffset using the provided format description. The formatted value will be output to the provided writer. The format description will typically be parsed by using format_description::parse.

pub fn format(self, format: &impl Formattable) -> Result<String, Format>[src]

This is supported on crate feature formatting only.

Format the UtcOffset using the provided format description. The format description will typically be parsed by using format_description::parse.

let format = format_description::parse("[offset_hour sign:mandatory]:[offset_minute]")?;
assert_eq!(offset!("+1").format(&format)?, "+01:00");
Run

impl UtcOffset[src]

pub fn parse(input: &str, description: &impl Parsable) -> Result<Self, Parse>[src]

This is supported on crate feature parsing only.

Parse a UtcOffset from the input using the provided format description. The format description will typically be parsed by using format_description::parse.

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

Trait Implementations

impl Arbitrary for UtcOffset[src]

This is supported on crate feature quickcheck only.

fn arbitrary(g: &mut Gen) -> Self[src]

Return an arbitrary value. Read more

fn shrink(&self) -> Box<dyn Iterator<Item = Self>>[src]

Return an iterator of values that are smaller than itself. Read more

impl Clone for UtcOffset[src]

fn clone(&self) -> UtcOffset[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for UtcOffset[src]

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

Formats the value using the given formatter. Read more

impl<'a> Deserialize<'a> for UtcOffset[src]

This is supported on crate feature serde only.

fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>[src]

Deserialize this value from the given Serde deserializer. Read more

impl Display for UtcOffset[src]

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

Formats the value using the given formatter. Read more

impl Hash for UtcOffset[src]

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

Feeds this value into the given Hasher. Read more

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

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

impl Neg for UtcOffset[src]

type Output = Self

The resulting type after applying the - operator.

fn neg(self) -> Self::Output[src]

Performs the unary - operation. Read more

impl Ord for UtcOffset[src]

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

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl PartialEq<UtcOffset> for UtcOffset[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &UtcOffset) -> bool[src]

This method tests for !=.

impl PartialOrd<UtcOffset> for UtcOffset[src]

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

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

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl Serialize for UtcOffset[src]

This is supported on crate feature serde only.

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>[src]

Serialize this value into the given Serde serializer. Read more

impl TryFrom<Parsed> for UtcOffset[src]

This is supported on crate feature parsing only.

type Error = TryFromParsed

The type returned in the event of a conversion error.

fn try_from(parsed: Parsed) -> Result<Self, Self::Error>[src]

Performs the conversion.

impl Copy for UtcOffset[src]

impl Eq for UtcOffset[src]

impl StructuralEq for UtcOffset[src]

impl StructuralPartialEq for UtcOffset[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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