Struct UtcOffset

#[repr(C)]
pub struct UtcOffset { /* private fields */ }

An offset from UTC.

This struct can store values up to ±25:59:59. If you need support outside this range, please file an issue with your use case.

Implementations

impl UtcOffset

const UTC: Self = _;

A UtcOffset that is UTC.

# use time::UtcOffset;
# use time_macros::offset;
assert_eq!(UtcOffset::UTC, offset!(UTC));
const fn from_hms(hours: i8, minutes: i8, seconds: i8) -> Result<Self, ComponentRange>

Create a UtcOffset representing an offset by the number of hours, minutes, and seconds provided.

The sign of all three components should match. If they do not, all smaller components will have their signs flipped.

# use time::UtcOffset;
assert_eq!(UtcOffset::from_hms(1, 2, 3)?.as_hms(), (1, 2, 3));
assert_eq!(UtcOffset::from_hms(1, -2, -3)?.as_hms(), (1, 2, 3));
# Ok::<_, time::Error>(())
const fn from_whole_seconds(seconds: i32) -> Result<Self, ComponentRange>

Create a UtcOffset representing an offset by the number of seconds provided.

# use time::UtcOffset;
assert_eq!(UtcOffset::from_whole_seconds(3_723)?.as_hms(), (1, 2, 3));
# Ok::<_, time::Error>(())
const fn as_hms(self) -> (i8, i8, i8)

Obtain the UTC offset as its hours, minutes, and seconds. The sign of all three components will always match. A positive value indicates an offset to the east; a negative to the west.

# use time_macros::offset;
assert_eq!(offset!(+1:02:03).as_hms(), (1, 2, 3));
assert_eq!(offset!(-1:02:03).as_hms(), (-1, -2, -3));
const fn whole_hours(self) -> i8

Obtain the number of whole hours the offset is from UTC. A positive value indicates an offset to the east; a negative to the west.

# use time_macros::offset;
assert_eq!(offset!(+1:02:03).whole_hours(), 1);
assert_eq!(offset!(-1:02:03).whole_hours(), -1);
const fn whole_minutes(self) -> i16

Obtain the number of whole minutes the offset is from UTC. A positive value indicates an offset to the east; a negative to the west.

# use time_macros::offset;
assert_eq!(offset!(+1:02:03).whole_minutes(), 62);
assert_eq!(offset!(-1:02:03).whole_minutes(), -62);
const fn minutes_past_hour(self) -> i8

Obtain the number of minutes past the hour the offset is from UTC. A positive value indicates an offset to the east; a negative to the west.

# use time_macros::offset;
assert_eq!(offset!(+1:02:03).minutes_past_hour(), 2);
assert_eq!(offset!(-1:02:03).minutes_past_hour(), -2);
const fn whole_seconds(self) -> i32

Obtain the number of whole seconds the offset is from UTC. A positive value indicates an offset to the east; a negative to the west.

# use time_macros::offset;
assert_eq!(offset!(+1:02:03).whole_seconds(), 3723);
assert_eq!(offset!(-1:02:03).whole_seconds(), -3723);
const fn seconds_past_minute(self) -> i8

Obtain the number of seconds past the minute the offset is from UTC. A positive value indicates an offset to the east; a negative to the west.

# use time_macros::offset;
assert_eq!(offset!(+1:02:03).seconds_past_minute(), 3);
assert_eq!(offset!(-1:02:03).seconds_past_minute(), -3);
const fn is_utc(self) -> bool

Check if the offset is exactly UTC.

# use time_macros::offset;
assert!(!offset!(+1:02:03).is_utc());
assert!(!offset!(-1:02:03).is_utc());
assert!(offset!(UTC).is_utc());
const fn is_positive(self) -> bool

Check if the offset is positive, or east of UTC.

# use time_macros::offset;
assert!(offset!(+1:02:03).is_positive());
assert!(!offset!(-1:02:03).is_positive());
assert!(!offset!(UTC).is_positive());
const fn is_negative(self) -> bool

Check if the offset is negative, or west of UTC.

# use time_macros::offset;
assert!(!offset!(+1:02:03).is_negative());
assert!(offset!(-1:02:03).is_negative());
assert!(!offset!(UTC).is_negative());

Trait Implementations

impl Clone for UtcOffset

fn clone(&self) -> UtcOffset

impl Copy for UtcOffset

impl Debug for UtcOffset

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

impl Display for UtcOffset

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

impl Eq for UtcOffset

impl Hash for UtcOffset

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

impl Neg for UtcOffset

type Output = UtcOffset;
fn neg(self) -> Self::Output

impl Ord for UtcOffset

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

impl PartialEq for UtcOffset

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

impl PartialOrd for UtcOffset

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

impl SmartDisplay for UtcOffset

type Metadata = ();
fn metadata(&self, FormatterOptions) -> Metadata<'_, Self>
fn fmt(&self, f: &mut Formatter<'_>) -> Result

Auto Trait Implementations

impl Freeze for UtcOffset

impl RefUnwindSafe for UtcOffset

impl Send for UtcOffset

impl Sync for UtcOffset

impl Unpin for UtcOffset

impl UnsafeUnpin for UtcOffset

impl UnwindSafe for UtcOffset

Blanket Implementations

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

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

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

impl<T> From<T> for UtcOffset

fn from(t: T) -> T

Returns the argument unchanged.

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

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

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

fn to_string(&self) -> String

impl<T, U> Into<U> for UtcOffset 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 UtcOffset where U: Into<T>,

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

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

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