Struct time::UtcOffset [−][src]
An offset from UTC.
Guaranteed to store values up to ±23:59:59. Any values outside this range may have incidental support that can change at any time without notice. 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));
pub const fn east_hours(hours: u8) -> Self
[src]
Create a UtcOffset
representing an easterly offset by the number of
hours provided.
assert_eq!(UtcOffset::east_hours(1).as_hours(), 1); assert_eq!(UtcOffset::east_hours(2).as_minutes(), 120);
pub const fn west_hours(hours: u8) -> Self
[src]
Create a UtcOffset
representing a westerly offset by the number of
hours provided.
assert_eq!(UtcOffset::west_hours(1).as_hours(), -1); assert_eq!(UtcOffset::west_hours(2).as_minutes(), -120);
pub const fn hours(hours: i8) -> Self
[src]
Create a UtcOffset
representing an offset by the number of hours
provided.
assert_eq!(UtcOffset::hours(2).as_minutes(), 120); assert_eq!(UtcOffset::hours(-2).as_minutes(), -120);
pub const fn east_minutes(minutes: u16) -> Self
[src]
Create a UtcOffset
representing an easterly offset by the number of
minutes provided.
assert_eq!(UtcOffset::east_minutes(60).as_hours(), 1);
pub const fn west_minutes(minutes: u16) -> Self
[src]
Create a UtcOffset
representing a westerly offset by the number of
minutes provided.
assert_eq!(UtcOffset::west_minutes(60).as_hours(), -1);
pub const fn minutes(minutes: i16) -> Self
[src]
Create a UtcOffset
representing a offset by the number of minutes
provided.
assert_eq!(UtcOffset::minutes(60).as_hours(), 1); assert_eq!(UtcOffset::minutes(-60).as_hours(), -1);
pub const fn east_seconds(seconds: u32) -> Self
[src]
Create a UtcOffset
representing an easterly offset by the number of
seconds provided.
assert_eq!(UtcOffset::east_seconds(3_600).as_hours(), 1); assert_eq!(UtcOffset::east_seconds(1_800).as_minutes(), 30);
pub const fn west_seconds(seconds: u32) -> Self
[src]
Create a UtcOffset
representing a westerly offset by the number of
seconds provided.
assert_eq!(UtcOffset::west_seconds(3_600).as_hours(), -1); assert_eq!(UtcOffset::west_seconds(1_800).as_minutes(), -30);
pub const fn seconds(seconds: i32) -> Self
[src]
Create a UtcOffset
representing an offset by the number of seconds
provided.
assert_eq!(UtcOffset::seconds(3_600).as_hours(), 1); assert_eq!(UtcOffset::seconds(-3_600).as_hours(), -1);
pub const fn as_seconds(self) -> i32
[src]
Get the number of seconds from UTC the value is. Positive is east, negative is west.
assert_eq!(UtcOffset::UTC.as_seconds(), 0); assert_eq!(UtcOffset::hours(12).as_seconds(), 43_200); assert_eq!(UtcOffset::hours(-12).as_seconds(), -43_200);
pub const fn as_minutes(self) -> i16
[src]
Get the number of minutes from UTC the value is. Positive is east, negative is west.
assert_eq!(UtcOffset::UTC.as_minutes(), 0); assert_eq!(UtcOffset::hours(12).as_minutes(), 720); assert_eq!(UtcOffset::hours(-12).as_minutes(), -720);
pub const fn as_hours(self) -> i8
[src]
Get the number of hours from UTC the value is. Positive is east, negative is west.
assert_eq!(UtcOffset::UTC.as_hours(), 0); assert_eq!(UtcOffset::hours(12).as_hours(), 12); assert_eq!(UtcOffset::hours(-12).as_hours(), -12);
pub fn local_offset_at(datetime: OffsetDateTime) -> Self
[src]
UTC is returned if the local offset cannot be determined
Obtain the system’s UTC offset at a known moment in time. If the offset cannot be determined, UTC is returned.
let unix_epoch = OffsetDateTime::unix_epoch(); let local_offset = UtcOffset::local_offset_at(unix_epoch); println!("{}", local_offset.format("%z"));
pub fn try_local_offset_at(
datetime: OffsetDateTime
) -> Result<Self, IndeterminateOffset>
[src]
datetime: OffsetDateTime
) -> Result<Self, IndeterminateOffset>
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 unix_epoch = OffsetDateTime::unix_epoch(); let local_offset = UtcOffset::try_local_offset_at(unix_epoch); assert!(local_offset.is_ok());
pub fn current_local_offset() -> Self
[src]
UTC is returned if the local offset cannot be determined
Obtain the system’s current UTC offset. If the offset cannot be determined, UTC is returned.
let local_offset = UtcOffset::current_local_offset(); println!("{}", local_offset.format("%z"));
pub fn try_current_local_offset() -> Result<Self, IndeterminateOffset>
[src]
Attempt to obtain the system’s current UTC offset. If the offset cannot be determined, an error is returned.
let local_offset = UtcOffset::try_current_local_offset(); assert!(local_offset.is_ok());
impl UtcOffset
[src]
Methods that allow parsing and formatting the UtcOffset
.
pub fn format(self, format: impl AsRef<str>) -> String
[src]
Format the UtcOffset
using the provided string.
assert_eq!(UtcOffset::hours(2).format("%z"), "+0200"); assert_eq!(UtcOffset::hours(-2).format("%z"), "-0200");
pub fn lazy_format(self, format: impl AsRef<str>) -> impl Display
[src]
Format the UtcOffset
using the provided string.
assert_eq!(UtcOffset::hours(2).lazy_format("%z").to_string(), "+0200"); assert_eq!(UtcOffset::hours(-2).lazy_format("%z").to_string(), "-0200");
pub fn parse(s: impl AsRef<str>, format: impl AsRef<str>) -> Result<Self, Error>
[src]
Attempt to parse the UtcOffset
using the provided string.
assert_eq!(UtcOffset::parse("+0200", "%z"), Ok(UtcOffset::hours(2))); assert_eq!(UtcOffset::parse("-0200", "%z"), Ok(UtcOffset::hours(-2)));
Trait Implementations
impl Clone for UtcOffset
[src]
impl Copy for UtcOffset
[src]
impl Debug for UtcOffset
[src]
impl Display for UtcOffset
[src]
impl Eq for UtcOffset
[src]
impl Hash for UtcOffset
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for UtcOffset
[src]
fn cmp(&self, other: &UtcOffset) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<UtcOffset> for UtcOffset
[src]
impl PartialOrd<UtcOffset> for UtcOffset
[src]
fn partial_cmp(&self, other: &UtcOffset) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq for UtcOffset
[src]
impl StructuralPartialEq for UtcOffset
[src]
Auto Trait Implementations
impl RefUnwindSafe for UtcOffset
impl Send for UtcOffset
impl Sync for UtcOffset
impl Unpin for UtcOffset
impl UnwindSafe for UtcOffset
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Sealed<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,