Struct Offset

pub struct Offset { /* private fields */ }

A fixed offset, in seconds, from UTC.

Implementations

impl Offset

const MIN: Offset = _;

The minimum possible offset from UTC.

const MAX: Offset = _;

The maximum possible offset from UTC.

const UTC: Offset = _;

The UTC offset.

const ZERO: Offset = _;

The zero offset.

const fn constant(hours: i8) -> Offset

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

const fn constant_seconds(seconds: i32) -> Offset

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

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.

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.

const fn seconds(self) -> i32

Returns the seconds value corresponding to this time zone offset.

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.

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.

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.

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.

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.

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.

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.

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

Returns the number of seconds from this offset to other.

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

Returns the number of seconds since this offset from other.

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.

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

impl Add<i32> for Offset

type Output = Offset;
fn add(self, seconds: i32) -> Offset

impl AddAssign<i32> for Offset

fn add_assign(&mut self, rhs: i32)

impl Clone for Offset

fn clone(&self) -> Offset

impl Copy for Offset

impl Debug for Offset

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

impl Display for Offset

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

impl Eq for Offset

impl Hash for Offset

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

impl Neg for Offset

type Output = Offset;
fn neg(self) -> Offset

impl Ord for Offset

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

impl PartialEq for Offset

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

impl PartialOrd for Offset

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

impl StructuralPartialEq for Offset

impl Sub<i32> for Offset

type Output = Offset;
fn sub(self, seconds: i32) -> Offset

impl SubAssign<i32> for Offset

fn sub_assign(&mut self, rhs: i32)

Auto Trait Implementations

impl Freeze for Offset

impl RefUnwindSafe for Offset

impl Send for Offset

impl Sync for Offset

impl Unpin for Offset

impl UnsafeUnpin for Offset

impl UnwindSafe for Offset

Blanket Implementations

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

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

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Offset

fn from(t: T) -> T

Returns the argument unchanged.

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

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

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

fn to_string(&self) -> String

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

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, U> TryFrom<U> for Offset where U: Into<T>,

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

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

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