Struct time::UtcOffset [−][src]
pub struct UtcOffset { /* fields omitted */ }
Expand description
An offset from UTC.
This struct can store values up to ±23:59:59. If you need support outside this range, please file an issue with your use case.
Implementations
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.
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));Run
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.
assert_eq!(offset!(+1:02:03).as_hms(), (1, 2, 3)); assert_eq!(offset!(-1:02:03).as_hms(), (-1, -2, -3));Run
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.
assert_eq!(offset!(+1:02:03).whole_hours(), 1); assert_eq!(offset!(-1:02:03).whole_hours(), -1);Run
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.
assert_eq!(offset!(+1:02:03).whole_minutes(), 62); assert_eq!(offset!(-1:02:03).whole_minutes(), -62);Run
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.
assert_eq!(offset!(+1:02:03).minutes_past_hour(), 2); assert_eq!(offset!(-1:02:03).minutes_past_hour(), -2);Run
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.
assert_eq!(offset!(+1:02:03).whole_seconds(), 3723); assert_eq!(offset!(-1:02:03).whole_seconds(), -3723);Run
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.
assert_eq!(offset!(+1:02:03).seconds_past_minute(), 3); assert_eq!(offset!(-1:02:03).seconds_past_minute(), -3);Run
Check if the offset is exactly UTC.
assert!(!offset!(+1:02:03).is_utc()); assert!(!offset!(-1:02:03).is_utc()); assert!(offset!(UTC).is_utc());Run
Check if the offset is positive, or east of UTC.
assert!(offset!(+1:02:03).is_positive()); assert!(!offset!(-1:02:03).is_positive()); assert!(!offset!(UTC).is_positive());Run
Check if the offset is negative, or west of UTC.
assert!(!offset!(+1:02:03).is_negative()); assert!(offset!(-1:02:03).is_negative()); assert!(!offset!(UTC).is_negative());Run
This is supported on crate feature local-offset
only.
local-offset
only.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 local_offset = UtcOffset::local_offset_at(OffsetDateTime::UNIX_EPOCH); assert!(local_offset.is_ok());Run
Due to a soundness bug, the error value is currently always returned on Unix-like platforms.
This is supported on crate feature local-offset
only.
local-offset
only.Attempt to obtain the system’s current UTC offset. If the offset cannot be determined, an error is returned.
let local_offset = UtcOffset::current_local_offset(); assert!(local_offset.is_ok());Run
pub fn format_into(
self,
output: &mut impl Write,
format: &impl Formattable
) -> Result<usize, Format>
[src]This is supported on crate feature formatting
only.
pub fn format_into(
self,
output: &mut impl Write,
format: &impl Formattable
) -> Result<usize, Format>
[src]formatting
only.Format the UtcOffset
using the provided format description. The formatted value will be
output to the provided writer. The format description will typically be parsed by using
format_description::parse
.
This is supported on crate feature formatting
only.
formatting
only.Format the UtcOffset
using the provided format description. The format description will
typically be parsed by using
format_description::parse
.
let format = format_description::parse("[offset_hour sign:mandatory]:[offset_minute]")?; assert_eq!(offset!(+1).format(&format)?, "+01:00");Run
This is supported on crate feature parsing
only.
parsing
only.Parse a UtcOffset
from the input using the provided format description. The format
description will typically be parsed by using
format_description::parse
.
let format = format_description::parse("[offset_hour]:[offset_minute]")?; assert_eq!(UtcOffset::parse("-03:42", &format)?, offset!(-3:42));Run
Trait Implementations
quickcheck
only.serde
only.Deserialize this value from the given Serde deserializer. Read more
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
serde
only.parsing
only.Auto Trait Implementations
impl RefUnwindSafe for UtcOffset
impl UnwindSafe for UtcOffset
Blanket Implementations
Mutably borrows from an owned value. Read more