Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ log = { version = "0.4.0", optional = true }

tzif = { version = "0.2.3", optional = true }
iana-time-zone = "0.1.61"
jiff-tzdb = { version = "0.1.1", optional = true }
combine = { version = "4.6.7", optional = true }

[features]
log = ["dep:log"]
experimental = ["tzdb"]
tzdb = ["dep:tzif", "std"]
tzdb = ["dep:tzif", "std", "dep:jiff-tzdb", "dep:combine"]
std = []
31 changes: 31 additions & 0 deletions docs/TZDB.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,34 @@ Range: Seconds(36000)..Seconds(39600)
Diff value: Seconds(37800)
Contains Result: true
Result: [LocalTimeTypeRecord { utoff: Seconds(39600), is_dst: true, idx: 4 }, LocalTimeTypeRecord { utoff: Seconds(36000), is_dst: false, idx: 9 }]

## Slim format testing

`jiff_tzdb` and potentially others use a different compiled `tzif`
than operating systems.

Where operating systems use the "-b fat", smaller embedded tzifs may
use "-b slim" (it's also worth noting that slim is the default setting)

What does slim actually do? The slim formats "slims" the size of a tzif
by calculating the transition times for a smaller range. Instead of calculating
the transition times in a larger range, the tzif (and thus user) differs to
the POSIX tz string.

So in order to support "slim" format `tzif`s, we need to be able to resolve the
[POSIX tz string](glibc-posix-docs).

### Running tests / logging

While using `jiff_tzdb`, the binary search will run the below:

Running a date from 2017 using jiff:

time array length: 175
Returned idx: Err(175)

This will panic, because we have gone past the supported transition times, so
we should default to parsing the POSIX tz string.


[glibc-posix-docs]:https://sourceware.org/glibc/manual/2.40/html_node/Proleptic-TZ.html
6 changes: 3 additions & 3 deletions src/components/tz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use num_traits::ToPrimitive;

use crate::{components::Instant, iso::IsoDateTime, TemporalError, TemporalResult};

#[cfg(all(feature = "tzdb", not(target_os = "windows")))]
#[cfg(feature = "experimental")]
use crate::tzdb::FsTzdbProvider;
#[cfg(all(feature = "experimental", not(target_os = "windows")))]
#[cfg(feature = "experimental")]
use std::sync::{LazyLock, Mutex};

#[cfg(all(feature = "experimental", not(target_os = "windows")))]
#[cfg(feature = "experimental")]
pub static TZ_PROVIDER: LazyLock<Mutex<FsTzdbProvider>> =
LazyLock::new(|| Mutex::new(FsTzdbProvider::default()));

Expand Down
8 changes: 4 additions & 4 deletions src/components/zoneddatetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::{

use super::{calendar::CalendarDateLike, tz::TzProvider, PlainDateTime};

#[cfg(all(feature = "experimental", not(target_os = "windows")))]
#[cfg(feature = "experimental")]
use crate::{components::tz::TZ_PROVIDER, TemporalError};
#[cfg(all(feature = "experimental", not(target_os = "windows")))]
#[cfg(feature = "experimental")]
use std::ops::DerefMut;

/// The native Rust implementation of `Temporal.ZonedDateTime`.
Expand Down Expand Up @@ -101,7 +101,7 @@ impl ZonedDateTime {

// ===== TzProvider APIs for ZonedDateTime =====

#[cfg(all(feature = "experimental", not(target_os = "windows")))]
#[cfg(feature = "experimental")]
impl ZonedDateTime {
pub fn year(&self) -> TemporalResult<i32> {
let mut provider = TZ_PROVIDER
Expand Down Expand Up @@ -223,7 +223,7 @@ impl ZonedDateTime {
}
}

#[cfg(all(feature = "tzdb", not(target_os = "windows")))]
#[cfg(feature = "tzdb")]
#[cfg(test)]
mod tests {

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) mod iso;
#[cfg(feature = "std")]
mod sys;

#[cfg(all(feature = "tzdb", not(target_os = "windows")))]
#[cfg(feature = "tzdb")]
pub mod tzdb;

#[doc(hidden)]
Expand Down
Loading