Skip to main content

Offset

Struct Offset 

Source
pub struct Offset { /* private fields */ }
Expand description

A fixed offset, in seconds, from UTC.

Implementations§

Source§

impl Offset

Source

pub const MIN: Offset

The minimum possible offset from UTC.

Source

pub const MAX: Offset

The maximum possible offset from UTC.

Source

pub const UTC: Offset

The UTC offset.

Source

pub const ZERO: Offset

The zero offset.

Source

pub const fn constant(hours: i8) -> Offset

Creates a new time zone offset in a const context from a given number of hours.

Source

pub const fn constant_seconds(seconds: i32) -> Offset

Creates a new time zone offset in a const context from a given number of seconds.

Source

pub const fn from_hours(hours: i8) -> Result<Offset, RangeError>

Creates a new time zone offset from a given number of hours.

Negative offsets correspond to time zones west of the prime meridian, while positive offsets correspond to time zones east of the prime meridian. Equivalently, in all cases, civil-time - offset = UTC.

Source

pub const fn from_seconds(seconds: i32) -> Result<Offset, RangeError>

Returns a new time zone offset from UTC given its representation in seconds.

An error is also returned when seconds is not in the range specified by OffsetTotalSeconds.

Source

pub const fn seconds(self) -> i32

Returns the seconds value corresponding to this time zone offset.

Source

pub const fn negate(self) -> Offset

Returns the negation of this offset.

A negative offset will become positive and vice versa. This is a no-op if the offset is zero.

This never panics.

Source

pub const fn signum(self) -> i8

Returns the “sign number” or “signum” of this offset.

The number returned is -1 when this offset is negative, 0 when this offset is zero and 1 when this span is positive.

Source

pub const fn is_positive(self) -> bool

Returns true if and only if this offset is positive.

This returns false when the offset is zero or negative.

Source

pub const fn is_negative(self) -> bool

Returns true if and only if this offset is less than zero.

This returns false when the offset is zero or positive.

Source

pub const fn is_zero(self) -> bool

Returns true if and only if this offset is zero.

Or equivalently, when this offset corresponds to Offset::UTC.

Source

pub const fn checked_add(self, seconds: i32) -> Result<Offset, RangeError>

Adds the given number of seconds to this offset.

If the resulting offset would be outside the an offset’s boundaries, an error is returned.

Source

pub const fn checked_sub(self, seconds: i32) -> Result<Offset, RangeError>

Subtracts the given number of seconds from this offset.

If the resulting offset would be outside the an offset’s boundaries, an error is returned.

Source

pub const fn until(self, other: Offset) -> i32

Returns the number of seconds from this offset to other.

Source

pub const fn since(self, other: Offset) -> i32

Returns the number of seconds since this offset from other.

Source

pub const fn to_datetime(self, timestamp: Timestamp) -> DateTime

Converts a Unix timestamp with an offset to a Gregorian datetime.

The offset should correspond to the number of seconds required to add to this timestamp to get the local time.

Source

pub const fn to_timestamp(self, dt: DateTime) -> Result<Timestamp, RangeError>

Converts the given civil datetime to a timestamp using this offset.

§Errors

This returns an error if this would have returned a timestamp outside of its minimum and maximum values.

Trait Implementations§

Source§

impl Add<i32> for Offset

Adds a number of seconds to an Offset.

§Panics

When adding would result in a value outside the boundaries of a Offset.

Source§

type Output = Offset

The resulting type after applying the + operator.
Source§

fn add(self, seconds: i32) -> Offset

Performs the + operation. Read more
Source§

impl AddAssign<i32> for Offset

Adds a number of seconds into an Offset.

§Panics

When adding would result in a value outside the boundaries of a Offset.

Source§

fn add_assign(&mut self, rhs: i32)

Performs the += operation. Read more
Source§

impl Clone for Offset

Source§

fn clone(&self) -> Offset

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Offset

Source§

impl Debug for Offset

Source§

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

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

impl Display for Offset

Source§

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

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

impl Eq for Offset

Source§

impl Format for Offset

Available on crate feature defmt only.
Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
Source§

impl Hash for Offset

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 Offset

Negate this offset.

A positive offset becomes negative and vice versa. This is a no-op for the zero offset.

This never panics.

Source§

type Output = Offset

The resulting type after applying the - operator.
Source§

fn neg(self) -> Offset

Performs the unary - operation. Read more
Source§

impl Ord for Offset

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

impl PartialEq for Offset

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Offset

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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
Source§

impl StructuralPartialEq for Offset

Source§

impl Sub<i32> for Offset

Subtracts a number of seconds from an Offset.

§Panics

When adding would result in a value outside the boundaries of a Offset.

Source§

type Output = Offset

The resulting type after applying the - operator.
Source§

fn sub(self, seconds: i32) -> Offset

Performs the - operation. Read more
Source§

impl SubAssign<i32> for Offset

Subtracts a number of seconds from an Offset in place.

§Panics

When adding would result in a value outside the boundaries of a Offset.

Source§

fn sub_assign(&mut self, rhs: i32)

Performs the -= operation. Read more

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

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§

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.