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
impl Zone
Sourcepub fn offset_at(&self, unix: i64) -> i32
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).
Sourcepub fn posix(rule: &str) -> Result<Zone, String>
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’.