Struct time::UtcOffset[][src]

pub struct UtcOffset { /* fields omitted */ }
Expand description

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

A UtcOffset that is UTC.

assert_eq!(UtcOffset::UTC, offset!(UTC));

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

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

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

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

assert_eq!(UtcOffset::east_minutes(60).as_hours(), 1);

Create a UtcOffset representing a westerly offset by the number of minutes provided.

assert_eq!(UtcOffset::west_minutes(60).as_hours(), -1);

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

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

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

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

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

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

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);
👎 Deprecated since 0.2.23:

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"));

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());
👎 Deprecated since 0.2.23:

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"));

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

Methods that allow parsing and formatting the UtcOffset.

Format the UtcOffset using the provided string.

assert_eq!(UtcOffset::hours(2).format("%z"), "+0200");
assert_eq!(UtcOffset::hours(-2).format("%z"), "-0200");

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");

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.