Skip to main content

Zone

Enum Zone 

Source
pub enum Zone {
    Utc,
    Local,
    Fixed(i32),
    Rules(Arc<Rules>),
}
Expand description

A time zone: how many seconds its clocks are ahead of UTC at each moment. Zone::Local is the platform’s local zone, which follows summer time; Zone::posix, Zone::tzif and Zone::named read a zone’s rules; Zone::Fixed never changes.

use rich_interact::datetime::{Date, DateTime, Time, Zone};

// Central Europe: an hour ahead in winter, two in summer.
let cet = Zone::posix("CET-1CEST,M3.5.0,M10.5.0/3").unwrap();
let winter = DateTime::new(Date::new(2026, 1, 15), Time::new(12, 0, 0));
let summer = DateTime::new(Date::new(2026, 7, 15), Time::new(12, 0, 0));
assert_eq!(cet.offset_at(winter.to_unix(&Zone::Utc)), 3600);
assert_eq!(cet.offset_at(summer.to_unix(&Zone::Utc)), 7200);

Variants§

§

Utc

Coordinated Universal Time.

§

Local

The platform’s local zone, as it is now configured (TZ, /etc/localtime, the system’s setting).

§

Fixed(i32)

Always this many seconds ahead of UTC (behind if negative).

§

Rules(Arc<Rules>)

A zone’s rules, read by Zone::posix, Zone::tzif or Zone::named.

Implementations§

Source§

impl Zone

Source

pub fn offset_at(&self, unix: i64) -> i32

How many seconds the zone’s clocks are ahead of UTC at unix (seconds since 1970-01-01 00:00 UTC).

Source

pub fn posix(rule: &str) -> Result<Zone, String>

The zone a POSIX TZ rule describes: "CET-1CEST,M3.5.0,M10.5.0/3", "EST5EDT,M3.2.0,M11.1.0", "<+0330>-3:30", "UTC0". A summer time with no days given starts and ends on the United States’.

Source

pub fn tzif(bytes: &[u8]) -> Result<Zone, String>

The zone in a TZif file (/usr/share/zoneinfo/Europe/Berlin): its transitions, and the rule in its footer for the years after.

Source

pub fn named(name: &str) -> Result<Zone, String>

The zone named name in the zoneinfo database ("Europe/London"), read from $TZDIR or /usr/share/zoneinfo; an error where there is no such file (as on Windows).

Trait Implementations§

Source§

impl Clone for Zone

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Zone

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Zone

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Zone

Auto Trait Implementations§

§

impl Freeze for Zone

§

impl RefUnwindSafe for Zone

§

impl Send for Zone

§

impl Sync for Zone

§

impl Unpin for Zone

§

impl UnsafeUnpin for Zone

§

impl UnwindSafe for Zone

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.