-
-
Notifications
You must be signed in to change notification settings - Fork 87
Description
Today, Jiff tries to load as many tzdb's as possible depending on the kind. For example, if for some reason Jiff can find a zoneinfo database, a concatenated database and has a bundled database, then it will look through all three on a tz lookup:
Lines 358 to 388 in 94e8270
| pub fn get(&self, name: &str) -> Result<TimeZone, Error> { | |
| let inner = self.inner.as_deref().ok_or_else(|| { | |
| if cfg!(feature = "std") { | |
| err!( | |
| "failed to find time zone `{name}` since there is no \ | |
| time zone database configured", | |
| ) | |
| } else { | |
| err!( | |
| "failed to find time zone `{name}`, there is no \ | |
| global time zone database configured (and is currently \ | |
| impossible to do so without Jiff's `std` feature \ | |
| enabled, if you need this functionality, please file \ | |
| an issue on Jiff's tracker with your use case)", | |
| ) | |
| } | |
| })?; | |
| if let Some(tz) = inner.zoneinfo.get(name) { | |
| trace!("found time zone `{name}` in {:?}", inner.zoneinfo); | |
| return Ok(tz); | |
| } | |
| if let Some(tz) = inner.concatenated.get(name) { | |
| trace!("found time zone `{name}` in {:?}", inner.concatenated); | |
| return Ok(tz); | |
| } | |
| if let Some(tz) = inner.bundled.get(name) { | |
| trace!("found time zone `{name}` in {:?}", inner.bundled); | |
| return Ok(tz); | |
| } | |
| Err(err!("failed to find time zone `{name}` in time zone database")) | |
| } |
I think I did things this way originally because I was thinking about a bundled database "augmenting" an incomplete zoneinfo database. But this is making less sense now with Jiff supporting Android's concatenated database. Overall, I think this is too much "smarts" for not a lot of gain. And it's somewhat less predictable in terms of its behavior.
In jiff 0.2, I plan to make TimeZoneDatabase represent only a single source of tzdb. And which tzdb is used depends on which is found. And different platforms can prioritize different tzdb sources. For example, on Android, I plan to prioritize the concatenated tzdb so that we aren't always looking for the zoneinfo tzdb unnecessarily.