Struct UtcOffset

struct UtcOffset { ... }

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 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: 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: 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: 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: 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: 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: 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: 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: 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: 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());

impl Clone for UtcOffset

fn clone(self: &Self) -> UtcOffset

impl Copy for UtcOffset

impl Debug for UtcOffset

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

impl Display for UtcOffset

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

impl Eq for UtcOffset

impl Freeze for UtcOffset

impl Hash for UtcOffset

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

impl Neg for UtcOffset

fn neg(self: Self) -> <Self as >::Output

impl Ord for UtcOffset

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

impl PartialEq for UtcOffset

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

impl PartialOrd for UtcOffset

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

impl RefUnwindSafe for UtcOffset

impl Send for UtcOffset

impl SmartDisplay for UtcOffset

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

impl Sync for UtcOffset

impl Unpin for UtcOffset

impl UnsafeUnpin for UtcOffset

impl UnwindSafe for UtcOffset

impl<T> Any for UtcOffset

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for UtcOffset

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for UtcOffset

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

impl<T> CloneToUninit for UtcOffset

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

impl<T> From for UtcOffset

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for UtcOffset

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> ToString for UtcOffset

fn to_string(self: &Self) -> String

impl<T, U> Into for UtcOffset

fn into(self: 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 for UtcOffset

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

impl<T, U> TryInto for UtcOffset

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