pub struct Offset { /* private fields */ }Expand description
A fixed offset, in seconds, from UTC.
Implementations§
Source§impl Offset
impl Offset
Sourcepub const fn constant(hours: i8) -> Offset
pub const fn constant(hours: i8) -> Offset
Creates a new time zone offset in a const context from a given number
of hours.
Sourcepub const fn constant_seconds(seconds: i32) -> Offset
pub const fn constant_seconds(seconds: i32) -> Offset
Creates a new time zone offset in a const context from a given number
of seconds.
Sourcepub const fn from_hours(hours: i8) -> Result<Offset, RangeError>
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.
Sourcepub const fn from_seconds(seconds: i32) -> Result<Offset, RangeError>
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.
Sourcepub const fn seconds(self) -> i32
pub const fn seconds(self) -> i32
Returns the seconds value corresponding to this time zone offset.
Sourcepub const fn negate(self) -> Offset
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.
Sourcepub const fn signum(self) -> i8
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.
Sourcepub const fn is_positive(self) -> bool
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.
Sourcepub const fn is_negative(self) -> bool
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.
Sourcepub const fn is_zero(self) -> bool
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.
Sourcepub const fn checked_add(self, seconds: i32) -> Result<Offset, RangeError>
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.
Sourcepub const fn checked_sub(self, seconds: i32) -> Result<Offset, RangeError>
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.
Sourcepub const fn until(self, other: Offset) -> i32
pub const fn until(self, other: Offset) -> i32
Returns the number of seconds from this offset to other.
Sourcepub const fn since(self, other: Offset) -> i32
pub const fn since(self, other: Offset) -> i32
Returns the number of seconds since this offset from other.
Sourcepub const fn to_datetime(self, timestamp: Timestamp) -> DateTime
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.
Sourcepub const fn to_timestamp(self, dt: DateTime) -> Result<Timestamp, RangeError>
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.
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§impl AddAssign<i32> for Offset
Adds a number of seconds into an Offset.
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)
fn add_assign(&mut self, rhs: i32)
+= operation. Read moreimpl Copy for Offset
impl Eq for Offset
Source§impl Neg for Offset
Negate this offset.
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.