pub struct Offset { /* private fields */ }
Expand description
Represents the number of seconds offset from UTC.
Implementations§
Source§impl Offset
impl Offset
Sourcepub fn utc() -> Self
pub fn utc() -> Self
Generate a UTC based offset.
§Examples
let offset = Offset::utc();
assert!(offset.is_utc());
let time = Time::new(2022, 7, 29, 12, 36, 0, 0, offset)?;
assert!(time.is_utc());
Sourcepub fn local() -> Self
pub fn local() -> Self
Generate an offset based on the detected local time zone of the system.
Detection is done by tzdb::local_tz
, and if it fails will return a
GMT timezone.
The system timezone is detected on the first call to this function and will be constant for the life of the program.
§Examples
let offset = Offset::local();
assert!(!offset.is_utc());
let time = Time::new(2022, 7, 29, 12, 36, 0, 0, offset)?;
assert!(!time.is_utc());
Sourcepub fn fixed(offset: i32) -> Result<Self, TimeError>
pub fn fixed(offset: i32) -> Result<Self, TimeError>
Generate an offset with a number of seconds from UTC.
§Examples
let offset = Offset::fixed(6600)?; // +0150
assert!(!offset.is_utc());
let time = Time::new(2022, 7, 29, 12, 36, 0, 0, offset)?;
assert!(!time.is_utc());
The offset must be in range:
let offset = Offset::fixed(500_000); // +0150
assert!(offset.is_err());
§Errors
Return a TimeError::TzOutOfRangeError
when outside of range of
acceptable offset of MIN_OFFSET_SECONDS
to MAX_OFFSET_SECONDS
.
Trait Implementations§
Source§impl From<TimeZoneRef<'static>> for Offset
impl From<TimeZoneRef<'static>> for Offset
Source§fn from(tz: TimeZoneRef<'static>) -> Self
fn from(tz: TimeZoneRef<'static>) -> Self
Converts to this type from the input type.
Source§impl TryFrom<&str> for Offset
impl TryFrom<&str> for Offset
impl Copy for Offset
impl Eq for Offset
impl StructuralPartialEq for Offset
Auto Trait Implementations§
impl Freeze for Offset
impl RefUnwindSafe for Offset
impl Send for Offset
impl Sync for Offset
impl Unpin for Offset
impl UnwindSafe for Offset
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more