pub trait OffsetComponents {
    // Required methods
    fn base_utc_offset(&self) -> Duration;
    fn dst_offset(&self) -> Duration;
}
Expand description

Detailed timezone offset components that expose any special conditions currently in effect.

This trait breaks down an offset into the standard UTC offset and any special offset in effect (such as DST) at a given time.

use chrono::{Duration, Offset, TimeZone};
use chrono_tz::Europe::London;
use chrono_tz::OffsetComponents;

let london_time = London.ymd(2016, 5, 10).and_hms(12, 0, 0);

// London typically has zero offset from UTC, but has a 1h adjustment forward
// when summer time is in effect.
let lon_utc_offset = london_time.offset().base_utc_offset();
let lon_dst_offset = london_time.offset().dst_offset();
let total_offset = lon_utc_offset + lon_dst_offset;
assert_eq!(lon_utc_offset, Duration::hours(0));
assert_eq!(lon_dst_offset, Duration::hours(1));

// As a sanity check, make sure that the total offsets added together are equivalent to the
// total fixed offset.
assert_eq!(total_offset.num_seconds(), london_time.offset().fix().local_minus_utc() as i64);

Required Methods§

source

fn base_utc_offset(&self) -> Duration

The base offset from UTC; this usually doesn’t change unless the government changes something

source

fn dst_offset(&self) -> Duration

The additional offset from UTC that is currently in effect; typically for daylight saving time

Implementors§