use core::fmt;
use jiff::tz::{AmbiguousOffset, TimeZone};
use crate::time::breakpoints;
use crate::time::error::TimeError;
use crate::time::{Date, Instant, TimeOfDay};
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ZoneName(String);
impl ZoneName {
pub fn new(name: &str) -> Result<Self, TimeError> {
if name.trim().is_empty() {
return Err(TimeError::ZoneNameInvalid {
name: name.to_owned(),
});
}
Ok(Self(name.to_owned()))
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
#[must_use]
pub fn utc() -> Self {
Self("UTC".to_owned())
}
}
impl fmt::Debug for ZoneName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl AsRef<str> for ZoneName {
fn as_ref(&self) -> &str {
&self.0
}
}
impl TryFrom<&str> for ZoneName {
type Error = TimeError;
fn try_from(name: &str) -> Result<Self, TimeError> {
Self::new(name)
}
}
impl TryFrom<String> for ZoneName {
type Error = TimeError;
fn try_from(name: String) -> Result<Self, TimeError> {
if name.trim().is_empty() {
return Err(TimeError::ZoneNameInvalid { name });
}
Ok(Self(name))
}
}
impl fmt::Display for ZoneName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
#[derive(Clone)]
pub struct TimeZoneDatabase {
db: jiff::tz::TimeZoneDatabase,
version: String,
}
impl TimeZoneDatabase {
#[cfg(feature = "bundled-tzdb")]
pub fn bundled() -> Result<Self, TimeError> {
let db = jiff::tz::TimeZoneDatabase::bundled();
if db.is_definitively_empty() {
return Err(TimeError::TzdbBundledUnavailable);
}
Ok(Self {
db,
version: jiff_tzdb::VERSION.to_owned(),
})
}
#[cfg(not(target_family = "wasm"))]
pub fn from_dir(
path: impl AsRef<std::path::Path>,
label: Option<&str>,
) -> Result<Self, TimeError> {
let path = path.as_ref();
let shown = path.display().to_string();
let unusable = |reason: String| TimeError::TzdbDirectoryUnusable {
path: shown.clone(),
reason,
};
let db =
jiff::tz::TimeZoneDatabase::from_dir(path).map_err(|err| unusable(err.to_string()))?;
if db.available().next().is_none() {
return Err(unusable(
"the directory holds no TZif time zone files".to_owned(),
));
}
let version = read_version(path)
.map_err(unusable)?
.or_else(|| normalised_label(label))
.ok_or_else(|| TimeError::TzdbVersionMissing {
path: shown.clone(),
})?;
Ok(Self { db, version })
}
#[must_use]
pub fn version(&self) -> &str {
&self.version
}
pub fn zone(&self, name: &str) -> Result<Zone, TimeError> {
self.db
.get(name)
.map(|inner| Zone {
name: name.to_owned(),
inner,
})
.map_err(|_| TimeError::ZoneUnknown {
name: name.to_owned(),
})
}
#[cfg(all(test, feature = "bundled-tzdb"))]
pub(crate) fn available_names(&self) -> Vec<String> {
self.db
.available()
.map(|name| name.as_str().to_owned())
.collect()
}
}
impl fmt::Debug for TimeZoneDatabase {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("TimeZoneDatabase")
.field("version", &self.version)
.finish_non_exhaustive()
}
}
#[cfg(not(target_family = "wasm"))]
fn read_version(path: &std::path::Path) -> Result<Option<String>, String> {
match std::fs::read_to_string(path.join("+VERSION")) {
Ok(contents) => Ok(normalised_label(Some(&contents))),
Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(None),
Err(err) => Err(format!("+VERSION cannot be read: {err}")),
}
}
#[cfg(not(target_family = "wasm"))]
fn normalised_label(label: Option<&str>) -> Option<String> {
label
.map(str::trim)
.filter(|label| !label.is_empty())
.map(str::to_owned)
}
#[derive(Clone, PartialEq, Eq)]
pub struct Zone {
name: String,
inner: TimeZone,
}
impl Zone {
#[must_use]
pub fn utc() -> Self {
Self {
name: "UTC".to_owned(),
inner: TimeZone::UTC,
}
}
#[must_use]
pub fn name(&self) -> &str {
&self.name
}
#[must_use]
pub fn offset_at(&self, instant: Instant) -> UtcOffset {
UtcOffset {
seconds: self.inner.to_offset(instant.as_jiff()).seconds(),
}
}
#[must_use]
pub fn zoned(&self, instant: Instant) -> ZonedInstant {
instant.zoned(self)
}
pub fn resolve_local(&self, date: Date, time: TimeOfDay) -> Result<LocalResolution, TimeError> {
let to_instant = |seconds: i64| {
Instant::from_unix_seconds(seconds).map_err(|err| match err {
TimeError::InstantOutOfRange { .. } => TimeError::CivilToInstant { date, time },
other => other,
})
};
match self.local_seconds(date, time)?.as_slice() {
[] => Ok(LocalResolution::Skipped),
[only] => Ok(LocalResolution::Unique(to_instant(*only)?)),
[earlier, later] => Ok(LocalResolution::Repeated(
to_instant(*earlier)?,
to_instant(*later)?,
)),
_ => unreachable!("a local date-time occurs at no more than two instants"),
}
}
fn local_seconds(&self, date: Date, time: TimeOfDay) -> Result<LocalValues<i64>, TimeError> {
let datetime = time.on(date);
let to_seconds = |offset: jiff::tz::Offset| {
offset
.to_timestamp(datetime)
.map(jiff::Timestamp::as_second)
.map_err(|_| TimeError::CivilToInstant { date, time })
};
match self.inner.to_ambiguous_zoned_datetime(datetime).offset() {
AmbiguousOffset::Gap { .. } => Ok(LocalValues::empty(0)),
AmbiguousOffset::Unambiguous { offset } => Ok(LocalValues::one(to_seconds(offset)?)),
AmbiguousOffset::Fold { before, after } => {
Ok(LocalValues::two(to_seconds(before)?, to_seconds(after)?))
}
}
}
pub(crate) fn local_instants(
&self,
date: Date,
time: TimeOfDay,
) -> Result<LocalValues<Instant>, TimeError> {
let mut instants = LocalValues::empty(Instant::MIN);
for seconds in self.local_seconds(date, time)? {
match Instant::from_unix_seconds(seconds) {
Ok(instant) => instants.push(instant),
Err(TimeError::InstantOutOfRange { .. }) => {}
Err(other) => return Err(other),
}
}
Ok(instants)
}
pub(crate) fn transition_instants(
&self,
after: Instant,
until: Instant,
) -> Result<Vec<Instant>, TimeError> {
let mut instants = Vec::new();
for transition in self.inner.following(after.as_jiff()) {
let seconds = transition.timestamp().as_second();
if seconds >= until.unix_seconds() {
break;
}
instants.push(Instant::from_unix_seconds(seconds)?);
}
Ok(instants)
}
pub fn day_start(&self, date: Date) -> Result<Instant, TimeError> {
match self.resolve_local(date, TimeOfDay::MIDNIGHT)? {
LocalResolution::Unique(instant) | LocalResolution::Repeated(instant, _) => Ok(instant),
LocalResolution::Skipped => {
let approximately = Instant::from_utc(date, TimeOfDay::MIDNIGHT)?;
let lo = Instant::from_minutes(
(approximately.minutes() - 26 * 60).max(Instant::MIN.minutes()),
)?;
let hi = Instant::from_minutes(
(approximately.minutes() + 26 * 60).min(Instant::MAX.minutes()),
)?;
for transition in self.transition_instants(lo, hi)? {
if self.zoned(transition).date() >= date {
return Ok(transition);
}
}
Ok(lo)
}
}
}
pub fn resolve_local_compatible(
&self,
date: Date,
time: TimeOfDay,
second: u8,
) -> Result<i64, TimeError> {
let unrepresentable = || TimeError::CivilToInstant { date, time };
if second >= 60 {
return Err(TimeError::SecondOutOfRange { second });
}
let datetime = jiff::civil::DateTime::new(
date.year(),
date.month(),
date.day(),
i8::try_from(time.hour()).map_err(|_| unrepresentable())?,
i8::try_from(time.minute()).map_err(|_| unrepresentable())?,
i8::try_from(second).map_err(|_| unrepresentable())?,
0,
)
.map_err(|_| unrepresentable())?;
let zoned = self
.inner
.to_zoned_datetime(datetime)
.map_err(|_| unrepresentable())?;
Ok(zoned.timestamp().as_second())
}
pub(crate) fn last_instant_on(&self, date: Date) -> Result<Option<Instant>, TimeError> {
let next = date.plus_days(1)?;
let midnights = self.local_instants(next, TimeOfDay::MIDNIGHT)?;
if !midnights.as_slice().is_empty() {
let mut last = None;
for midnight in midnights {
let Ok(before) = Instant::from_minutes(midnight.minutes() - 1) else {
continue;
};
if self.zoned(before).date() <= date {
last = Some(last.map_or(before, |seen: Instant| seen.max(before)));
}
}
if last.is_some() {
return Ok(last);
}
}
match self.day_start(next) {
Ok(start) => Ok(Instant::from_minutes(start.minutes() - 1)
.ok()
.filter(|before| self.zoned(*before).date() <= date)),
Err(TimeError::CivilToInstant { .. } | TimeError::InstantOutOfRange { .. }) => {
Ok((date >= self.zoned(Instant::MAX).date()).then_some(Instant::MAX))
}
Err(err) => Err(err),
}
}
pub(crate) fn date_exists(&self, date: Date) -> bool {
let first = self.zoned(Instant::MIN).date();
let last = self.zoned(Instant::MAX).date();
if date < first || date > last {
return false;
}
match self.day_start(date) {
Ok(start) => self.zoned(start).date() <= date,
Err(_) => true,
}
}
pub(crate) fn local_date_bounds(
&self,
from: Instant,
until: Instant,
) -> Result<(Date, Date), TimeError> {
let transitions = self.transition_instants(from, until)?;
Ok(breakpoints::dates_covering(self, from, until, &transitions))
}
}
impl fmt::Debug for Zone {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.name)
}
}
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct UtcOffset {
seconds: i32,
}
impl UtcOffset {
#[must_use]
pub const fn seconds(&self) -> i32 {
self.seconds
}
#[must_use]
pub const fn minutes(&self) -> i32 {
self.seconds / 60
}
}
impl fmt::Debug for UtcOffset {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
impl fmt::Display for UtcOffset {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let sign = if self.seconds < 0 { '-' } else { '+' };
let total = self.seconds.unsigned_abs() / 60;
write!(f, "UTC{sign}{:02}:{:02}", total / 60, total % 60)
}
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct ZonedInstant {
instant: Instant,
date: Date,
time: TimeOfDay,
offset: UtcOffset,
}
impl ZonedInstant {
#[must_use]
pub const fn instant(&self) -> Instant {
self.instant
}
#[must_use]
pub const fn date(&self) -> Date {
self.date
}
#[must_use]
pub const fn time(&self) -> TimeOfDay {
self.time
}
#[must_use]
pub const fn offset(&self) -> UtcOffset {
self.offset
}
}
impl fmt::Debug for ZonedInstant {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
impl fmt::Display for ZonedInstant {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} {} {}", self.date, self.time, self.offset)
}
}
impl Instant {
#[must_use]
pub fn zoned(&self, zone: &Zone) -> ZonedInstant {
let timestamp = self.as_jiff();
let offset = zone.inner.to_offset(timestamp);
let datetime = offset.to_datetime(timestamp);
ZonedInstant {
instant: *self,
date: Date::from_jiff(datetime.date()),
time: TimeOfDay::from_jiff(datetime.time()),
offset: UtcOffset {
seconds: offset.seconds(),
},
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LocalResolution {
Skipped,
Unique(Instant),
Repeated(Instant, Instant),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct LocalValues<T: Copy> {
items: [T; 2],
len: usize,
}
impl<T: Copy> LocalValues<T> {
const fn empty(fill: T) -> Self {
Self {
items: [fill, fill],
len: 0,
}
}
const fn one(first: T) -> Self {
Self {
items: [first, first],
len: 1,
}
}
const fn two(first: T, second: T) -> Self {
Self {
items: [first, second],
len: 2,
}
}
fn push(&mut self, value: T) {
debug_assert!(self.len < 2, "a local date-time occurs at most twice");
self.items[self.len] = value;
self.len += 1;
}
pub(crate) fn as_slice(&self) -> &[T] {
&self.items[..self.len]
}
}
impl<T: Copy> IntoIterator for LocalValues<T> {
type Item = T;
type IntoIter = std::iter::Take<std::array::IntoIter<T, 2>>;
fn into_iter(self) -> Self::IntoIter {
self.items.into_iter().take(self.len)
}
}
#[cfg(all(test, not(target_family = "wasm")))]
fn fixture(directory: &str) -> std::path::PathBuf {
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures")
.join(directory)
}
#[cfg(all(test, feature = "bundled-tzdb"))]
mod bundled_tests {
use super::{TimeZoneDatabase, UtcOffset};
use crate::time::{Instant, TimeOfDay, Zone};
#[test]
fn the_database_reports_the_bundled_version() {
let db = TimeZoneDatabase::bundled().unwrap();
assert_eq!(db.version(), jiff_tzdb::VERSION);
assert!(!db.version().is_empty());
}
#[test]
fn legacy_aliases_resolve_to_the_zone_they_name() {
let db = TimeZoneDatabase::bundled().unwrap();
let alias = db.zone("US/Eastern").unwrap();
let primary = db.zone("America/New_York").unwrap();
assert_eq!(alias.name(), "US/Eastern");
for instant in [Instant::MIN, Instant::MAX] {
assert_eq!(alias.offset_at(instant), primary.offset_at(instant));
}
let noon = Zone::utc()
.resolve_local(
crate::time::Date::new(2027, 3, 14).unwrap(),
TimeOfDay::new(12, 0).unwrap(),
)
.unwrap();
let crate::time::LocalResolution::Unique(noon) = noon else {
panic!("UTC has no transitions")
};
assert_eq!(alias.zoned(noon).offset(), UtcOffset { seconds: -4 * 3600 });
}
#[test]
fn a_local_time_that_no_instant_can_represent_is_reported() {
let db = TimeZoneDatabase::bundled().unwrap();
let west = db.zone("Etc/GMT+12").unwrap();
let error = west
.resolve_local(
crate::time::Date::new(9999, 12, 31).unwrap(),
TimeOfDay::new(23, 59).unwrap(),
)
.unwrap_err();
assert_eq!(error.code(), "civil_to_instant");
}
#[test]
fn a_civil_date_begins_at_its_midnight_or_at_the_transition_that_skips_it() {
let db = TimeZoneDatabase::bundled().unwrap();
let date = |y, m, d| crate::time::Date::new(y, m, d).unwrap();
let new_york = db.zone("America/New_York").unwrap();
let midnight = new_york.day_start(date(2027, 3, 9)).unwrap();
assert_eq!(new_york.zoned(midnight).time(), TimeOfDay::MIDNIGHT);
assert_eq!(new_york.zoned(midnight).date(), date(2027, 3, 9));
assert!(new_york.date_exists(date(2027, 3, 9)));
let santiago = db.zone("America/Santiago").unwrap();
let begins = santiago.day_start(date(2027, 9, 5)).unwrap();
assert_eq!(santiago.zoned(begins).date(), date(2027, 9, 5));
assert_eq!(santiago.zoned(begins).time(), TimeOfDay::new(1, 0).unwrap());
assert_eq!(begins.to_string(), "2027-09-05T04:00Z");
let before = Instant::from_minutes(begins.minutes() - 1).unwrap();
assert_eq!(santiago.zoned(before).date(), date(2027, 9, 4));
let apia = db.zone("Pacific/Apia").unwrap();
assert!(!apia.date_exists(date(2011, 12, 30)));
assert!(apia.date_exists(date(2011, 12, 31)));
let begins = apia.day_start(date(2011, 12, 31)).unwrap();
assert_eq!(apia.zoned(begins).date(), date(2011, 12, 31));
}
#[test]
fn a_local_date_range_is_the_exact_span_of_dates_its_instants_fall_on() {
let db = TimeZoneDatabase::bundled().unwrap();
let new_york = db.zone("America/New_York").unwrap();
let utc = |y, m, d, hour| {
let crate::time::LocalResolution::Unique(instant) = Zone::utc()
.resolve_local(
crate::time::Date::new(y, m, d).unwrap(),
TimeOfDay::new(hour, 0).unwrap(),
)
.unwrap()
else {
panic!("UTC has no transitions")
};
instant
};
let from = utc(2027, 3, 9, 9);
let until = Instant::from_minutes(from.minutes() + 24 * 60).unwrap();
let (first, last) = new_york.local_date_bounds(from, until).unwrap();
assert_eq!(first, crate::time::Date::new(2027, 3, 9).unwrap());
assert_eq!(last, crate::time::Date::new(2027, 3, 10).unwrap());
}
#[test]
fn no_zone_moves_its_offset_backward_by_more_than_a_day() {
const SECONDS_PER_DAY: i64 = 86_400;
let db = TimeZoneDatabase::bundled().unwrap();
let names = db.available_names();
assert!(
names.len() > 400,
"the bundled database holds the IANA zones, but only {} names were listed",
names.len()
);
for name in names {
let zone = db
.zone(&name)
.unwrap_or_else(|err| panic!("`{name}` is listed but does not resolve: {err}"));
let mut highest_offset = i64::from(zone.offset_at(Instant::MIN).seconds());
for transition in zone.inner.following(Instant::MIN.as_jiff()) {
let seconds = transition.timestamp().as_second();
if seconds > Instant::MAX.unix_seconds() {
break;
}
let instant = Instant::from_unix_seconds(seconds).unwrap_or_else(|err| {
panic!(
"`{name}` changes offset at {seconds}, which is not a whole minute: {err}"
)
});
let offset = i64::from(zone.offset_at(instant).seconds());
assert!(
highest_offset - offset <= SECONDS_PER_DAY,
"`{name}` has moved backward from {highest_offset}s to {offset}s by {instant}: \
more than a day, so a grid window near it would miss candidates"
);
highest_offset = highest_offset.max(offset);
}
}
}
#[test]
fn every_zone_has_whole_minute_offsets_across_the_supported_range() {
let db = TimeZoneDatabase::bundled().unwrap();
let names = db.available_names();
assert!(
names.len() > 400,
"the bundled database holds the IANA zones, but only {} names were listed",
names.len()
);
let mut transitions = 0usize;
for name in names {
let zone = db
.zone(&name)
.unwrap_or_else(|err| panic!("`{name}` is listed but does not resolve: {err}"));
let check = |offset: UtcOffset| {
assert_eq!(
offset.seconds() % 60,
0,
"`{name}` has a sub-minute offset of {} seconds",
offset.seconds()
);
};
check(zone.offset_at(Instant::MIN));
for transition in zone.inner.following(Instant::MIN.as_jiff()) {
let seconds = transition.timestamp().as_second();
if seconds > Instant::MAX.unix_seconds() {
break;
}
let instant = Instant::from_unix_seconds(seconds).unwrap_or_else(|err| {
panic!(
"`{name}` changes offset at {seconds}, which is not a whole minute: {err}"
)
});
check(zone.offset_at(instant));
transitions += 1;
}
}
assert!(
transitions > 10_000,
"the sweep should cross the database's transitions, but saw {transitions}"
);
}
}
#[cfg(all(test, not(target_family = "wasm")))]
mod directory_tests {
use super::{TimeZoneDatabase, fixture};
use crate::time::{Date, LocalResolution, TimeOfDay};
#[test]
fn the_version_comes_from_plus_version_then_the_caller_label() {
let versioned = TimeZoneDatabase::from_dir(fixture("tzdb-2018"), None).unwrap();
assert_eq!(versioned.version(), "2018f");
let labelled = TimeZoneDatabase::from_dir(fixture("tzdb-2018"), Some("2026f")).unwrap();
assert_eq!(labelled.version(), "2018f");
let unversioned = TimeZoneDatabase::from_dir(fixture("tzdb-unversioned"), None);
assert_eq!(
unversioned.err(),
Some(crate::time::TimeError::TzdbVersionMissing {
path: fixture("tzdb-unversioned").display().to_string(),
})
);
let labelled =
TimeZoneDatabase::from_dir(fixture("tzdb-unversioned"), Some("custom-2018")).unwrap();
assert_eq!(labelled.version(), "custom-2018");
}
#[test]
fn an_unusable_directory_is_a_construction_error() {
let missing = fixture("no-such-database");
let error = TimeZoneDatabase::from_dir(&missing, Some("2026f")).unwrap_err();
assert_eq!(error.code(), "tzdb_directory_unusable");
assert!(error.to_string().contains("no-such-database"));
}
#[test]
fn a_directory_database_never_falls_back_to_the_system_database() {
let db = TimeZoneDatabase::from_dir(fixture("tzdb-2018"), None).unwrap();
assert!(db.zone("America/Sao_Paulo").is_ok());
assert_eq!(db.zone("Europe/London").unwrap_err().code(), "zone_unknown");
}
#[test]
fn two_database_versions_resolve_the_same_local_time_differently() {
let before = TimeZoneDatabase::from_dir(fixture("tzdb-2018"), None).unwrap();
let after = TimeZoneDatabase::from_dir(fixture("tzdb-2019"), None).unwrap();
assert_ne!(before.version(), after.version());
let date = Date::new(2019, 12, 15).unwrap();
let noon = TimeOfDay::new(12, 0).unwrap();
let older = before
.zone("America/Sao_Paulo")
.unwrap()
.resolve_local(date, noon)
.unwrap();
let newer = after
.zone("America/Sao_Paulo")
.unwrap()
.resolve_local(date, noon)
.unwrap();
let LocalResolution::Unique(older) = older else {
panic!("noon exists")
};
let LocalResolution::Unique(newer) = newer else {
panic!("noon exists")
};
assert_eq!(older.to_string(), "2019-12-15T14:00Z"); assert_eq!(newer.to_string(), "2019-12-15T15:00Z"); assert_ne!(older, newer);
}
}
#[cfg(test)]
mod tests {
use super::{UtcOffset, Zone};
use crate::time::{Date, Instant, LocalResolution, TimeOfDay};
#[test]
fn utc_needs_no_database() {
let utc = Zone::utc();
let noon = utc
.resolve_local(
Date::new(2027, 3, 9).unwrap(),
TimeOfDay::new(12, 0).unwrap(),
)
.unwrap();
let LocalResolution::Unique(instant) = noon else {
panic!("UTC has no transitions")
};
assert_eq!(instant.to_string(), "2027-03-09T12:00Z");
assert_eq!(utc.offset_at(instant), UtcOffset { seconds: 0 });
assert_eq!(utc.offset_at(instant).minutes(), 0);
assert_eq!(utc.offset_at(instant).to_string(), "UTC+00:00");
}
#[test]
fn offsets_display_with_sign_and_minutes() {
assert_eq!(
UtcOffset {
seconds: -12 * 3600
}
.to_string(),
"UTC-12:00"
);
assert_eq!(UtcOffset { seconds: -720 }.minutes(), -12);
assert_eq!(
UtcOffset {
seconds: 5 * 3600 + 45 * 60
}
.to_string(),
"UTC+05:45"
);
assert_eq!(
UtcOffset {
seconds: 5 * 3600 + 45 * 60
}
.minutes(),
345,
"Kathmandu is 5 hours 45 minutes ahead"
);
}
#[test]
fn instants_round_trip_through_utc() {
let instant = Instant::from_minutes(Instant::MIN.minutes() + 123).unwrap();
let local = instant.zoned(&Zone::utc());
assert_eq!(local.instant(), instant);
assert_eq!(local.to_string(), "1975-01-01 02:03 UTC+00:00");
let LocalResolution::Unique(back) = Zone::utc()
.resolve_local(local.date(), local.time())
.unwrap()
else {
panic!("UTC has no transitions")
};
assert_eq!(back, instant);
}
}