From 676765050ce920a5e40d356e78c7e082d2eb7d42 Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 13 Nov 2026 01:12:07 +0000 Subject: [PATCH 01/13] Print dates and timestamps in ISO form --- src/structs/field_array.rs | 23 +- src/structs/variants/datetime/mod.rs | 77 +------ src/traits/print.rs | 326 ++++++++++++++++++++------- 3 files changed, 258 insertions(+), 168 deletions(-) diff --git a/src/structs/field_array.rs b/src/structs/field_array.rs index 09ffac7..87750f3 100644 --- a/src/structs/field_array.rs +++ b/src/structs/field_array.rs @@ -569,9 +569,17 @@ fn format_field_array_with_timezone( field_array: &FieldArray, timezone: &str, ) -> std::fmt::Result { - use crate::traits::print::MAX_PREVIEW; + use crate::traits::print::{MAX_PREVIEW, format_datetime_value}; use crate::{Array, TemporalArray}; + // Time zone conversion requires the `time` crate. + if cfg!(not(feature = "datetime_ops")) { + panic!( + "Timezone functionality requires the 'datetime_ops' feature. \ + Enable it in Cargo.toml with: features = [\"datetime_ops\"]" + ); + } + let arr = &field_array.array; let len = arr.len(); let nulls = arr.null_count(); @@ -591,7 +599,7 @@ fn format_field_array_with_timezone( if i > 0 { write!(f, ", ")?; } - write!(f, "{}", format_datetime_with_tz(dt.as_ref(), i, timezone))?; + write!(f, "{}", format_datetime_value(dt.as_ref(), i))?; } if len > MAX_PREVIEW { write!(f, ", ...")?; @@ -612,7 +620,7 @@ fn format_field_array_with_timezone( if i > 0 { write!(f, ", ")?; } - write!(f, "{}", format_datetime_with_tz(dt.as_ref(), i, timezone))?; + write!(f, "{}", format_datetime_value(dt.as_ref(), i))?; } if len > MAX_PREVIEW { write!(f, ", ...")?; @@ -623,15 +631,6 @@ fn format_field_array_with_timezone( } } -#[cfg(feature = "datetime")] -fn format_datetime_with_tz(arr: &crate::DatetimeArray, idx: usize, timezone: &str) -> String -where - T: crate::Integer + std::fmt::Display, -{ - use crate::traits::print::format_datetime_value; - format_datetime_value(arr, idx, Some(timezone)) -} - impl Shape for FieldArray { fn shape(&self) -> ShapeDim { ShapeDim::Rank1(self.len()) diff --git a/src/structs/variants/datetime/mod.rs b/src/structs/variants/datetime/mod.rs index c4a5c70..a17a615 100644 --- a/src/structs/variants/datetime/mod.rs +++ b/src/structs/variants/datetime/mod.rs @@ -451,7 +451,7 @@ where T: Integer + Display, { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { - use crate::traits::print::MAX_PREVIEW; + use crate::traits::print::{MAX_PREVIEW, format_datetime_value}; let len = self.len(); let nulls = self.null_count(); @@ -464,78 +464,11 @@ where )?; write!(f, "[")?; - - #[cfg(feature = "datetime_ops")] - { - use time::OffsetDateTime; - for i in 0..usize::min(len, MAX_PREVIEW) { - if i > 0 { - write!(f, ", ")?; - } - match self.value(i) { - Some(val) => match self.time_unit() { - TimeUnit::Seconds => { - let v = val.to_i64().unwrap(); - match OffsetDateTime::from_unix_timestamp(v) { - Ok(dt) => write!(f, "{}", dt), - Err(_) => write!(f, "{}s", val), - } - } - TimeUnit::Milliseconds => { - let v = val.to_i64().unwrap(); - match OffsetDateTime::from_unix_timestamp_nanos((v as i128) * 1_000_000) - { - Ok(dt) => write!(f, "{}", dt), - Err(_) => write!(f, "{}ms", val), - } - } - TimeUnit::Microseconds => { - let v = val.to_i64().unwrap(); - match OffsetDateTime::from_unix_timestamp_nanos((v as i128) * 1_000) { - Ok(dt) => write!(f, "{}", dt), - Err(_) => write!(f, "{}µs", val), - } - } - TimeUnit::Nanoseconds => { - let v = val.to_i64().unwrap(); - match OffsetDateTime::from_unix_timestamp_nanos(v as i128) { - Ok(dt) => write!(f, "{}", dt), - Err(_) => write!(f, "{}ns", val), - } - } - TimeUnit::Days => { - let days = val.to_i64().unwrap(); - match time::Date::from_julian_day((days + UNIX_EPOCH_JULIAN_DAY) as i32) - { - Ok(date) => write!(f, "{}", date), - Err(_) => write!(f, "{}d", val), - } - } - }, - None => write!(f, "null"), - }?; - } - } - - #[cfg(not(feature = "datetime_ops"))] - { - // Raw value plus suffix - let suffix = match self.time_unit() { - TimeUnit::Seconds => "s", - TimeUnit::Milliseconds => "ms", - TimeUnit::Microseconds => "µs", - TimeUnit::Nanoseconds => "ns", - TimeUnit::Days => "d", - }; - for i in 0..usize::min(len, MAX_PREVIEW) { - if i > 0 { - write!(f, ", ")?; - } - match self.value(i) { - Some(val) => write!(f, "{}{}", val, suffix)?, - None => write!(f, "null")?, - } + for i in 0..usize::min(len, MAX_PREVIEW) { + if i > 0 { + write!(f, ", ")?; } + write!(f, "{}", format_datetime_value(self, i))?; } if len > MAX_PREVIEW { diff --git a/src/traits/print.rs b/src/traits/print.rs index ae3cdbf..9ca3f38 100644 --- a/src/traits/print.rs +++ b/src/traits/print.rs @@ -114,8 +114,8 @@ pub(crate) fn value_to_string(arr: &Array, idx: usize) -> String { // ------------------------- datetime ----------------------------- #[cfg(feature = "datetime")] Array::TemporalArray(inner) => match inner { - TemporalArray::Datetime32(dt) => format_datetime_value(dt, idx, None), - TemporalArray::Datetime64(dt) => format_datetime_value(dt, idx, None), + TemporalArray::Datetime32(dt) => format_datetime_value(dt, idx), + TemporalArray::Datetime64(dt) => format_datetime_value(dt, idx), TemporalArray::Null => "null".into(), }, // ------------------------- fallback ----------------------------- @@ -292,104 +292,82 @@ pub(crate) fn print_ndarray_body( } } +/// Formats the datetime value at `idx` according to the array's `Dt`. +/// +/// Under `datetime_ops`, dates and timestamps print in ISO form: +/// - `Date32` and `Date64` print as `YYYY-MM-DD`. +/// - `Timestamp` prints as `YYYY-MM-DD HH:MM:SS`, with fractional seconds +/// only when they are not zero, using the fewest digits needed. +/// - Timestamps with a time zone that resolves to an offset print the local +/// wall time, the offset and the time zone text, as in +/// `2026-01-01 19:30:00 +10:00:00 Australia/Sydney`. +/// Unresolved time zones print the UTC value followed by the time zone text. +/// - `Time32`, `Time64` and `Duration` values print through the `time` crate's +/// `OffsetDateTime` display. +/// +/// Without `datetime_ops`, and for values outside the supported date range, the +/// raw integer prints with its time unit suffix. Nulls print as `null`. #[cfg(feature = "datetime")] -pub(crate) fn format_datetime_value( - arr: &DatetimeArray, - idx: usize, - timezone: Option<&str>, -) -> String +pub(crate) fn format_datetime_value(arr: &DatetimeArray, idx: usize) -> String where T: Integer + std::fmt::Display, { - use crate::MaskedArray; + use crate::{MaskedArray, TimeUnit}; if arr.is_null(idx) { return "null".into(); } #[cfg(feature = "datetime_ops")] { - use crate::TimeUnit; + use crate::Dt; use time::OffsetDateTime; - - let utc_dt = match arr.time_unit() { - TimeUnit::Seconds => { - let secs = arr.data[idx].to_i64().unwrap(); - OffsetDateTime::from_unix_timestamp(secs).ok() - } - TimeUnit::Milliseconds => { - let v = arr.data[idx].to_i64().unwrap(); - OffsetDateTime::from_unix_timestamp_nanos((v as i128) * 1_000_000).ok() - } - TimeUnit::Microseconds => { - let v = arr.data[idx].to_i64().unwrap(); - OffsetDateTime::from_unix_timestamp_nanos((v as i128) * 1_000).ok() - } - TimeUnit::Nanoseconds => { - let v = arr.data[idx].to_i64().unwrap(); - OffsetDateTime::from_unix_timestamp_nanos(v as i128).ok() - } - TimeUnit::Days => { - use crate::structs::variants::datetime::UNIX_EPOCH_JULIAN_DAY; - let days = arr.data[idx].to_i64().unwrap(); - time::Date::from_julian_day((days + UNIX_EPOCH_JULIAN_DAY) as i32) - .ok() - .and_then(|d| d.with_hms(0, 0, 0).ok()) - .map(|dt| dt.assume_utc()) - } - }; - - if let Some(dt) = utc_dt { - if let Some(tz) = timezone { - format_with_timezone(dt, tz) - } else { - dt.to_string() - } - } else { - let v = arr.data[idx]; - let suffix = match arr.time_unit() { - TimeUnit::Seconds => "s", - TimeUnit::Milliseconds => "ms", - TimeUnit::Microseconds => "µs", - TimeUnit::Nanoseconds => "ns", - TimeUnit::Days => "d", + use time::macros::format_description; + + // The conversion depends only on the time unit, and is shared with `DatetimeOps`. + let value = arr.data[idx].to_i64().unwrap(); + if let Some(utc_dt) = DatetimeArray::::i64_to_datetime(value, arr.time_unit()) { + let date_format = format_description!("[year]-[month]-[day]"); + let whole_seconds_format = + format_description!("[year]-[month]-[day] [hour]:[minute]:[second]"); + let fractional_seconds_format = + format_description!("[year]-[month]-[day] [hour]:[minute]:[second].[subsecond]"); + + let format_timestamp = |dt: OffsetDateTime| { + let text = if dt.nanosecond() == 0 { + dt.format(whole_seconds_format) + } else { + dt.format(fractional_seconds_format) + }; + text.unwrap_or_else(|_| dt.to_string()) }; - format!("{v}{suffix}") - } - } - #[cfg(not(feature = "datetime_ops"))] - { - use crate::TimeUnit; - if timezone.is_some() { - panic!( - "Timezone functionality requires the 'datetime_ops' feature. \ - Enable it in Cargo.toml with: features = [\"datetime_ops\"]" - ); + return match &arr.dtype { + Dt::Date32 | Dt::Date64 => utc_dt + .format(date_format) + .unwrap_or_else(|_| utc_dt.to_string()), + Dt::Timestamp(_, None) => format_timestamp(utc_dt), + Dt::Timestamp(_, Some(tz)) => match parse_timezone_offset(tz) { + Some(offset) => { + let local_dt = utc_dt.to_offset(offset); + format!("{} {} {}", format_timestamp(local_dt), local_dt.offset(), tz) + } + // Time zones without a known offset print the UTC value and the time zone text. + None => format!("{} {}", utc_dt, tz), + }, + _ => utc_dt.to_string(), + }; } - - let v = arr.data[idx]; - let suffix = match arr.time_unit() { - TimeUnit::Seconds => "s", - TimeUnit::Milliseconds => "ms", - TimeUnit::Microseconds => "µs", - TimeUnit::Nanoseconds => "ns", - TimeUnit::Days => "d", - }; - format!("{v}{suffix}") } -} -#[cfg(all(feature = "datetime", feature = "datetime_ops"))] -fn format_with_timezone(utc_dt: time::OffsetDateTime, tz: &str) -> String { - // Try to parse as offset string first (e.g., "+05:00", "-08:00") - if let Some(offset) = parse_timezone_offset(tz) { - let local_dt = utc_dt.to_offset(offset); - format!("{} {}", local_dt, tz) - } else { - // For IANA timezones (e.g., "America/New_York"), we can't do full conversion - // without a timezone database. Just append the timezone name. - format!("{} {}", utc_dt, tz) - } + let v = arr.data[idx]; + let suffix = match arr.time_unit() { + TimeUnit::Seconds => "s", + TimeUnit::Milliseconds => "ms", + TimeUnit::Microseconds => "µs", + TimeUnit::Nanoseconds => "ns", + TimeUnit::Days => "d", + }; + format!("{v}{suffix}") } #[cfg(all(feature = "datetime", feature = "datetime_ops"))] @@ -509,4 +487,184 @@ mod tests { assert!(display.contains("678.90"), "display should contain 678.90, got: {}", display); assert!(display.contains("1.00"), "display should contain 1.00, got: {}", display); } + + #[cfg(feature = "datetime_ops")] + fn timestamp_array(values: &[Option], dtype: crate::Dt) -> crate::DatetimeArray { + let data: Vec = values.iter().map(|v| v.unwrap_or(0)).collect(); + let mut arr = crate::DatetimeArray::::from_slice(&data, dtype); + if values.iter().any(|v| v.is_none()) { + arr.null_mask = Some(crate::Bitmask::from_bools( + &values.iter().map(|v| v.is_some()).collect::>(), + )); + } + arr + } + + // Asserts the text through `Array::value_to_string`, `DatetimeArray` Display and + // `FieldArray` Display for each value of a 64-bit datetime array. + #[cfg(feature = "datetime_ops")] + fn assert_datetime_text(arr: crate::DatetimeArray, expected: &[&str]) { + // Values of zoned timestamps print the time zone text given to the array. + if let crate::Dt::Timestamp(_, Some(tz)) = &arr.dtype { + for text in expected.iter().filter(|text| **text != "null") { + assert!(text.ends_with(&format!(" {tz}")), "{text} should end with {tz}"); + } + } + + let list = format!("[{}]", expected.join(", ")); + assert_eq!(arr.to_string().lines().last(), Some(list.as_str())); + + let array = Array::from_datetime_i64(arr); + for (i, text) in expected.iter().enumerate() { + assert_eq!(array.value_to_string(i), *text); + } + + let field_array = crate::FieldArray::from_arr("ts", array); + let display = field_array.to_string(); + assert_eq!(display.lines().last(), Some(list.as_str())); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_date32_prints_iso_date() { + use crate::{DatetimeArray, Dt}; + let mut arr = DatetimeArray::::from_slice(&[20461, 0, -1], Dt::Date32); + arr.null_mask = Some(crate::Bitmask::from_bools(&[true, true, false])); + assert_eq!(arr.to_string().lines().last(), Some("[2026-01-08, 1970-01-01, null]")); + + let array = Array::from_datetime_i32(arr); + assert_eq!(array.value_to_string(0), "2026-01-08"); + assert_eq!(array.value_to_string(1), "1970-01-01"); + assert_eq!(array.value_to_string(2), "null"); + + let display = crate::FieldArray::from_arr("d", array).to_string(); + assert_eq!(display.lines().last(), Some("[2026-01-08, 1970-01-01, null]")); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_date64_prints_iso_date() { + use crate::Dt; + let arr = timestamp_array(&[Some(1_767_830_400_000), None], Dt::Date64); + assert_datetime_text(arr, &["2026-01-08", "null"]); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timestamp_seconds_prints_iso_datetime() { + use crate::{Dt, TimeUnit}; + let arr = timestamp_array( + &[Some(1_767_259_800), None, Some(0)], + Dt::Timestamp(TimeUnit::Seconds, None), + ); + assert_datetime_text(arr, &["2026-01-01 09:30:00", "null", "1970-01-01 00:00:00"]); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timestamp_milliseconds_prints_fraction_when_not_zero() { + use crate::{Dt, TimeUnit}; + let arr = timestamp_array( + &[Some(1_767_259_800_123), Some(1_767_259_800_000), None], + Dt::Timestamp(TimeUnit::Milliseconds, None), + ); + assert_datetime_text( + arr, + &["2026-01-01 09:30:00.123", "2026-01-01 09:30:00", "null"], + ); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timestamp_microseconds_prints_fewest_fraction_digits() { + use crate::{Dt, TimeUnit}; + let arr = timestamp_array( + &[Some(1_767_259_800_500_000), Some(1_767_259_800_000_000), Some(1_767_259_800_000_250)], + Dt::Timestamp(TimeUnit::Microseconds, None), + ); + assert_datetime_text( + arr, + &["2026-01-01 09:30:00.5", "2026-01-01 09:30:00", "2026-01-01 09:30:00.00025"], + ); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timestamp_nanoseconds_prints_fraction_when_not_zero() { + use crate::{Dt, TimeUnit}; + let arr = timestamp_array( + &[Some(1_767_259_800_000_000_001), Some(1_767_259_800_000_000_000), None], + Dt::Timestamp(TimeUnit::Nanoseconds, None), + ); + assert_datetime_text( + arr, + &["2026-01-01 09:30:00.000000001", "2026-01-01 09:30:00", "null"], + ); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timestamp_with_offset_prints_local_time_and_offset() { + use crate::{Dt, TimeUnit}; + let arr = timestamp_array( + &[Some(1_767_259_800_000_000), Some(1_767_259_800_250_000), None], + Dt::Timestamp(TimeUnit::Microseconds, Some("+05:00".into())), + ); + assert_datetime_text( + arr, + &["2026-01-01 14:30:00 +05:00:00 +05:00", "2026-01-01 14:30:00.25 +05:00:00 +05:00", "null"], + ); + + let arr = timestamp_array( + &[Some(1_767_259_800)], + Dt::Timestamp(TimeUnit::Seconds, Some("-08:00".into())), + ); + assert_datetime_text(arr, &["2026-01-01 01:30:00 -08:00:00 -08:00"]); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timestamp_with_named_zone_prints_local_time_and_offset() { + use crate::{Dt, TimeUnit}; + let arr = timestamp_array( + &[Some(1_767_259_800_000), None], + Dt::Timestamp(TimeUnit::Milliseconds, Some("Asia/Tokyo".into())), + ); + assert_datetime_text(arr, &["2026-01-01 18:30:00 +09:00:00 Asia/Tokyo", "null"]); + + let arr = timestamp_array( + &[Some(1_767_259_800)], + Dt::Timestamp(TimeUnit::Seconds, Some("UTC".into())), + ); + assert_datetime_text(arr, &["2026-01-01 09:30:00 +00:00:00 UTC"]); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timestamp_with_unresolved_zone_prints_utc_value_and_zone_text() { + use crate::{Dt, TimeUnit}; + let arr = timestamp_array( + &[Some(1_767_259_800), None], + Dt::Timestamp(TimeUnit::Seconds, Some("Mars/Olympus_Mons".into())), + ); + assert_datetime_text( + arr, + &["2026-01-01 9:30:00.0 +00:00:00 Mars/Olympus_Mons", "null"], + ); + } + + #[cfg(all(feature = "datetime", not(feature = "datetime_ops")))] + #[test] + fn test_datetime_prints_raw_value_without_datetime_ops() { + use crate::{DatetimeArray, Dt, TimeUnit}; + let date = Array::from_datetime_i32(DatetimeArray::from_slice(&[20461], Dt::Date32)); + assert_eq!(date.value_to_string(0), "20461d"); + let ts = DatetimeArray::::from_slice( + &[1_767_259_800_000_000], + Dt::Timestamp(TimeUnit::Microseconds, None), + ); + assert_eq!(ts.to_string().lines().last(), Some("[1767259800000000µs]")); + let ts = Array::from_datetime_i64(ts); + assert_eq!(ts.value_to_string(0), "1767259800000000µs"); + } } From 42b7d2b776678165d78000303a6931587b791d6e Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 20 Nov 2026 03:06:56 +0000 Subject: [PATCH 02/13] Print timestamps with fixed fraction digits and ISO offsets, times of day as HH:MM:SS and durations as counts --- src/traits/print.rs | 232 ++++++++++++++++++++++++++++++++------------ 1 file changed, 168 insertions(+), 64 deletions(-) diff --git a/src/traits/print.rs b/src/traits/print.rs index 9ca3f38..5722a68 100644 --- a/src/traits/print.rs +++ b/src/traits/print.rs @@ -294,19 +294,26 @@ pub(crate) fn print_ndarray_body( /// Formats the datetime value at `idx` according to the array's `Dt`. /// -/// Under `datetime_ops`, dates and timestamps print in ISO form: +/// ## Behaviour +/// With `datetime_ops`: /// - `Date32` and `Date64` print as `YYYY-MM-DD`. -/// - `Timestamp` prints as `YYYY-MM-DD HH:MM:SS`, with fractional seconds -/// only when they are not zero, using the fewest digits needed. -/// - Timestamps with a time zone that resolves to an offset print the local -/// wall time, the offset and the time zone text, as in -/// `2026-01-01 19:30:00 +10:00:00 Australia/Sydney`. -/// Unresolved time zones print the UTC value followed by the time zone text. -/// - `Time32`, `Time64` and `Duration` values print through the `time` crate's -/// `OffsetDateTime` display. +/// - `Timestamp` prints as `YYYY-MM-DD HH:MM:SS`, followed by the fraction +/// digits of its time unit: 3 for milliseconds, 6 for microseconds and 9 for +/// nanoseconds. The values of an array therefore print at one width. +/// - Timestamps with a time zone print the wall time and the UTC offset, as in +/// `2026-01-01 14:30:00+05:00`. Time zone text other than an offset follows +/// the value, as in `2026-01-01 18:30:00+09:00 Asia/Tokyo`. +/// - Time zones that observe daylight saving time, and time zones absent from +/// the time zone tables, print the UTC value with `+00:00` and the time zone +/// text, because the tables hold offsets without transition dates. +/// - `Time32` and `Time64` print the time of day as `HH:MM:SS`, with the +/// fraction digits of their time unit. +/// - `Duration32` and `Duration64` print the stored count with its time unit +/// suffix, as in `90s`. /// -/// Without `datetime_ops`, and for values outside the supported date range, the -/// raw integer prints with its time unit suffix. Nulls print as `null`. +/// Without `datetime_ops`, and for dates and timestamps outside the `time` +/// crate's date range, the stored integer prints with its time unit suffix. +/// Nulls print as `null`. #[cfg(feature = "datetime")] pub(crate) fn format_datetime_value(arr: &DatetimeArray, idx: usize) -> String where @@ -320,42 +327,87 @@ where #[cfg(feature = "datetime_ops")] { use crate::Dt; - use time::OffsetDateTime; - use time::macros::format_description; + use time::{OffsetDateTime, UtcOffset}; - // The conversion depends only on the time unit, and is shared with `DatetimeOps`. + let unit = arr.time_unit(); let value = arr.data[idx].to_i64().unwrap(); - if let Some(utc_dt) = DatetimeArray::::i64_to_datetime(value, arr.time_unit()) { - let date_format = format_description!("[year]-[month]-[day]"); - let whole_seconds_format = - format_description!("[year]-[month]-[day] [hour]:[minute]:[second]"); - let fractional_seconds_format = - format_description!("[year]-[month]-[day] [hour]:[minute]:[second].[subsecond]"); - - let format_timestamp = |dt: OffsetDateTime| { - let text = if dt.nanosecond() == 0 { - dt.format(whole_seconds_format) - } else { - dt.format(fractional_seconds_format) + + // The time unit fixes the number of fraction digits. + let fraction = |nanosecond: u32| match unit { + TimeUnit::Milliseconds => format!(".{:03}", nanosecond / 1_000_000), + TimeUnit::Microseconds => format!(".{:06}", nanosecond / 1_000), + TimeUnit::Nanoseconds => format!(".{:09}", nanosecond), + TimeUnit::Seconds | TimeUnit::Days => String::new(), + }; + let format_date = |dt: OffsetDateTime| { + format!("{:04}-{:02}-{:02}", dt.year(), u8::from(dt.month()), dt.day()) + }; + let format_timestamp = |dt: OffsetDateTime| { + format!( + "{} {:02}:{:02}:{:02}{}", + format_date(dt), + dt.hour(), + dt.minute(), + dt.second(), + fraction(dt.nanosecond()) + ) + }; + + match &arr.dtype { + Dt::Date32 | Dt::Date64 => { + // The conversion depends only on the time unit, and is shared with `DatetimeOps`. + if let Some(dt) = DatetimeArray::::i64_to_datetime(value, unit) { + return format_date(dt); + } + } + Dt::Timestamp(_, None) => { + if let Some(dt) = DatetimeArray::::i64_to_datetime(value, unit) { + return format_timestamp(dt); + } + } + Dt::Timestamp(_, Some(tz)) => { + let offset = parse_timezone_offset(tz); + let local_dt = DatetimeArray::::i64_to_datetime(value, unit) + .and_then(|dt| dt.checked_to_offset(offset.unwrap_or(UtcOffset::UTC))); + if let Some(local_dt) = local_dt { + let seconds = local_dt.offset().whole_seconds(); + let sign = if seconds < 0 { '-' } else { '+' }; + let text = format!( + "{}{}{:02}:{:02}", + format_timestamp(local_dt), + sign, + seconds.abs() / 3_600, + seconds.abs() / 60 % 60 + ); + // Time zone text that is an offset is already printed with the value. + let is_offset_text = tz.starts_with(['+', '-']) + || tz.eq_ignore_ascii_case("UTC") + || tz.eq_ignore_ascii_case("Z"); + return if offset.is_some() && is_offset_text { + text + } else { + format!("{text} {tz}") + }; + } + } + Dt::Time32(_) | Dt::Time64(_) if value >= 0 && unit != TimeUnit::Days => { + let per_second: i64 = match unit { + TimeUnit::Milliseconds => 1_000, + TimeUnit::Microseconds => 1_000_000, + TimeUnit::Nanoseconds => 1_000_000_000, + TimeUnit::Seconds | TimeUnit::Days => 1, }; - text.unwrap_or_else(|_| dt.to_string()) - }; - - return match &arr.dtype { - Dt::Date32 | Dt::Date64 => utc_dt - .format(date_format) - .unwrap_or_else(|_| utc_dt.to_string()), - Dt::Timestamp(_, None) => format_timestamp(utc_dt), - Dt::Timestamp(_, Some(tz)) => match parse_timezone_offset(tz) { - Some(offset) => { - let local_dt = utc_dt.to_offset(offset); - format!("{} {} {}", format_timestamp(local_dt), local_dt.offset(), tz) - } - // Time zones without a known offset print the UTC value and the time zone text. - None => format!("{} {}", utc_dt, tz), - }, - _ => utc_dt.to_string(), - }; + let seconds = value / per_second; + let nanosecond = (value % per_second * (1_000_000_000 / per_second)) as u32; + return format!( + "{:02}:{:02}:{:02}{}", + seconds / 3_600, + seconds / 60 % 60, + seconds % 60, + fraction(nanosecond) + ); + } + _ => {} } } @@ -370,11 +422,24 @@ where format!("{v}{suffix}") } +/// Returns the UTC offset of the time zone text `tz`, for offsets, time zone +/// abbreviations and IANA identifiers with one offset throughout the year. +/// +/// Returns `None` for IANA identifiers that observe daylight saving time, +/// because the time zone tables hold their two offsets without the dates on +/// which each applies, and for text absent from the tables. #[cfg(all(feature = "datetime", feature = "datetime_ops"))] fn parse_timezone_offset(tz: &str) -> Option { - use crate::structs::variants::datetime::tz::lookup_timezone; + use crate::structs::variants::datetime::tz::{TZ_DATABASE, lookup_timezone}; use time::UtcOffset; + if TZ_DATABASE + .get(tz) + .is_some_and(|info| info.std_offset != info.dst_offset) + { + return None; + } + // First try timezone database lookup (handles IANA IDs, abbreviations, and direct offsets) let tz_offset = lookup_timezone(tz)?; @@ -504,13 +569,6 @@ mod tests { // `FieldArray` Display for each value of a 64-bit datetime array. #[cfg(feature = "datetime_ops")] fn assert_datetime_text(arr: crate::DatetimeArray, expected: &[&str]) { - // Values of zoned timestamps print the time zone text given to the array. - if let crate::Dt::Timestamp(_, Some(tz)) = &arr.dtype { - for text in expected.iter().filter(|text| **text != "null") { - assert!(text.ends_with(&format!(" {tz}")), "{text} should end with {tz}"); - } - } - let list = format!("[{}]", expected.join(", ")); assert_eq!(arr.to_string().lines().last(), Some(list.as_str())); @@ -562,7 +620,7 @@ mod tests { #[cfg(feature = "datetime_ops")] #[test] - fn test_timestamp_milliseconds_prints_fraction_when_not_zero() { + fn test_timestamp_milliseconds_prints_three_fraction_digits() { use crate::{Dt, TimeUnit}; let arr = timestamp_array( &[Some(1_767_259_800_123), Some(1_767_259_800_000), None], @@ -570,13 +628,13 @@ mod tests { ); assert_datetime_text( arr, - &["2026-01-01 09:30:00.123", "2026-01-01 09:30:00", "null"], + &["2026-01-01 09:30:00.123", "2026-01-01 09:30:00.000", "null"], ); } #[cfg(feature = "datetime_ops")] #[test] - fn test_timestamp_microseconds_prints_fewest_fraction_digits() { + fn test_timestamp_microseconds_prints_six_fraction_digits() { use crate::{Dt, TimeUnit}; let arr = timestamp_array( &[Some(1_767_259_800_500_000), Some(1_767_259_800_000_000), Some(1_767_259_800_000_250)], @@ -584,13 +642,13 @@ mod tests { ); assert_datetime_text( arr, - &["2026-01-01 09:30:00.5", "2026-01-01 09:30:00", "2026-01-01 09:30:00.00025"], + &["2026-01-01 09:30:00.500000", "2026-01-01 09:30:00.000000", "2026-01-01 09:30:00.000250"], ); } #[cfg(feature = "datetime_ops")] #[test] - fn test_timestamp_nanoseconds_prints_fraction_when_not_zero() { + fn test_timestamp_nanoseconds_prints_nine_fraction_digits() { use crate::{Dt, TimeUnit}; let arr = timestamp_array( &[Some(1_767_259_800_000_000_001), Some(1_767_259_800_000_000_000), None], @@ -598,7 +656,7 @@ mod tests { ); assert_datetime_text( arr, - &["2026-01-01 09:30:00.000000001", "2026-01-01 09:30:00", "null"], + &["2026-01-01 09:30:00.000000001", "2026-01-01 09:30:00.000000000", "null"], ); } @@ -612,31 +670,37 @@ mod tests { ); assert_datetime_text( arr, - &["2026-01-01 14:30:00 +05:00:00 +05:00", "2026-01-01 14:30:00.25 +05:00:00 +05:00", "null"], + &["2026-01-01 14:30:00.000000+05:00", "2026-01-01 14:30:00.250000+05:00", "null"], ); let arr = timestamp_array( &[Some(1_767_259_800)], Dt::Timestamp(TimeUnit::Seconds, Some("-08:00".into())), ); - assert_datetime_text(arr, &["2026-01-01 01:30:00 -08:00:00 -08:00"]); + assert_datetime_text(arr, &["2026-01-01 01:30:00-08:00"]); } #[cfg(feature = "datetime_ops")] #[test] - fn test_timestamp_with_named_zone_prints_local_time_and_offset() { + fn test_timestamp_with_fixed_offset_zone_prints_local_time_offset_and_zone() { use crate::{Dt, TimeUnit}; let arr = timestamp_array( &[Some(1_767_259_800_000), None], Dt::Timestamp(TimeUnit::Milliseconds, Some("Asia/Tokyo".into())), ); - assert_datetime_text(arr, &["2026-01-01 18:30:00 +09:00:00 Asia/Tokyo", "null"]); + assert_datetime_text(arr, &["2026-01-01 18:30:00.000+09:00 Asia/Tokyo", "null"]); + + let arr = timestamp_array( + &[Some(1_767_259_800)], + Dt::Timestamp(TimeUnit::Seconds, Some("AEST".into())), + ); + assert_datetime_text(arr, &["2026-01-01 19:30:00+10:00 AEST"]); let arr = timestamp_array( &[Some(1_767_259_800)], Dt::Timestamp(TimeUnit::Seconds, Some("UTC".into())), ); - assert_datetime_text(arr, &["2026-01-01 09:30:00 +00:00:00 UTC"]); + assert_datetime_text(arr, &["2026-01-01 09:30:00+00:00"]); } #[cfg(feature = "datetime_ops")] @@ -649,8 +713,48 @@ mod tests { ); assert_datetime_text( arr, - &["2026-01-01 9:30:00.0 +00:00:00 Mars/Olympus_Mons", "null"], + &["2026-01-01 09:30:00+00:00 Mars/Olympus_Mons", "null"], + ); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timestamp_with_daylight_saving_zone_prints_utc_value_and_zone_text() { + use crate::{Dt, TimeUnit}; + let arr = timestamp_array( + &[Some(1_767_259_800), None], + Dt::Timestamp(TimeUnit::Seconds, Some("Australia/Sydney".into())), + ); + assert_datetime_text(arr, &["2026-01-01 09:30:00+00:00 Australia/Sydney", "null"]); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_time_of_day_prints_hours_minutes_seconds() { + use crate::{DatetimeArray, Dt, TimeUnit}; + let mut arr = DatetimeArray::::from_slice(&[34_200, 0, 86_399, 0], Dt::Time32(TimeUnit::Seconds)); + arr.null_mask = Some(crate::Bitmask::from_bools(&[true, true, true, false])); + assert_eq!(arr.to_string().lines().last(), Some("[09:30:00, 00:00:00, 23:59:59, null]")); + + let arr = timestamp_array( + &[Some(34_200_250_000), Some(0), None], + Dt::Time64(TimeUnit::Microseconds), ); + assert_datetime_text(arr, &["09:30:00.250000", "00:00:00.000000", "null"]); + + let arr = timestamp_array(&[Some(34_200_000_000_001)], Dt::Time64(TimeUnit::Nanoseconds)); + assert_datetime_text(arr, &["09:30:00.000000001"]); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_durations_print_count_with_unit_suffix() { + use crate::{DatetimeArray, Dt, TimeUnit}; + let arr = timestamp_array(&[Some(90), Some(-5), None], Dt::Duration64(TimeUnit::Seconds)); + assert_datetime_text(arr, &["90s", "-5s", "null"]); + + let arr = DatetimeArray::::from_slice(&[1_500], Dt::Duration32(TimeUnit::Milliseconds)); + assert_eq!(arr.to_string().lines().last(), Some("[1500ms]")); } #[cfg(all(feature = "datetime", not(feature = "datetime_ops")))] From f0dc950abb106535449ee7acbfc7dd16168452c0 Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 20 Nov 2026 03:27:05 +0000 Subject: [PATCH 03/13] Print the time zone text only beside the wall time of that zone --- src/traits/print.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/traits/print.rs b/src/traits/print.rs index 5722a68..dc164f6 100644 --- a/src/traits/print.rs +++ b/src/traits/print.rs @@ -304,8 +304,9 @@ pub(crate) fn print_ndarray_body( /// `2026-01-01 14:30:00+05:00`. Time zone text other than an offset follows /// the value, as in `2026-01-01 18:30:00+09:00 Asia/Tokyo`. /// - Time zones that observe daylight saving time, and time zones absent from -/// the time zone tables, print the UTC value with `+00:00` and the time zone -/// text, because the tables hold offsets without transition dates. +/// the time zone tables, print the UTC value with `+00:00` and without the +/// time zone text. The tables hold their offsets without transition dates, +/// and the time zone text is printed only beside the wall time of that zone. /// - `Time32` and `Time64` print the time of day as `HH:MM:SS`, with the /// fraction digits of their time unit. /// - `Duration32` and `Duration64` print the stored count with its time unit @@ -383,10 +384,12 @@ where let is_offset_text = tz.starts_with(['+', '-']) || tz.eq_ignore_ascii_case("UTC") || tz.eq_ignore_ascii_case("Z"); - return if offset.is_some() && is_offset_text { - text - } else { + // The time zone text follows wall times of that zone only. Values + // printed in UTC end with their `+00:00` offset. + return if offset.is_some() && !is_offset_text { format!("{text} {tz}") + } else { + text }; } } @@ -705,7 +708,7 @@ mod tests { #[cfg(feature = "datetime_ops")] #[test] - fn test_timestamp_with_unresolved_zone_prints_utc_value_and_zone_text() { + fn test_timestamp_with_unresolved_zone_prints_utc_value_with_utc_offset() { use crate::{Dt, TimeUnit}; let arr = timestamp_array( &[Some(1_767_259_800), None], @@ -713,19 +716,19 @@ mod tests { ); assert_datetime_text( arr, - &["2026-01-01 09:30:00+00:00 Mars/Olympus_Mons", "null"], + &["2026-01-01 09:30:00+00:00", "null"], ); } #[cfg(feature = "datetime_ops")] #[test] - fn test_timestamp_with_daylight_saving_zone_prints_utc_value_and_zone_text() { + fn test_timestamp_with_daylight_saving_zone_prints_utc_value_with_utc_offset() { use crate::{Dt, TimeUnit}; let arr = timestamp_array( &[Some(1_767_259_800), None], Dt::Timestamp(TimeUnit::Seconds, Some("Australia/Sydney".into())), ); - assert_datetime_text(arr, &["2026-01-01 09:30:00+00:00 Australia/Sydney", "null"]); + assert_datetime_text(arr, &["2026-01-01 09:30:00+00:00", "null"]); } #[cfg(feature = "datetime_ops")] From e696bfd41dd90c55d5c18d51045c3ccd544a233c Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 20 Nov 2026 03:32:03 +0000 Subject: [PATCH 04/13] Print zoned timestamps in the wall time of their time zone through the IANA Time Zone Database --- Cargo.lock | 16 ++++++ Cargo.toml | 5 +- src/traits/print.rs | 120 +++++++++++++++++++++++++++++++------------- 3 files changed, 106 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b44847d..2f808f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -921,6 +921,7 @@ dependencies = [ "regex", "ryu", "time", + "tzdb_data", "vec64", ] @@ -1762,6 +1763,21 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "tz-rs" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fc6c929ffa10fb34f4a3c7e9a73620a83ef2e85e47f9ec3381b8289e6762f42" + +[[package]] +name = "tzdb_data" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "febaa995f6852367564e16c3369988b99d471d43ed12b1255b8d294661797f1c" +dependencies = [ + "tz-rs", +] + [[package]] name = "unicode-ident" version = "1.0.24" diff --git a/Cargo.toml b/Cargo.toml index a75f3fb..c41a086 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,8 @@ polars-core = { version = "0.55.2", default-features = false, features = [ polars-arrow = { version = "0.55.2", optional = true } time = { version = "0.3", optional = true, features = ["parsing", "formatting", "macros", "local-offset"] } phf = { version = "0.13.1", features = ["macros"], optional = true } +# IANA Time Zone Database as static data, for the UTC offset of each time zone at an instant. +tzdb_data = { version = "0.2.5", optional = true } num-traits = "0.2.19" rayon = { version = "1.11.0", optional = true } ryu = { version = "1.0.23", optional = true } @@ -206,12 +208,13 @@ simd = [] # - Date/time arithmetic (add/subtract durations, dates) # - Comparison operations # - Component extraction (year, month, day, hour, etc.) +# - Time zone offsets from the IANA Time Zone Database, including daylight saving # At, the expense of an external dependency. # # Without this feature, datetime values are raw integer offsets. # The `ArrowType` stored in `Field` and/or `FieldArray` specifies the # logical type (Date32, Date64, Timestamp, etc.) for Arrow FFI compatibility. -datetime_ops = ["dep:time", "dep:phf", "datetime"] +datetime_ops = ["dep:time", "dep:phf", "dep:tzdb_data", "datetime"] # Adds string arithmetic kernels # Includes (small) external dependencies, and supports diff --git a/src/traits/print.rs b/src/traits/print.rs index dc164f6..df636f2 100644 --- a/src/traits/print.rs +++ b/src/traits/print.rs @@ -300,13 +300,17 @@ pub(crate) fn print_ndarray_body( /// - `Timestamp` prints as `YYYY-MM-DD HH:MM:SS`, followed by the fraction /// digits of its time unit: 3 for milliseconds, 6 for microseconds and 9 for /// nanoseconds. The values of an array therefore print at one width. -/// - Timestamps with a time zone print the wall time and the UTC offset, as in -/// `2026-01-01 14:30:00+05:00`. Time zone text other than an offset follows -/// the value, as in `2026-01-01 18:30:00+09:00 Asia/Tokyo`. -/// - Time zones that observe daylight saving time, and time zones absent from -/// the time zone tables, print the UTC value with `+00:00` and without the -/// time zone text. The tables hold their offsets without transition dates, -/// and the time zone text is printed only beside the wall time of that zone. +/// - Timestamps with a time zone print the wall time of that time zone and +/// its UTC offset at that instant, as in `2026-01-01 14:30:00+05:00`. Time +/// zone text other than an offset follows the value, as in +/// `2026-01-01 20:30:00+11:00 Australia/Sydney`. +/// - IANA identifiers are resolved through the IANA Time Zone Database, which +/// includes daylight saving and historical transitions. The same time zone +/// therefore prints `+11:00` in January and `+10:00` in July for Sydney. +/// - Offsets with seconds, which occur before standard time was adopted, +/// print as `+HH:MM:SS`. +/// - Time zone text that is not an offset, an abbreviation or an IANA +/// identifier prints the UTC value with `+00:00` and without that text. /// - `Time32` and `Time64` print the time of day as `HH:MM:SS`, with the /// fraction digits of their time unit. /// - `Duration32` and `Duration64` print the stored count with its time unit @@ -367,19 +371,23 @@ where } } Dt::Timestamp(_, Some(tz)) => { - let offset = parse_timezone_offset(tz); - let local_dt = DatetimeArray::::i64_to_datetime(value, unit) - .and_then(|dt| dt.checked_to_offset(offset.unwrap_or(UtcOffset::UTC))); + let utc_dt = DatetimeArray::::i64_to_datetime(value, unit); + let offset = utc_dt.and_then(|dt| timezone_offset(tz, dt.unix_timestamp())); + let local_dt = + utc_dt.and_then(|dt| dt.checked_to_offset(offset.unwrap_or(UtcOffset::UTC))); if let Some(local_dt) = local_dt { let seconds = local_dt.offset().whole_seconds(); let sign = if seconds < 0 { '-' } else { '+' }; - let text = format!( + let mut text = format!( "{}{}{:02}:{:02}", format_timestamp(local_dt), sign, seconds.abs() / 3_600, seconds.abs() / 60 % 60 ); + if seconds % 60 != 0 { + text.push_str(&format!(":{:02}", seconds.abs() % 60)); + } // Time zone text that is an offset is already printed with the value. let is_offset_text = tz.starts_with(['+', '-']) || tz.eq_ignore_ascii_case("UTC") @@ -425,29 +433,31 @@ where format!("{v}{suffix}") } -/// Returns the UTC offset of the time zone text `tz`, for offsets, time zone -/// abbreviations and IANA identifiers with one offset throughout the year. +/// Returns the UTC offset in effect at `unix_seconds` for the time zone text `tz`. +/// +/// ## Behaviour +/// - Time zone abbreviations in `ABBR_TO_OFFSET` return their fixed offset. +/// - IANA identifiers return the offset of that instant from the IANA Time +/// Zone Database, which includes daylight saving and historical transitions. +/// - `UTC`, `Z` and offsets such as `+05:00` and `+0530` return that offset. /// -/// Returns `None` for IANA identifiers that observe daylight saving time, -/// because the time zone tables hold their two offsets without the dates on -/// which each applies, and for text absent from the tables. +/// Returns `None` for any other text. #[cfg(all(feature = "datetime", feature = "datetime_ops"))] -fn parse_timezone_offset(tz: &str) -> Option { - use crate::structs::variants::datetime::tz::{TZ_DATABASE, lookup_timezone}; +fn timezone_offset(tz: &str, unix_seconds: i64) -> Option { + use crate::structs::variants::datetime::tz::ABBR_TO_OFFSET; use time::UtcOffset; - if TZ_DATABASE - .get(tz) - .is_some_and(|info| info.std_offset != info.dst_offset) - { - return None; + let tz = match ABBR_TO_OFFSET.get(tz) { + Some(offset) => offset, + None => { + if let Some(zone) = tzdb_data::find_tz(tz.as_bytes()) { + let seconds = zone.find_local_time_type(unix_seconds).ok()?.ut_offset(); + return UtcOffset::from_whole_seconds(seconds).ok(); + } + tz + } } - - // First try timezone database lookup (handles IANA IDs, abbreviations, and direct offsets) - let tz_offset = lookup_timezone(tz)?; - - // Now parse the resolved offset string - let tz = tz_offset.trim(); + .trim(); // Handle UTC specially if tz.eq_ignore_ascii_case("UTC") || tz.eq_ignore_ascii_case("Z") { @@ -685,7 +695,7 @@ mod tests { #[cfg(feature = "datetime_ops")] #[test] - fn test_timestamp_with_fixed_offset_zone_prints_local_time_offset_and_zone() { + fn test_timestamp_with_named_zone_prints_local_time_offset_and_zone() { use crate::{Dt, TimeUnit}; let arr = timestamp_array( &[Some(1_767_259_800_000), None], @@ -720,15 +730,57 @@ mod tests { ); } + // The expected text is from Python's `zoneinfo`, which reads the IANA Time + // Zone Database. It covers daylight saving in both hemispheres, the seconds + // either side of a transition, historical rules, offsets of 30 and 45 + // minutes, and local mean time offsets with seconds. #[cfg(feature = "datetime_ops")] #[test] - fn test_timestamp_with_daylight_saving_zone_prints_utc_value_with_utc_offset() { + fn test_timestamp_with_iana_zone_prints_wall_time_and_offset_of_the_instant() { + use crate::{Dt, TimeUnit}; + let cases: [(&str, i64, &str); 17] = [ + ("Australia/Sydney", 1767259800, "2026-01-01 20:30:00+11:00 Australia/Sydney"), + ("Australia/Sydney", 1782898200, "2026-07-01 19:30:00+10:00 Australia/Sydney"), + ("America/New_York", 1767259800, "2026-01-01 04:30:00-05:00 America/New_York"), + ("America/New_York", 1782898200, "2026-07-01 05:30:00-04:00 America/New_York"), + ("Europe/London", 1782898200, "2026-07-01 10:30:00+01:00 Europe/London"), + ("Australia/Sydney", 1775318399, "2026-04-05 02:59:59+11:00 Australia/Sydney"), + ("Australia/Sydney", 1775318400, "2026-04-05 02:00:00+10:00 Australia/Sydney"), + ("America/New_York", 1772953199, "2026-03-08 01:59:59-05:00 America/New_York"), + ("America/New_York", 1772953200, "2026-03-08 03:00:00-04:00 America/New_York"), + ("America/New_York", 1142856000, "2006-03-20 07:00:00-05:00 America/New_York"), + ("Europe/London", 0, "1970-01-01 01:00:00+01:00 Europe/London"), + ("Asia/Kolkata", 1767259800, "2026-01-01 15:00:00+05:30 Asia/Kolkata"), + ("Asia/Kathmandu", 1767259800, "2026-01-01 15:15:00+05:45 Asia/Kathmandu"), + ("Australia/Lord_Howe", 1767259800, "2026-01-01 20:30:00+11:00 Australia/Lord_Howe"), + ("Australia/Lord_Howe", 1782898200, "2026-07-01 20:00:00+10:30 Australia/Lord_Howe"), + ("Australia/Sydney", -2524521600, "1890-01-01 10:04:52+10:04:52 Australia/Sydney"), + ("America/New_York", -2840140800, "1879-12-31 19:03:58-04:56:02 America/New_York"), + ]; + for (zone, unix_seconds, expected) in cases { + let arr = timestamp_array( + &[Some(unix_seconds), None], + Dt::Timestamp(TimeUnit::Seconds, Some(zone.into())), + ); + assert_datetime_text(arr, &[expected, "null"]); + } + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timestamp_with_iana_zone_prints_fraction_digits_of_its_unit() { use crate::{Dt, TimeUnit}; let arr = timestamp_array( - &[Some(1_767_259_800), None], - Dt::Timestamp(TimeUnit::Seconds, Some("Australia/Sydney".into())), + &[Some(1_767_259_800_123), Some(1_782_898_200_000)], + Dt::Timestamp(TimeUnit::Milliseconds, Some("Australia/Sydney".into())), + ); + assert_datetime_text( + arr, + &[ + "2026-01-01 20:30:00.123+11:00 Australia/Sydney", + "2026-07-01 19:30:00.000+10:00 Australia/Sydney", + ], ); - assert_datetime_text(arr, &["2026-01-01 09:30:00+00:00", "null"]); } #[cfg(feature = "datetime_ops")] From 75e8e4f9df00311efd75a70acd6eb959e06ddc01 Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 20 Nov 2026 03:36:37 +0000 Subject: [PATCH 05/13] Drop the unused formatting and local-offset features of the time dependency --- Cargo.lock | 11 ----------- Cargo.toml | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f808f7..55eb1b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -991,15 +991,6 @@ dependencies = [ "libm", ] -[[package]] -name = "num_threads" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" -dependencies = [ - "libc", -] - [[package]] name = "object" version = "0.39.1" @@ -1706,9 +1697,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134" dependencies = [ "deranged", - "libc", "num-conv", - "num_threads", "powerfmt", "serde_core", "time-core", diff --git a/Cargo.toml b/Cargo.toml index c41a086..00c411b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ polars-core = { version = "0.55.2", default-features = false, features = [ "dtype-decimal", ], optional = true } polars-arrow = { version = "0.55.2", optional = true } -time = { version = "0.3", optional = true, features = ["parsing", "formatting", "macros", "local-offset"] } +time = { version = "0.3", optional = true, features = ["parsing", "macros"] } phf = { version = "0.13.1", features = ["macros"], optional = true } # IANA Time Zone Database as static data, for the UTC offset of each time zone at an instant. tzdb_data = { version = "0.2.5", optional = true } From f2877e184ca1e2e6d5c65027d49e76897b20668b Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 20 Nov 2026 03:45:59 +0000 Subject: [PATCH 06/13] Remove the phf dependency and the time macros feature from datetime_ops --- Cargo.lock | 54 +-- Cargo.toml | 5 +- src/structs/variants/datetime/tz.rs | 670 ++++------------------------ src/traits/print.rs | 91 +++- src/utils.rs | 30 +- 5 files changed, 210 insertions(+), 640 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55eb1b7..9f7e674 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -384,7 +384,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6139a8597ed92cf816dfb33f5dd6cf0bb93a6adc938f11039f371bc5bcd26c3" dependencies = [ "chrono", - "phf 0.12.1", + "phf", ] [[package]] @@ -616,12 +616,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6e8948ce679d00a02a94739ea185595dca7118ed04feb991127e443bd3d761f" -[[package]] -name = "fastrand" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" - [[package]] name = "find-msvc-tools" version = "0.1.11" @@ -914,7 +908,6 @@ dependencies = [ "memchr", "num-traits", "parking_lot", - "phf 0.13.1", "polars-arrow", "polars-core", "rayon", @@ -1051,41 +1044,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "913273894cec178f401a31ec4b656318d95473527be05c0752cc41cdc32be8b7" dependencies = [ - "phf_shared 0.12.1", -] - -[[package]] -name = "phf" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf" -dependencies = [ - "phf_macros", - "phf_shared 0.13.1", - "serde", -] - -[[package]] -name = "phf_generator" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "135ace3a761e564ec88c03a77317a7c6b80bb7f7135ef2544dbe054243b89737" -dependencies = [ - "fastrand", - "phf_shared 0.13.1", -] - -[[package]] -name = "phf_macros" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812f032b54b1e759ccd5f8b6677695d5268c588701effba24601f6932f8269ef" -dependencies = [ - "phf_generator", - "phf_shared 0.13.1", - "proc-macro2", - "quote", - "syn 2.0.119", + "phf_shared", ] [[package]] @@ -1097,15 +1056,6 @@ dependencies = [ "siphasher", ] -[[package]] -name = "phf_shared" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266" -dependencies = [ - "siphasher", -] - [[package]] name = "pin-project-lite" version = "0.2.17" diff --git a/Cargo.toml b/Cargo.toml index 00c411b..b0c70fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,8 +40,7 @@ polars-core = { version = "0.55.2", default-features = false, features = [ "dtype-decimal", ], optional = true } polars-arrow = { version = "0.55.2", optional = true } -time = { version = "0.3", optional = true, features = ["parsing", "macros"] } -phf = { version = "0.13.1", features = ["macros"], optional = true } +time = { version = "0.3", optional = true, features = ["parsing"] } # IANA Time Zone Database as static data, for the UTC offset of each time zone at an instant. tzdb_data = { version = "0.2.5", optional = true } num-traits = "0.2.19" @@ -214,7 +213,7 @@ simd = [] # Without this feature, datetime values are raw integer offsets. # The `ArrowType` stored in `Field` and/or `FieldArray` specifies the # logical type (Date32, Date64, Timestamp, etc.) for Arrow FFI compatibility. -datetime_ops = ["dep:time", "dep:phf", "dep:tzdb_data", "datetime"] +datetime_ops = ["dep:time", "dep:tzdb_data", "datetime"] # Adds string arithmetic kernels # Includes (small) external dependencies, and supports diff --git a/src/structs/variants/datetime/tz.rs b/src/structs/variants/datetime/tz.rs index fc9c272..4f3cd25 100644 --- a/src/structs/variants/datetime/tz.rs +++ b/src/structs/variants/datetime/tz.rs @@ -12,533 +12,101 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! # **Timezone Database** - *IANA Timezone Mappings* +//! # **Time Zone Abbreviations** - *Fixed UTC Offsets* //! -//! Provides compile-time static maps for looking up timezone offsets by: -//! - IANA timezone identifier (e.g., "Australia/Sydney") -//! - Timezone abbreviation (e.g., "AEST", "AEDT") -//! - Direct offset string (e.g., "+10:00") +//! Maps time zone abbreviations, such as `AEST` and `EDT`, to their fixed UTC +//! offsets. //! -//! All 341 canonical timezones from the IANA timezone database are included. -//! However, these are based on static entries. If you have any specific -//! Datetime timezone requirements, you are responsible for checking and verifying -//! them. +//! IANA identifiers, such as `Australia/Sydney`, are resolved through the IANA +//! Time Zone Database, which includes daylight saving and historical +//! transitions. Abbreviations refer to one offset throughout the year, and are +//! listed in this module. //! -//! If you would like to update a timezone, please file a PR or issue. +//! Some abbreviations are ambiguous. For example, `CST` refers to Central +//! Standard Time, China Standard Time and Cuba Standard Time. The most common +//! reading is used. Consider IANA identifiers or offsets such as `+10:00` +//! where an exact reading is required. -#[cfg(feature = "datetime_ops")] -use phf::{Map, phf_map}; - -/// Timezone information including standard and DST offsets with abbreviations -#[cfg(feature = "datetime_ops")] -#[derive(Debug, Clone, Copy)] -pub struct TimezoneInfo { - /// Standard time offset (e.g., "+10:00") - pub std_offset: &'static str, - /// Daylight saving time offset (e.g., "+11:00") - pub dst_offset: &'static str, - /// Standard time abbreviation (e.g., "AEST") - pub std_abbr: &'static str, - /// Daylight saving time abbreviation (e.g., "AEDT") - pub dst_abbr: &'static str, -} - -/// Static map of IANA timezone identifiers to TimezoneInfo -#[cfg(feature = "datetime_ops")] -pub static TZ_DATABASE: Map<&'static str, TimezoneInfo> = phf_map! { - // Africa - "Africa/Abidjan" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+00:00", std_abbr: "GMT", dst_abbr: "" }, - "Africa/Algiers" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+01:00", std_abbr: "CET", dst_abbr: "" }, - "Africa/Bissau" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+00:00", std_abbr: "GMT", dst_abbr: "" }, - "Africa/Cairo" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Africa/Casablanca" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+01:00", std_abbr: "+01", dst_abbr: "+01" }, - "Africa/Ceuta" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Africa/El_Aaiun" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+01:00", std_abbr: "+01", dst_abbr: "+01" }, - "Africa/Johannesburg" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+02:00", std_abbr: "SAST", dst_abbr: "" }, - "Africa/Juba" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+02:00", std_abbr: "CAT", dst_abbr: "" }, - "Africa/Khartoum" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+02:00", std_abbr: "CAT", dst_abbr: "" }, - "Africa/Lagos" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+01:00", std_abbr: "WAT", dst_abbr: "" }, - "Africa/Maputo" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+02:00", std_abbr: "CAT", dst_abbr: "" }, - "Africa/Monrovia" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+00:00", std_abbr: "GMT", dst_abbr: "" }, - "Africa/Nairobi" => TimezoneInfo { std_offset: "+03:00", dst_offset: "+03:00", std_abbr: "EAT", dst_abbr: "" }, - "Africa/Ndjamena" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+01:00", std_abbr: "WAT", dst_abbr: "" }, - "Africa/Sao_Tome" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+00:00", std_abbr: "GMT", dst_abbr: "" }, - "Africa/Tripoli" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+02:00", std_abbr: "EET", dst_abbr: "" }, - "Africa/Tunis" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+01:00", std_abbr: "CET", dst_abbr: "" }, - "Africa/Windhoek" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+02:00", std_abbr: "CAT", dst_abbr: "" }, - - // America - "America/Adak" => TimezoneInfo { std_offset: "-10:00", dst_offset: "-09:00", std_abbr: "HST", dst_abbr: "HDT" }, - "America/Anchorage" => TimezoneInfo { std_offset: "-09:00", dst_offset: "-08:00", std_abbr: "AKST", dst_abbr: "AKDT" }, - "America/Araguaina" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Argentina/Buenos_Aires" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Argentina/Catamarca" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Argentina/Cordoba" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Argentina/Jujuy" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Argentina/La_Rioja" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Argentina/Mendoza" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Argentina/Rio_Gallegos" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Argentina/Salta" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Argentina/San_Juan" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Argentina/San_Luis" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Argentina/Tucuman" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Argentina/Ushuaia" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Asuncion" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "-04", dst_abbr: "-04" }, - "America/Bahia" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Bahia_Banderas" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "CST", dst_abbr: "" }, - "America/Barbados" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "AST", dst_abbr: "" }, - "America/Belem" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Belize" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "CST", dst_abbr: "" }, - "America/Boa_Vista" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "-04", dst_abbr: "" }, - "America/Bogota" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-05:00", std_abbr: "-05", dst_abbr: "" }, - "America/Boise" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-06:00", std_abbr: "MST", dst_abbr: "MDT" }, - "America/Cambridge_Bay" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-06:00", std_abbr: "MST", dst_abbr: "MDT" }, - "America/Campo_Grande" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "-04", dst_abbr: "" }, - "America/Cancun" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-05:00", std_abbr: "EST", dst_abbr: "" }, - "America/Caracas" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "-04", dst_abbr: "" }, - "America/Cayenne" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Chicago" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-05:00", std_abbr: "CST", dst_abbr: "CDT" }, - "America/Chihuahua" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "CST", dst_abbr: "" }, - "America/Ciudad_Juarez" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-06:00", std_abbr: "MST", dst_abbr: "MDT" }, - "America/Costa_Rica" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "CST", dst_abbr: "" }, - "America/Coyhaique" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Cuiaba" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "-04", dst_abbr: "" }, - "America/Danmarkshavn" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+00:00", std_abbr: "GMT", dst_abbr: "" }, - "America/Dawson" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-07:00", std_abbr: "MST", dst_abbr: "" }, - "America/Dawson_Creek" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-07:00", std_abbr: "MST", dst_abbr: "" }, - "America/Denver" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-06:00", std_abbr: "MST", dst_abbr: "MDT" }, - "America/Detroit" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/Edmonton" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-06:00", std_abbr: "MST", dst_abbr: "MDT" }, - "America/Eirunepe" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-05:00", std_abbr: "-05", dst_abbr: "" }, - "America/El_Salvador" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "CST", dst_abbr: "" }, - "America/Fort_Nelson" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-07:00", std_abbr: "MST", dst_abbr: "" }, - "America/Fortaleza" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Glace_Bay" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-03:00", std_abbr: "AST", dst_abbr: "ADT" }, - "America/Goose_Bay" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-03:00", std_abbr: "AST", dst_abbr: "ADT" }, - "America/Grand_Turk" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/Guatemala" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "CST", dst_abbr: "" }, - "America/Guayaquil" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-05:00", std_abbr: "-05", dst_abbr: "" }, - "America/Guyana" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "-04", dst_abbr: "" }, - "America/Halifax" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-03:00", std_abbr: "AST", dst_abbr: "ADT" }, - "America/Havana" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "CST", dst_abbr: "CDT" }, - "America/Hermosillo" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-07:00", std_abbr: "MST", dst_abbr: "" }, - "America/Indiana/Indianapolis" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/Indiana/Knox" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-05:00", std_abbr: "CST", dst_abbr: "CDT" }, - "America/Indiana/Marengo" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/Indiana/Petersburg" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/Indiana/Tell_City" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-05:00", std_abbr: "CST", dst_abbr: "CDT" }, - "America/Indiana/Vevay" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/Indiana/Vincennes" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/Indiana/Winamac" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/Inuvik" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-06:00", std_abbr: "MST", dst_abbr: "MDT" }, - "America/Iqaluit" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/Jamaica" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-05:00", std_abbr: "EST", dst_abbr: "" }, - "America/Juneau" => TimezoneInfo { std_offset: "-09:00", dst_offset: "-08:00", std_abbr: "AKST", dst_abbr: "AKDT" }, - "America/Kentucky/Louisville" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/Kentucky/Monticello" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/La_Paz" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "-04", dst_abbr: "" }, - "America/Lima" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-05:00", std_abbr: "-05", dst_abbr: "" }, - "America/Los_Angeles" => TimezoneInfo { std_offset: "-08:00", dst_offset: "-07:00", std_abbr: "PST", dst_abbr: "PDT" }, - "America/Maceio" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Managua" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "CST", dst_abbr: "" }, - "America/Manaus" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "-04", dst_abbr: "" }, - "America/Martinique" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "AST", dst_abbr: "" }, - "America/Matamoros" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-05:00", std_abbr: "CST", dst_abbr: "CDT" }, - "America/Mazatlan" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-07:00", std_abbr: "MST", dst_abbr: "" }, - "America/Menominee" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-05:00", std_abbr: "CST", dst_abbr: "CDT" }, - "America/Merida" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "CST", dst_abbr: "" }, - "America/Metlakatla" => TimezoneInfo { std_offset: "-09:00", dst_offset: "-08:00", std_abbr: "AKST", dst_abbr: "AKDT" }, - "America/Mexico_City" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "CST", dst_abbr: "" }, - "America/Miquelon" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-02:00", std_abbr: "-03", dst_abbr: "-02" }, - "America/Moncton" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-03:00", std_abbr: "AST", dst_abbr: "ADT" }, - "America/Monterrey" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "CST", dst_abbr: "" }, - "America/Montevideo" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/New_York" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/Nome" => TimezoneInfo { std_offset: "-09:00", dst_offset: "-08:00", std_abbr: "AKST", dst_abbr: "AKDT" }, - "America/Noronha" => TimezoneInfo { std_offset: "-02:00", dst_offset: "-02:00", std_abbr: "-02", dst_abbr: "" }, - "America/North_Dakota/Beulah" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-05:00", std_abbr: "CST", dst_abbr: "CDT" }, - "America/North_Dakota/Center" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-05:00", std_abbr: "CST", dst_abbr: "CDT" }, - "America/North_Dakota/New_Salem" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-05:00", std_abbr: "CST", dst_abbr: "CDT" }, - "America/Nuuk" => TimezoneInfo { std_offset: "-02:00", dst_offset: "-02:00", std_abbr: "-02", dst_abbr: "-02" }, - "America/Ojinaga" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-05:00", std_abbr: "CST", dst_abbr: "CDT" }, - "America/Panama" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-05:00", std_abbr: "EST", dst_abbr: "" }, - "America/Paramaribo" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Phoenix" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-07:00", std_abbr: "MST", dst_abbr: "" }, - "America/Port-au-Prince" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/Porto_Velho" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "-04", dst_abbr: "" }, - "America/Puerto_Rico" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "AST", dst_abbr: "" }, - "America/Punta_Arenas" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Rankin_Inlet" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-05:00", std_abbr: "CST", dst_abbr: "CDT" }, - "America/Recife" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Regina" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "CST", dst_abbr: "" }, - "America/Resolute" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-05:00", std_abbr: "CST", dst_abbr: "CDT" }, - "America/Rio_Branco" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-05:00", std_abbr: "-05", dst_abbr: "" }, - "America/Santarem" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Santiago" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-03:00", std_abbr: "-04", dst_abbr: "-03" }, - "America/Santo_Domingo" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "AST", dst_abbr: "" }, - "America/Sao_Paulo" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "America/Scoresbysund" => TimezoneInfo { std_offset: "-02:00", dst_offset: "-01:00", std_abbr: "-02", dst_abbr: "-01" }, - "America/Sitka" => TimezoneInfo { std_offset: "-09:00", dst_offset: "-08:00", std_abbr: "AKST", dst_abbr: "AKDT" }, - "America/St_Johns" => TimezoneInfo { std_offset: "-03:30", dst_offset: "-02:30", std_abbr: "NST", dst_abbr: "NDT" }, - "America/Swift_Current" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "CST", dst_abbr: "" }, - "America/Tegucigalpa" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "CST", dst_abbr: "" }, - "America/Thule" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-03:00", std_abbr: "AST", dst_abbr: "ADT" }, - "America/Tijuana" => TimezoneInfo { std_offset: "-08:00", dst_offset: "-07:00", std_abbr: "PST", dst_abbr: "PDT" }, - "America/Toronto" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-04:00", std_abbr: "EST", dst_abbr: "EDT" }, - "America/Vancouver" => TimezoneInfo { std_offset: "-08:00", dst_offset: "-07:00", std_abbr: "PST", dst_abbr: "PDT" }, - "America/Whitehorse" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-07:00", std_abbr: "MST", dst_abbr: "" }, - "America/Winnipeg" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-05:00", std_abbr: "CST", dst_abbr: "CDT" }, - "America/Yakutat" => TimezoneInfo { std_offset: "-09:00", dst_offset: "-08:00", std_abbr: "AKST", dst_abbr: "AKDT" }, - - // Antarctica - "Antarctica/Casey" => TimezoneInfo { std_offset: "+08:00", dst_offset: "+08:00", std_abbr: "+08", dst_abbr: "" }, - "Antarctica/Davis" => TimezoneInfo { std_offset: "+07:00", dst_offset: "+07:00", std_abbr: "+07", dst_abbr: "" }, - "Antarctica/Macquarie" => TimezoneInfo { std_offset: "+10:00", dst_offset: "+10:00", std_abbr: "AEST", dst_abbr: "AEST" }, - "Antarctica/Mawson" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Antarctica/Palmer" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "Antarctica/Rothera" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "Antarctica/Troll" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+02:00", std_abbr: "+00", dst_abbr: "+02" }, - "Antarctica/Vostok" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - - // Asia - "Asia/Almaty" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Asia/Amman" => TimezoneInfo { std_offset: "+03:00", dst_offset: "+03:00", std_abbr: "+03", dst_abbr: "" }, - "Asia/Anadyr" => TimezoneInfo { std_offset: "+12:00", dst_offset: "+12:00", std_abbr: "+12", dst_abbr: "" }, - "Asia/Aqtau" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Asia/Aqtobe" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Asia/Ashgabat" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Asia/Atyrau" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Asia/Baghdad" => TimezoneInfo { std_offset: "+03:00", dst_offset: "+03:00", std_abbr: "+03", dst_abbr: "" }, - "Asia/Baku" => TimezoneInfo { std_offset: "+04:00", dst_offset: "+04:00", std_abbr: "+04", dst_abbr: "" }, - "Asia/Bangkok" => TimezoneInfo { std_offset: "+07:00", dst_offset: "+07:00", std_abbr: "+07", dst_abbr: "" }, - "Asia/Barnaul" => TimezoneInfo { std_offset: "+07:00", dst_offset: "+07:00", std_abbr: "+07", dst_abbr: "" }, - "Asia/Beirut" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Asia/Bishkek" => TimezoneInfo { std_offset: "+06:00", dst_offset: "+06:00", std_abbr: "+06", dst_abbr: "" }, - "Asia/Chita" => TimezoneInfo { std_offset: "+09:00", dst_offset: "+09:00", std_abbr: "+09", dst_abbr: "" }, - "Asia/Colombo" => TimezoneInfo { std_offset: "+05:30", dst_offset: "+05:30", std_abbr: "IST", dst_abbr: "" }, - "Asia/Damascus" => TimezoneInfo { std_offset: "+03:00", dst_offset: "+03:00", std_abbr: "+03", dst_abbr: "" }, - "Asia/Dhaka" => TimezoneInfo { std_offset: "+06:00", dst_offset: "+06:00", std_abbr: "+06", dst_abbr: "" }, - "Asia/Dili" => TimezoneInfo { std_offset: "+09:00", dst_offset: "+09:00", std_abbr: "+09", dst_abbr: "" }, - "Asia/Dubai" => TimezoneInfo { std_offset: "+04:00", dst_offset: "+04:00", std_abbr: "+04", dst_abbr: "" }, - "Asia/Dushanbe" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Asia/Famagusta" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Asia/Gaza" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Asia/Hebron" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Asia/Ho_Chi_Minh" => TimezoneInfo { std_offset: "+07:00", dst_offset: "+07:00", std_abbr: "+07", dst_abbr: "" }, - "Asia/Hong_Kong" => TimezoneInfo { std_offset: "+08:00", dst_offset: "+08:00", std_abbr: "HKT", dst_abbr: "" }, - "Asia/Hovd" => TimezoneInfo { std_offset: "+07:00", dst_offset: "+07:00", std_abbr: "+07", dst_abbr: "" }, - "Asia/Irkutsk" => TimezoneInfo { std_offset: "+08:00", dst_offset: "+08:00", std_abbr: "+08", dst_abbr: "" }, - "Asia/Jakarta" => TimezoneInfo { std_offset: "+07:00", dst_offset: "+07:00", std_abbr: "WIB", dst_abbr: "" }, - "Asia/Jayapura" => TimezoneInfo { std_offset: "+09:00", dst_offset: "+09:00", std_abbr: "WIT", dst_abbr: "" }, - "Asia/Jerusalem" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "IST", dst_abbr: "IDT" }, - "Asia/Kabul" => TimezoneInfo { std_offset: "+04:30", dst_offset: "+04:30", std_abbr: "+0430", dst_abbr: "" }, - "Asia/Kamchatka" => TimezoneInfo { std_offset: "+12:00", dst_offset: "+12:00", std_abbr: "+12", dst_abbr: "" }, - "Asia/Karachi" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "PKT", dst_abbr: "" }, - "Asia/Kathmandu" => TimezoneInfo { std_offset: "+05:45", dst_offset: "+05:45", std_abbr: "NPT", dst_abbr: "" }, - "Asia/Khandyga" => TimezoneInfo { std_offset: "+09:00", dst_offset: "+09:00", std_abbr: "+09", dst_abbr: "" }, - "Asia/Kolkata" => TimezoneInfo { std_offset: "+05:30", dst_offset: "+05:30", std_abbr: "IST", dst_abbr: "" }, - "Asia/Krasnoyarsk" => TimezoneInfo { std_offset: "+07:00", dst_offset: "+07:00", std_abbr: "+07", dst_abbr: "" }, - "Asia/Kuching" => TimezoneInfo { std_offset: "+08:00", dst_offset: "+08:00", std_abbr: "+08", dst_abbr: "" }, - "Asia/Macau" => TimezoneInfo { std_offset: "+08:00", dst_offset: "+08:00", std_abbr: "CST", dst_abbr: "" }, - "Asia/Magadan" => TimezoneInfo { std_offset: "+11:00", dst_offset: "+11:00", std_abbr: "+11", dst_abbr: "" }, - "Asia/Makassar" => TimezoneInfo { std_offset: "+08:00", dst_offset: "+08:00", std_abbr: "WITA", dst_abbr: "" }, - "Asia/Manila" => TimezoneInfo { std_offset: "+08:00", dst_offset: "+08:00", std_abbr: "PST", dst_abbr: "" }, - "Asia/Nicosia" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Asia/Novokuznetsk" => TimezoneInfo { std_offset: "+07:00", dst_offset: "+07:00", std_abbr: "+07", dst_abbr: "" }, - "Asia/Novosibirsk" => TimezoneInfo { std_offset: "+07:00", dst_offset: "+07:00", std_abbr: "+07", dst_abbr: "" }, - "Asia/Omsk" => TimezoneInfo { std_offset: "+06:00", dst_offset: "+06:00", std_abbr: "+06", dst_abbr: "" }, - "Asia/Oral" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Asia/Pontianak" => TimezoneInfo { std_offset: "+07:00", dst_offset: "+07:00", std_abbr: "WIB", dst_abbr: "" }, - "Asia/Pyongyang" => TimezoneInfo { std_offset: "+09:00", dst_offset: "+09:00", std_abbr: "KST", dst_abbr: "" }, - "Asia/Qatar" => TimezoneInfo { std_offset: "+03:00", dst_offset: "+03:00", std_abbr: "+03", dst_abbr: "" }, - "Asia/Qostanay" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Asia/Qyzylorda" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Asia/Riyadh" => TimezoneInfo { std_offset: "+03:00", dst_offset: "+03:00", std_abbr: "+03", dst_abbr: "" }, - "Asia/Sakhalin" => TimezoneInfo { std_offset: "+11:00", dst_offset: "+11:00", std_abbr: "+11", dst_abbr: "" }, - "Asia/Samarkand" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Asia/Seoul" => TimezoneInfo { std_offset: "+09:00", dst_offset: "+09:00", std_abbr: "KST", dst_abbr: "" }, - "Asia/Shanghai" => TimezoneInfo { std_offset: "+08:00", dst_offset: "+08:00", std_abbr: "CST", dst_abbr: "" }, - "Asia/Singapore" => TimezoneInfo { std_offset: "+08:00", dst_offset: "+08:00", std_abbr: "+08", dst_abbr: "" }, - "Asia/Srednekolymsk" => TimezoneInfo { std_offset: "+11:00", dst_offset: "+11:00", std_abbr: "+11", dst_abbr: "" }, - "Asia/Taipei" => TimezoneInfo { std_offset: "+08:00", dst_offset: "+08:00", std_abbr: "CST", dst_abbr: "" }, - "Asia/Tashkent" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Asia/Tbilisi" => TimezoneInfo { std_offset: "+04:00", dst_offset: "+04:00", std_abbr: "+04", dst_abbr: "" }, - "Asia/Tehran" => TimezoneInfo { std_offset: "+03:30", dst_offset: "+03:30", std_abbr: "+0330", dst_abbr: "" }, - "Asia/Thimphu" => TimezoneInfo { std_offset: "+06:00", dst_offset: "+06:00", std_abbr: "+06", dst_abbr: "" }, - "Asia/Tokyo" => TimezoneInfo { std_offset: "+09:00", dst_offset: "+09:00", std_abbr: "JST", dst_abbr: "" }, - "Asia/Tomsk" => TimezoneInfo { std_offset: "+07:00", dst_offset: "+07:00", std_abbr: "+07", dst_abbr: "" }, - "Asia/Ulaanbaatar" => TimezoneInfo { std_offset: "+08:00", dst_offset: "+08:00", std_abbr: "+08", dst_abbr: "" }, - "Asia/Urumqi" => TimezoneInfo { std_offset: "+06:00", dst_offset: "+06:00", std_abbr: "+06", dst_abbr: "" }, - "Asia/Ust-Nera" => TimezoneInfo { std_offset: "+10:00", dst_offset: "+10:00", std_abbr: "+10", dst_abbr: "" }, - "Asia/Vladivostok" => TimezoneInfo { std_offset: "+10:00", dst_offset: "+10:00", std_abbr: "+10", dst_abbr: "" }, - "Asia/Yakutsk" => TimezoneInfo { std_offset: "+09:00", dst_offset: "+09:00", std_abbr: "+09", dst_abbr: "" }, - "Asia/Yangon" => TimezoneInfo { std_offset: "+06:30", dst_offset: "+06:30", std_abbr: "MMT", dst_abbr: "" }, - "Asia/Yekaterinburg" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Asia/Yerevan" => TimezoneInfo { std_offset: "+04:00", dst_offset: "+04:00", std_abbr: "+04", dst_abbr: "" }, - - // Atlantic - "Atlantic/Azores" => TimezoneInfo { std_offset: "-01:00", dst_offset: "+00:00", std_abbr: "-01", dst_abbr: "+00" }, - "Atlantic/Bermuda" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-03:00", std_abbr: "AST", dst_abbr: "ADT" }, - "Atlantic/Canary" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+01:00", std_abbr: "WET", dst_abbr: "WEST" }, - "Atlantic/Cape_Verde" => TimezoneInfo { std_offset: "-01:00", dst_offset: "-01:00", std_abbr: "-01", dst_abbr: "" }, - "Atlantic/Faroe" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+01:00", std_abbr: "WET", dst_abbr: "WEST" }, - "Atlantic/Madeira" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+01:00", std_abbr: "WET", dst_abbr: "WEST" }, - "Atlantic/South_Georgia" => TimezoneInfo { std_offset: "-02:00", dst_offset: "-02:00", std_abbr: "-02", dst_abbr: "" }, - "Atlantic/Stanley" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - - // Australia - "Australia/Adelaide" => TimezoneInfo { std_offset: "+09:30", dst_offset: "+10:30", std_abbr: "ACST", dst_abbr: "ACDT" }, - "Australia/Brisbane" => TimezoneInfo { std_offset: "+10:00", dst_offset: "+10:00", std_abbr: "AEST", dst_abbr: "" }, - "Australia/Broken_Hill" => TimezoneInfo { std_offset: "+09:30", dst_offset: "+10:30", std_abbr: "ACST", dst_abbr: "ACDT" }, - "Australia/Darwin" => TimezoneInfo { std_offset: "+09:30", dst_offset: "+09:30", std_abbr: "ACST", dst_abbr: "" }, - "Australia/Eucla" => TimezoneInfo { std_offset: "+08:45", dst_offset: "+08:45", std_abbr: "+0845", dst_abbr: "" }, - "Australia/Hobart" => TimezoneInfo { std_offset: "+10:00", dst_offset: "+11:00", std_abbr: "AEST", dst_abbr: "AEDT" }, - "Australia/Lindeman" => TimezoneInfo { std_offset: "+10:00", dst_offset: "+10:00", std_abbr: "AEST", dst_abbr: "" }, - "Australia/Lord_Howe" => TimezoneInfo { std_offset: "+10:30", dst_offset: "+11:00", std_abbr: "+1030", dst_abbr: "+11" }, - "Australia/Melbourne" => TimezoneInfo { std_offset: "+10:00", dst_offset: "+11:00", std_abbr: "AEST", dst_abbr: "AEDT" }, - "Australia/Perth" => TimezoneInfo { std_offset: "+08:00", dst_offset: "+08:00", std_abbr: "AWST", dst_abbr: "" }, - "Australia/Sydney" => TimezoneInfo { std_offset: "+10:00", dst_offset: "+11:00", std_abbr: "AEST", dst_abbr: "AEDT" }, - - // Etc - "Etc/GMT" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+00:00", std_abbr: "GMT", dst_abbr: "" }, - "Etc/GMT+1" => TimezoneInfo { std_offset: "-01:00", dst_offset: "-01:00", std_abbr: "-01", dst_abbr: "" }, - "Etc/GMT+10" => TimezoneInfo { std_offset: "-10:00", dst_offset: "-10:00", std_abbr: "-10", dst_abbr: "" }, - "Etc/GMT+11" => TimezoneInfo { std_offset: "-11:00", dst_offset: "-11:00", std_abbr: "-11", dst_abbr: "" }, - "Etc/GMT+12" => TimezoneInfo { std_offset: "-12:00", dst_offset: "-12:00", std_abbr: "-12", dst_abbr: "" }, - "Etc/GMT+2" => TimezoneInfo { std_offset: "-02:00", dst_offset: "-02:00", std_abbr: "-02", dst_abbr: "" }, - "Etc/GMT+3" => TimezoneInfo { std_offset: "-03:00", dst_offset: "-03:00", std_abbr: "-03", dst_abbr: "" }, - "Etc/GMT+4" => TimezoneInfo { std_offset: "-04:00", dst_offset: "-04:00", std_abbr: "-04", dst_abbr: "" }, - "Etc/GMT+5" => TimezoneInfo { std_offset: "-05:00", dst_offset: "-05:00", std_abbr: "-05", dst_abbr: "" }, - "Etc/GMT+6" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "-06", dst_abbr: "" }, - "Etc/GMT+7" => TimezoneInfo { std_offset: "-07:00", dst_offset: "-07:00", std_abbr: "-07", dst_abbr: "" }, - "Etc/GMT+8" => TimezoneInfo { std_offset: "-08:00", dst_offset: "-08:00", std_abbr: "-08", dst_abbr: "" }, - "Etc/GMT+9" => TimezoneInfo { std_offset: "-09:00", dst_offset: "-09:00", std_abbr: "-09", dst_abbr: "" }, - "Etc/GMT-1" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+01:00", std_abbr: "+01", dst_abbr: "" }, - "Etc/GMT-10" => TimezoneInfo { std_offset: "+10:00", dst_offset: "+10:00", std_abbr: "+10", dst_abbr: "" }, - "Etc/GMT-11" => TimezoneInfo { std_offset: "+11:00", dst_offset: "+11:00", std_abbr: "+11", dst_abbr: "" }, - "Etc/GMT-12" => TimezoneInfo { std_offset: "+12:00", dst_offset: "+12:00", std_abbr: "+12", dst_abbr: "" }, - "Etc/GMT-13" => TimezoneInfo { std_offset: "+13:00", dst_offset: "+13:00", std_abbr: "+13", dst_abbr: "" }, - "Etc/GMT-14" => TimezoneInfo { std_offset: "+14:00", dst_offset: "+14:00", std_abbr: "+14", dst_abbr: "" }, - "Etc/GMT-2" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+02:00", std_abbr: "+02", dst_abbr: "" }, - "Etc/GMT-3" => TimezoneInfo { std_offset: "+03:00", dst_offset: "+03:00", std_abbr: "+03", dst_abbr: "" }, - "Etc/GMT-4" => TimezoneInfo { std_offset: "+04:00", dst_offset: "+04:00", std_abbr: "+04", dst_abbr: "" }, - "Etc/GMT-5" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Etc/GMT-6" => TimezoneInfo { std_offset: "+06:00", dst_offset: "+06:00", std_abbr: "+06", dst_abbr: "" }, - "Etc/GMT-7" => TimezoneInfo { std_offset: "+07:00", dst_offset: "+07:00", std_abbr: "+07", dst_abbr: "" }, - "Etc/GMT-8" => TimezoneInfo { std_offset: "+08:00", dst_offset: "+08:00", std_abbr: "+08", dst_abbr: "" }, - "Etc/GMT-9" => TimezoneInfo { std_offset: "+09:00", dst_offset: "+09:00", std_abbr: "+09", dst_abbr: "" }, - "Etc/UTC" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+00:00", std_abbr: "UTC", dst_abbr: "" }, - - // Europe - "Europe/Andorra" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Astrakhan" => TimezoneInfo { std_offset: "+04:00", dst_offset: "+04:00", std_abbr: "+04", dst_abbr: "" }, - "Europe/Athens" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Europe/Belgrade" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Berlin" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Brussels" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Bucharest" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Europe/Budapest" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Chisinau" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Europe/Dublin" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+01:00", std_abbr: "GMT", dst_abbr: "IST" }, - "Europe/Gibraltar" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Helsinki" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Europe/Istanbul" => TimezoneInfo { std_offset: "+03:00", dst_offset: "+03:00", std_abbr: "+03", dst_abbr: "" }, - "Europe/Kaliningrad" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+02:00", std_abbr: "EET", dst_abbr: "" }, - "Europe/Kirov" => TimezoneInfo { std_offset: "+03:00", dst_offset: "+03:00", std_abbr: "MSK", dst_abbr: "" }, - "Europe/Kyiv" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Europe/Lisbon" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+01:00", std_abbr: "WET", dst_abbr: "WEST" }, - "Europe/London" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+01:00", std_abbr: "GMT", dst_abbr: "BST" }, - "Europe/Madrid" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Malta" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Minsk" => TimezoneInfo { std_offset: "+03:00", dst_offset: "+03:00", std_abbr: "+03", dst_abbr: "" }, - "Europe/Moscow" => TimezoneInfo { std_offset: "+03:00", dst_offset: "+03:00", std_abbr: "MSK", dst_abbr: "" }, - "Europe/Paris" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Prague" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Riga" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Europe/Rome" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Samara" => TimezoneInfo { std_offset: "+04:00", dst_offset: "+04:00", std_abbr: "+04", dst_abbr: "" }, - "Europe/Saratov" => TimezoneInfo { std_offset: "+04:00", dst_offset: "+04:00", std_abbr: "+04", dst_abbr: "" }, - "Europe/Simferopol" => TimezoneInfo { std_offset: "+03:00", dst_offset: "+03:00", std_abbr: "MSK", dst_abbr: "" }, - "Europe/Sofia" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Europe/Tallinn" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Europe/Tirane" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Ulyanovsk" => TimezoneInfo { std_offset: "+04:00", dst_offset: "+04:00", std_abbr: "+04", dst_abbr: "" }, - "Europe/Vienna" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Vilnius" => TimezoneInfo { std_offset: "+02:00", dst_offset: "+03:00", std_abbr: "EET", dst_abbr: "EEST" }, - "Europe/Volgograd" => TimezoneInfo { std_offset: "+03:00", dst_offset: "+03:00", std_abbr: "MSK", dst_abbr: "" }, - "Europe/Warsaw" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - "Europe/Zurich" => TimezoneInfo { std_offset: "+01:00", dst_offset: "+02:00", std_abbr: "CET", dst_abbr: "CEST" }, - - // Factory - "Factory" => TimezoneInfo { std_offset: "+00:00", dst_offset: "+00:00", std_abbr: "+00", dst_abbr: "" }, - - // Indian - "Indian/Chagos" => TimezoneInfo { std_offset: "+06:00", dst_offset: "+06:00", std_abbr: "+06", dst_abbr: "" }, - "Indian/Maldives" => TimezoneInfo { std_offset: "+05:00", dst_offset: "+05:00", std_abbr: "+05", dst_abbr: "" }, - "Indian/Mauritius" => TimezoneInfo { std_offset: "+04:00", dst_offset: "+04:00", std_abbr: "+04", dst_abbr: "" }, - - // Pacific - "Pacific/Apia" => TimezoneInfo { std_offset: "+13:00", dst_offset: "+13:00", std_abbr: "+13", dst_abbr: "" }, - "Pacific/Auckland" => TimezoneInfo { std_offset: "+12:00", dst_offset: "+13:00", std_abbr: "NZST", dst_abbr: "NZDT" }, - "Pacific/Bougainville" => TimezoneInfo { std_offset: "+11:00", dst_offset: "+11:00", std_abbr: "+11", dst_abbr: "" }, - "Pacific/Chatham" => TimezoneInfo { std_offset: "+12:45", dst_offset: "+13:45", std_abbr: "+1245", dst_abbr: "+1345" }, - "Pacific/Easter" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-05:00", std_abbr: "-06", dst_abbr: "-05" }, - "Pacific/Efate" => TimezoneInfo { std_offset: "+11:00", dst_offset: "+11:00", std_abbr: "+11", dst_abbr: "" }, - "Pacific/Fakaofo" => TimezoneInfo { std_offset: "+13:00", dst_offset: "+13:00", std_abbr: "+13", dst_abbr: "" }, - "Pacific/Fiji" => TimezoneInfo { std_offset: "+12:00", dst_offset: "+12:00", std_abbr: "+12", dst_abbr: "" }, - "Pacific/Galapagos" => TimezoneInfo { std_offset: "-06:00", dst_offset: "-06:00", std_abbr: "-06", dst_abbr: "" }, - "Pacific/Gambier" => TimezoneInfo { std_offset: "-09:00", dst_offset: "-09:00", std_abbr: "-09", dst_abbr: "" }, - "Pacific/Guadalcanal" => TimezoneInfo { std_offset: "+11:00", dst_offset: "+11:00", std_abbr: "+11", dst_abbr: "" }, - "Pacific/Guam" => TimezoneInfo { std_offset: "+10:00", dst_offset: "+10:00", std_abbr: "ChST", dst_abbr: "" }, - "Pacific/Honolulu" => TimezoneInfo { std_offset: "-10:00", dst_offset: "-10:00", std_abbr: "HST", dst_abbr: "" }, - "Pacific/Kanton" => TimezoneInfo { std_offset: "+13:00", dst_offset: "+13:00", std_abbr: "+13", dst_abbr: "" }, - "Pacific/Kiritimati" => TimezoneInfo { std_offset: "+14:00", dst_offset: "+14:00", std_abbr: "+14", dst_abbr: "" }, - "Pacific/Kosrae" => TimezoneInfo { std_offset: "+11:00", dst_offset: "+11:00", std_abbr: "+11", dst_abbr: "" }, - "Pacific/Kwajalein" => TimezoneInfo { std_offset: "+12:00", dst_offset: "+12:00", std_abbr: "+12", dst_abbr: "" }, - "Pacific/Marquesas" => TimezoneInfo { std_offset: "-09:30", dst_offset: "-09:30", std_abbr: "-0930", dst_abbr: "" }, - "Pacific/Nauru" => TimezoneInfo { std_offset: "+12:00", dst_offset: "+12:00", std_abbr: "+12", dst_abbr: "" }, - "Pacific/Niue" => TimezoneInfo { std_offset: "-11:00", dst_offset: "-11:00", std_abbr: "-11", dst_abbr: "" }, - "Pacific/Norfolk" => TimezoneInfo { std_offset: "+11:00", dst_offset: "+11:00", std_abbr: "+11", dst_abbr: "+11" }, - "Pacific/Noumea" => TimezoneInfo { std_offset: "+11:00", dst_offset: "+11:00", std_abbr: "+11", dst_abbr: "" }, - "Pacific/Pago_Pago" => TimezoneInfo { std_offset: "-11:00", dst_offset: "-11:00", std_abbr: "SST", dst_abbr: "" }, - "Pacific/Palau" => TimezoneInfo { std_offset: "+09:00", dst_offset: "+09:00", std_abbr: "+09", dst_abbr: "" }, - "Pacific/Pitcairn" => TimezoneInfo { std_offset: "-08:00", dst_offset: "-08:00", std_abbr: "-08", dst_abbr: "" }, - "Pacific/Port_Moresby" => TimezoneInfo { std_offset: "+10:00", dst_offset: "+10:00", std_abbr: "+10", dst_abbr: "" }, - "Pacific/Rarotonga" => TimezoneInfo { std_offset: "-10:00", dst_offset: "-10:00", std_abbr: "-10", dst_abbr: "" }, - "Pacific/Tahiti" => TimezoneInfo { std_offset: "-10:00", dst_offset: "-10:00", std_abbr: "-10", dst_abbr: "" }, - "Pacific/Tarawa" => TimezoneInfo { std_offset: "+12:00", dst_offset: "+12:00", std_abbr: "+12", dst_abbr: "" }, - "Pacific/Tongatapu" => TimezoneInfo { std_offset: "+13:00", dst_offset: "+13:00", std_abbr: "+13", dst_abbr: "" }, -}; - -/// Static map of timezone abbreviations to standard offset strings +/// Returns the fixed UTC offset of a time zone abbreviation in `±HH:MM` form. /// -/// Note: Some abbreviations are ambiguous (e.g., "CST" can mean Central Standard Time, -/// China Standard Time, or Cuba Standard Time). This map uses the most common interpretation. -/// For unambiguous results, use IANA timezone identifiers or direct offset strings. -#[cfg(feature = "datetime_ops")] -pub static ABBR_TO_OFFSET: Map<&'static str, &'static str> = phf_map! { - // Common Standard Time Zones - "GMT" => "+00:00", - "UTC" => "+00:00", - "WET" => "+00:00", - "WEST" => "+01:00", - "CET" => "+01:00", - "CEST" => "+02:00", - "EET" => "+02:00", - "EEST" => "+03:00", - "MSK" => "+03:00", - - // Africa - "WAT" => "+01:00", // West Africa Time - "CAT" => "+02:00", // Central Africa Time - "EAT" => "+03:00", // East Africa Time - "SAST" => "+02:00", // South Africa Standard Time - - // Americas - "NST" => "-03:30", // Newfoundland Standard Time - "NDT" => "-02:30", // Newfoundland Daylight Time - "AST" => "-04:00", // Atlantic Standard Time - "ADT" => "-03:00", // Atlantic Daylight Time - "EST" => "-05:00", // Eastern Standard Time (North America) - "EDT" => "-04:00", // Eastern Daylight Time - "CST" => "-06:00", // Central Standard Time (North America, most common) - "CDT" => "-05:00", // Central Daylight Time - "MST" => "-07:00", // Mountain Standard Time - "MDT" => "-06:00", // Mountain Daylight Time - "PST" => "-08:00", // Pacific Standard Time (North America, most common) - "PDT" => "-07:00", // Pacific Daylight Time - "AKST" => "-09:00", // Alaska Standard Time - "AKDT" => "-08:00", // Alaska Daylight Time - "HST" => "-10:00", // Hawaii Standard Time - "HDT" => "-09:00", // Hawaii Daylight Time - "SST" => "-11:00", // Samoa Standard Time - - // Asia - "IST" => "+05:30", // India Standard Time (most common) - "IDT" => "+03:00", // Israel Daylight Time - "PKT" => "+05:00", // Pakistan Standard Time - "WIB" => "+07:00", // Western Indonesian Time - "WITA" => "+08:00", // Central Indonesian Time - "WIT" => "+09:00", // Eastern Indonesian Time - "HKT" => "+08:00", // Hong Kong Time - "JST" => "+09:00", // Japan Standard Time - "KST" => "+09:00", // Korea Standard Time - - // Australia/Pacific - "AWST" => "+08:00", // Australian Western Standard Time - "ACST" => "+09:30", // Australian Central Standard Time - "ACDT" => "+10:30", // Australian Central Daylight Time - "AEST" => "+10:00", // Australian Eastern Standard Time - "AEDT" => "+11:00", // Australian Eastern Daylight Time - "NZST" => "+12:00", // New Zealand Standard Time - "NZDT" => "+13:00", // New Zealand Daylight Time - "ChST" => "+10:00", // Chamorro Standard Time - - // Europe - "BST" => "+01:00", // British Summer Time -}; - -/// Looks up timezone information by IANA identifier, abbreviation, or direct offset +/// Returns `None` for text that is not a listed abbreviation. /// -/// # Arguments -/// * `tz_str` - Timezone string (e.g., "Australia/Sydney", "AEST", "+10:00") -/// -/// # Returns -/// Standard offset string in ±HH:MM format, or None if not found -/// -/// # Examples +/// # Example /// ``` -/// use minarrow::structs::variants::datetime::tz::lookup_timezone; -/// /// # #[cfg(feature = "datetime_ops")] /// # { -/// assert_eq!(lookup_timezone("Australia/Sydney"), Some("+10:00")); -/// assert_eq!(lookup_timezone("AEST"), Some("+10:00")); -/// assert_eq!(lookup_timezone("+10:00"), Some("+10:00")); -/// assert_eq!(lookup_timezone("UTC"), Some("+00:00")); +/// use minarrow::structs::variants::datetime::tz::abbreviation_offset; +/// +/// assert_eq!(abbreviation_offset("AEST"), Some("+10:00")); +/// assert_eq!(abbreviation_offset("AEDT"), Some("+11:00")); +/// assert_eq!(abbreviation_offset("Australia/Sydney"), None); /// # } /// ``` #[cfg(feature = "datetime_ops")] -pub fn lookup_timezone(tz_str: &str) -> Option<&str> { - // Try IANA timezone identifier lookup - if let Some(tz_info) = TZ_DATABASE.get(tz_str) { - return Some(tz_info.std_offset); - } - - // Try abbreviation lookup - if let Some(offset) = ABBR_TO_OFFSET.get(tz_str) { - return Some(offset); - } - - // Check if it's already a direct offset string - if is_offset_string(tz_str) { - return Some(tz_str); - } - - None -} - -/// Checks if a string is a valid offset string (e.g., "+10:00", "-05:00") -#[cfg(feature = "datetime_ops")] -fn is_offset_string(s: &str) -> bool { - if s.eq_ignore_ascii_case("UTC") || s.eq_ignore_ascii_case("Z") { - return true; - } - - let s = s.trim(); - if !s.starts_with('+') && !s.starts_with('-') { - return false; - } - - // Check for HH:MM format or HHMM format - let rest = &s[1..]; - if rest.contains(':') { - // HH:MM format - rest.len() == 5 && rest.chars().all(|c| c.is_ascii_digit() || c == ':') - } else { - // HHMM format - rest.len() == 4 && rest.chars().all(|c| c.is_ascii_digit()) - } +pub fn abbreviation_offset(abbreviation: &str) -> Option<&'static str> { + let offset = match abbreviation { + // Common Standard Time Zones + "GMT" => "+00:00", + "UTC" => "+00:00", + "WET" => "+00:00", + "WEST" => "+01:00", + "CET" => "+01:00", + "CEST" => "+02:00", + "EET" => "+02:00", + "EEST" => "+03:00", + "MSK" => "+03:00", + + // Africa + "WAT" => "+01:00", // West Africa Time + "CAT" => "+02:00", // Central Africa Time + "EAT" => "+03:00", // East Africa Time + "SAST" => "+02:00", // South Africa Standard Time + + // Americas + "NST" => "-03:30", // Newfoundland Standard Time + "NDT" => "-02:30", // Newfoundland Daylight Time + "AST" => "-04:00", // Atlantic Standard Time + "ADT" => "-03:00", // Atlantic Daylight Time + "EST" => "-05:00", // Eastern Standard Time (North America) + "EDT" => "-04:00", // Eastern Daylight Time + "CST" => "-06:00", // Central Standard Time (North America, most common) + "CDT" => "-05:00", // Central Daylight Time + "MST" => "-07:00", // Mountain Standard Time + "MDT" => "-06:00", // Mountain Daylight Time + "PST" => "-08:00", // Pacific Standard Time (North America, most common) + "PDT" => "-07:00", // Pacific Daylight Time + "AKST" => "-09:00", // Alaska Standard Time + "AKDT" => "-08:00", // Alaska Daylight Time + "HST" => "-10:00", // Hawaii Standard Time + "HDT" => "-09:00", // Hawaii Daylight Time + "SST" => "-11:00", // Samoa Standard Time + + // Asia + "IST" => "+05:30", // India Standard Time (most common) + "IDT" => "+03:00", // Israel Daylight Time + "PKT" => "+05:00", // Pakistan Standard Time + "WIB" => "+07:00", // Western Indonesian Time + "WITA" => "+08:00", // Central Indonesian Time + "WIT" => "+09:00", // Eastern Indonesian Time + "HKT" => "+08:00", // Hong Kong Time + "JST" => "+09:00", // Japan Standard Time + "KST" => "+09:00", // Korea Standard Time + + // Australia/Pacific + "AWST" => "+08:00", // Australian Western Standard Time + "ACST" => "+09:30", // Australian Central Standard Time + "ACDT" => "+10:30", // Australian Central Daylight Time + "AEST" => "+10:00", // Australian Eastern Standard Time + "AEDT" => "+11:00", // Australian Eastern Daylight Time + "NZST" => "+12:00", // New Zealand Standard Time + "NZDT" => "+13:00", // New Zealand Daylight Time + "ChST" => "+10:00", // Chamorro Standard Time + + // Europe + "BST" => "+01:00", // British Summer Time + _ => return None, + }; + Some(offset) } #[cfg(all(feature = "datetime", feature = "datetime_ops"))] @@ -547,67 +115,21 @@ mod tests { use super::*; #[test] - fn test_lookup_iana_identifier() { - assert_eq!(lookup_timezone("Australia/Sydney"), Some("+10:00")); - assert_eq!(lookup_timezone("America/New_York"), Some("-05:00")); - assert_eq!(lookup_timezone("Europe/London"), Some("+00:00")); - assert_eq!(lookup_timezone("Asia/Tokyo"), Some("+09:00")); - assert_eq!(lookup_timezone("Pacific/Auckland"), Some("+12:00")); - } - - #[test] - fn test_lookup_abbreviation() { - assert_eq!(lookup_timezone("AEST"), Some("+10:00")); - assert_eq!(lookup_timezone("EST"), Some("-05:00")); - assert_eq!(lookup_timezone("GMT"), Some("+00:00")); - assert_eq!(lookup_timezone("UTC"), Some("+00:00")); - assert_eq!(lookup_timezone("PST"), Some("-08:00")); - assert_eq!(lookup_timezone("JST"), Some("+09:00")); - } - - #[test] - fn test_lookup_direct_offset() { - assert_eq!(lookup_timezone("+10:00"), Some("+10:00")); - assert_eq!(lookup_timezone("-05:00"), Some("-05:00")); - assert_eq!(lookup_timezone("+00:00"), Some("+00:00")); - assert_eq!(lookup_timezone("+05:30"), Some("+05:30")); - assert_eq!(lookup_timezone("-03:30"), Some("-03:30")); - } - - #[test] - fn test_lookup_invalid() { - assert_eq!(lookup_timezone("Invalid/Timezone"), None); - assert_eq!(lookup_timezone("INVALID"), None); - assert_eq!(lookup_timezone("25:00"), None); - } - - #[test] - fn test_unusual_offsets() { - // Test unusual offset timezones - assert_eq!(lookup_timezone("Australia/Eucla"), Some("+08:45")); - assert_eq!(lookup_timezone("Asia/Kathmandu"), Some("+05:45")); - assert_eq!(lookup_timezone("Asia/Colombo"), Some("+05:30")); - assert_eq!(lookup_timezone("America/St_Johns"), Some("-03:30")); - assert_eq!(lookup_timezone("Pacific/Chatham"), Some("+12:45")); + fn test_abbreviation_offsets() { + assert_eq!(abbreviation_offset("AEST"), Some("+10:00")); + assert_eq!(abbreviation_offset("EST"), Some("-05:00")); + assert_eq!(abbreviation_offset("GMT"), Some("+00:00")); + assert_eq!(abbreviation_offset("UTC"), Some("+00:00")); + assert_eq!(abbreviation_offset("PST"), Some("-08:00")); + assert_eq!(abbreviation_offset("JST"), Some("+09:00")); } #[test] - fn test_all_timezones_have_valid_offsets() { - for (tz_name, tz_info) in &TZ_DATABASE { - assert!( - is_offset_string(tz_info.std_offset), - "Invalid std_offset for {}: {}", - tz_name, - tz_info.std_offset - ); - if !tz_info.dst_offset.is_empty() { - assert!( - is_offset_string(tz_info.dst_offset), - "Invalid dst_offset for {}: {}", - tz_name, - tz_info.dst_offset - ); - } - } + fn test_text_other_than_abbreviations_has_no_offset() { + assert_eq!(abbreviation_offset("Australia/Sydney"), None); + assert_eq!(abbreviation_offset("+10:00"), None); + assert_eq!(abbreviation_offset("Invalid/Timezone"), None); + assert_eq!(abbreviation_offset("INVALID"), None); + assert_eq!(abbreviation_offset("25:00"), None); } } diff --git a/src/traits/print.rs b/src/traits/print.rs index df636f2..8162636 100644 --- a/src/traits/print.rs +++ b/src/traits/print.rs @@ -436,7 +436,7 @@ where /// Returns the UTC offset in effect at `unix_seconds` for the time zone text `tz`. /// /// ## Behaviour -/// - Time zone abbreviations in `ABBR_TO_OFFSET` return their fixed offset. +/// - Time zone abbreviations listed in `abbreviation_offset` return their fixed offset. /// - IANA identifiers return the offset of that instant from the IANA Time /// Zone Database, which includes daylight saving and historical transitions. /// - `UTC`, `Z` and offsets such as `+05:00` and `+0530` return that offset. @@ -444,10 +444,10 @@ where /// Returns `None` for any other text. #[cfg(all(feature = "datetime", feature = "datetime_ops"))] fn timezone_offset(tz: &str, unix_seconds: i64) -> Option { - use crate::structs::variants::datetime::tz::ABBR_TO_OFFSET; + use crate::structs::variants::datetime::tz::abbreviation_offset; use time::UtcOffset; - let tz = match ABBR_TO_OFFSET.get(tz) { + let tz = match abbreviation_offset(tz) { Some(offset) => offset, None => { if let Some(zone) = tzdb_data::find_tz(tz.as_bytes()) { @@ -783,6 +783,91 @@ mod tests { ); } + // 1 January 2026 and 1 July 2026 at 09:30:00 UTC. + #[cfg(feature = "datetime_ops")] + const JANUARY: i64 = 1_767_259_800; + #[cfg(feature = "datetime_ops")] + const JULY: i64 = 1_782_898_200; + + #[cfg(feature = "datetime_ops")] + fn offset_text(tz: &str, unix_seconds: i64) -> Option { + timezone_offset(tz, unix_seconds).map(|offset| { + let seconds = offset.whole_seconds(); + let sign = if seconds < 0 { '-' } else { '+' }; + format!("{sign}{:02}:{:02}", seconds.abs() / 3_600, seconds.abs() / 60 % 60) + }) + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timezone_offset_of_iana_identifiers() { + assert_eq!(offset_text("Australia/Sydney", JULY).as_deref(), Some("+10:00")); + assert_eq!(offset_text("Australia/Sydney", JANUARY).as_deref(), Some("+11:00")); + assert_eq!(offset_text("America/New_York", JANUARY).as_deref(), Some("-05:00")); + assert_eq!(offset_text("America/New_York", JULY).as_deref(), Some("-04:00")); + assert_eq!(offset_text("Europe/London", JANUARY).as_deref(), Some("+00:00")); + assert_eq!(offset_text("Europe/London", JULY).as_deref(), Some("+01:00")); + assert_eq!(offset_text("Asia/Tokyo", JANUARY).as_deref(), Some("+09:00")); + assert_eq!(offset_text("Pacific/Auckland", JULY).as_deref(), Some("+12:00")); + assert_eq!(offset_text("Pacific/Auckland", JANUARY).as_deref(), Some("+13:00")); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timezone_offset_of_abbreviations() { + for (abbreviation, offset) in [ + ("AEST", "+10:00"), + ("EST", "-05:00"), + ("GMT", "+00:00"), + ("UTC", "+00:00"), + ("PST", "-08:00"), + ("JST", "+09:00"), + ] { + // Abbreviations have one offset throughout the year. + assert_eq!(offset_text(abbreviation, JANUARY).as_deref(), Some(offset)); + assert_eq!(offset_text(abbreviation, JULY).as_deref(), Some(offset)); + } + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timezone_offset_of_direct_offsets() { + for offset in ["+10:00", "-05:00", "+00:00", "+05:30", "-03:30"] { + assert_eq!(offset_text(offset, JANUARY).as_deref(), Some(offset)); + } + assert_eq!(offset_text("+0530", JANUARY).as_deref(), Some("+05:30")); + assert_eq!(offset_text("Z", JANUARY).as_deref(), Some("+00:00")); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timezone_offset_of_invalid_text() { + assert_eq!(offset_text("Invalid/Timezone", JANUARY), None); + assert_eq!(offset_text("INVALID", JANUARY), None); + assert_eq!(offset_text("25:00", JANUARY), None); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_timezone_offset_of_unusual_offsets() { + assert_eq!(offset_text("Australia/Eucla", JANUARY).as_deref(), Some("+08:45")); + assert_eq!(offset_text("Asia/Kathmandu", JANUARY).as_deref(), Some("+05:45")); + assert_eq!(offset_text("Asia/Colombo", JANUARY).as_deref(), Some("+05:30")); + assert_eq!(offset_text("America/St_Johns", JANUARY).as_deref(), Some("-03:30")); + assert_eq!(offset_text("America/St_Johns", JULY).as_deref(), Some("-02:30")); + assert_eq!(offset_text("Pacific/Chatham", JULY).as_deref(), Some("+12:45")); + assert_eq!(offset_text("Pacific/Chatham", JANUARY).as_deref(), Some("+13:45")); + } + + #[cfg(feature = "datetime_ops")] + #[test] + fn test_every_iana_identifier_has_an_offset() { + for name in tzdb_data::TZ_NAMES { + assert!(timezone_offset(name, JANUARY).is_some(), "no offset for {name}"); + assert!(timezone_offset(name, JULY).is_some(), "no offset for {name}"); + } + } + #[cfg(feature = "datetime_ops")] #[test] fn test_time_of_day_prints_hours_minutes_seconds() { diff --git a/src/utils.rs b/src/utils.rs index 41a9831..87839b4 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -66,12 +66,29 @@ pub fn parse_datetime_str(s: &str) -> Option { #[cfg(feature = "datetime_ops")] { + use std::sync::LazyLock; use time::{ Date, OffsetDateTime, PrimitiveDateTime, Time, - format_description::well_known::{Iso8601, Rfc3339}, - macros::format_description, + format_description::{ + self, BorrowedFormatItem, + well_known::{Iso8601, Rfc3339}, + }, }; + // The format descriptions are parsed on first use. + static DATE_TIME_FORMAT: LazyLock>> = LazyLock::new(|| { + format_description::parse_borrowed::<1>("[year]-[month]-[day] [hour]:[minute]:[second]") + .expect("the date-time format description is valid") + }); + static DATE_FORMAT: LazyLock>> = LazyLock::new(|| { + format_description::parse_borrowed::<1>("[year]-[month]-[day]") + .expect("the date format description is valid") + }); + static TIME_FORMAT: LazyLock>> = LazyLock::new(|| { + format_description::parse_borrowed::<1>("[hour]:[minute]:[second]") + .expect("the time format description is valid") + }); + // Try to parse as RFC3339/ISO8601 string (with timezone) if let Ok(dt) = OffsetDateTime::parse(s, &Rfc3339) { return Some(dt.unix_timestamp() * 1_000 + (dt.nanosecond() / 1_000_000) as i64); @@ -83,8 +100,7 @@ pub fn parse_datetime_str(s: &str) -> Option { } // Try parsing as full date-time (no timezone) "%Y-%m-%d %H:%M:%S" - let format = format_description!("[year]-[month]-[day] [hour]:[minute]:[second]"); - if let Ok(dt) = PrimitiveDateTime::parse(s, format) { + if let Ok(dt) = PrimitiveDateTime::parse(s, DATE_TIME_FORMAT.as_slice()) { let dt_utc = dt.assume_utc(); return Some( dt_utc.unix_timestamp() * 1_000 + (dt_utc.nanosecond() / 1_000_000) as i64, @@ -92,8 +108,7 @@ pub fn parse_datetime_str(s: &str) -> Option { } // Try parsing as date only "%Y-%m-%d" - let date_format = format_description!("[year]-[month]-[day]"); - if let Ok(date) = Date::parse(s, date_format) { + if let Ok(date) = Date::parse(s, DATE_FORMAT.as_slice()) { if let Ok(dt) = date.with_hms(0, 0, 0) { let dt_utc = dt.assume_utc(); return Some(dt_utc.unix_timestamp() * 1_000); @@ -101,8 +116,7 @@ pub fn parse_datetime_str(s: &str) -> Option { } // Try parsing as time only "%H:%M:%S" (use today's date) - let time_format = format_description!("[hour]:[minute]:[second]"); - if let Ok(time) = Time::parse(s, time_format) { + if let Ok(time) = Time::parse(s, TIME_FORMAT.as_slice()) { let today = OffsetDateTime::now_utc().date(); let dt_primitive = today.with_time(time); let dt_utc = dt_primitive.assume_utc(); From e2f656109400fa645c67eace78d878f425ae1dfa Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 20 Nov 2026 03:46:17 +0000 Subject: [PATCH 07/13] Add parse_datetime_str tests --- src/utils.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/utils.rs b/src/utils.rs index 87839b4..b910c4a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -495,3 +495,42 @@ pub fn create_aligned_chunks_from_array( Ok(SuperArray::from_chunks(chunks?)) } + +#[cfg(all(test, feature = "datetime_ops"))] +mod datetime_text_tests { + use super::parse_datetime_str; + + // Milliseconds since the epoch of 2026-01-01 09:30:00 UTC and of that day at midnight. + const INSTANT_MS: i64 = 1_767_259_800_000; + const MIDNIGHT_MS: i64 = 1_767_225_600_000; + + #[test] + fn test_rfc3339_and_iso8601_text_parses() { + assert_eq!(parse_datetime_str("2026-01-01T09:30:00Z"), Some(INSTANT_MS)); + assert_eq!(parse_datetime_str("2026-01-01T19:30:00+10:00"), Some(INSTANT_MS)); + assert_eq!(parse_datetime_str("2026-01-01T09:30:00.123Z"), Some(INSTANT_MS + 123)); + } + + #[test] + fn test_date_time_text_without_time_zone_parses_as_utc() { + assert_eq!(parse_datetime_str("2026-01-01 09:30:00"), Some(INSTANT_MS)); + } + + #[test] + fn test_date_text_parses_as_midnight_utc() { + assert_eq!(parse_datetime_str("2026-01-01"), Some(MIDNIGHT_MS)); + } + + #[test] + fn test_time_text_parses_as_that_time_today() { + let parsed = parse_datetime_str("09:30:00").expect("the time text parses"); + assert_eq!(parsed.rem_euclid(86_400_000), 34_200_000); + } + + #[test] + fn test_integer_text_parses_as_milliseconds() { + assert_eq!(parse_datetime_str("1767259800000"), Some(INSTANT_MS)); + assert_eq!(parse_datetime_str(""), None); + assert_eq!(parse_datetime_str("not a date"), None); + } +} From 90c92794187f36a1fcda7da788e652bbc891355f Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 20 Nov 2026 04:12:47 +0000 Subject: [PATCH 08/13] Add the time_zones feature for time zone conversion through the IANA Time Zone Database --- Cargo.toml | 17 ++++++-- README.md | 1 + src/structs/variants/datetime/mod.rs | 1 + src/structs/variants/datetime/tz.rs | 8 ++-- src/traits/print.rs | 62 ++++++++++++++++++++-------- 5 files changed, 63 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b0c70fc..6a484dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,8 @@ polars-core = { version = "0.55.2", default-features = false, features = [ ], optional = true } polars-arrow = { version = "0.55.2", optional = true } time = { version = "0.3", optional = true, features = ["parsing"] } -# IANA Time Zone Database as static data, for the UTC offset of each time zone at an instant. +# IANA Time Zone Database as static data, for the `time_zones` feature. +# Adds about 400 KB to the binary. tzdb_data = { version = "0.2.5", optional = true } num-traits = "0.2.19" rayon = { version = "1.11.0", optional = true } @@ -207,13 +208,23 @@ simd = [] # - Date/time arithmetic (add/subtract durations, dates) # - Comparison operations # - Component extraction (year, month, day, hour, etc.) -# - Time zone offsets from the IANA Time Zone Database, including daylight saving # At, the expense of an external dependency. # # Without this feature, datetime values are raw integer offsets. # The `ArrowType` stored in `Field` and/or `FieldArray` specifies the # logical type (Date32, Date64, Timestamp, etc.) for Arrow FFI compatibility. -datetime_ops = ["dep:time", "dep:tzdb_data", "datetime"] +datetime_ops = ["dep:time", "datetime"] + +# Adds time zone conversion for timestamps with a time zone: +# - Wall times and UTC offsets for IANA identifiers such as `Australia/Sydney`, +# including daylight saving and historical transitions +# - Fixed offsets for abbreviations such as `AEST`, and for offsets such as `+10:00` +# +# The IANA Time Zone Database is compiled into the binary as static data, +# which adds about 400 KB to the binary. +# +# Without this feature, timestamps with a time zone are printed in UTC. +time_zones = ["datetime_ops", "dep:tzdb_data"] # Adds string arithmetic kernels # Includes (small) external dependencies, and supports diff --git a/README.md b/README.md index 3e25c85..669cc09 100644 --- a/README.md +++ b/README.md @@ -260,6 +260,7 @@ Additional types: |---------|-------------| | `datetime` | Temporal array types as raw integer offsets | | `datetime_ops` | Datetime library functionality: ISO 8601 parsing, timezone-aware operations, arithmetic, component extraction | +| `time_zones` | Time zone conversion through the IANA Time Zone Database, including daylight saving and historical transitions. Adds about 400 KB to the binary. Without it, timestamps with a time zone are printed in UTC | | `extended_numeric_types` | i8, i16, u8, u16 variants | | `default_categorical_8` | 8-bit default categorical width, with Categorical8 and Categorical32 both available | | `extended_categorical` | Adds Categorical16 and Categorical64 dictionary index widths | diff --git a/src/structs/variants/datetime/mod.rs b/src/structs/variants/datetime/mod.rs index a17a615..70f567f 100644 --- a/src/structs/variants/datetime/mod.rs +++ b/src/structs/variants/datetime/mod.rs @@ -77,6 +77,7 @@ use ::vec64::{Vec64, Vec64Alloc}; pub mod datetime_ops; pub mod parse; +#[cfg(feature = "time_zones")] pub mod tz; /// Julian Day Number corresponding to the Unix epoch (1970-01-01 00:00:00 UTC). diff --git a/src/structs/variants/datetime/tz.rs b/src/structs/variants/datetime/tz.rs index 4f3cd25..1c9ef33 100644 --- a/src/structs/variants/datetime/tz.rs +++ b/src/structs/variants/datetime/tz.rs @@ -26,6 +26,9 @@ //! Standard Time, China Standard Time and Cuba Standard Time. The most common //! reading is used. Consider IANA identifiers or offsets such as `+10:00` //! where an exact reading is required. +//! +//! This module is part of the `time_zones` feature, which compiles the IANA +//! Time Zone Database into the binary and adds about 400 KB to it. /// Returns the fixed UTC offset of a time zone abbreviation in `±HH:MM` form. /// @@ -33,16 +36,12 @@ /// /// # Example /// ``` -/// # #[cfg(feature = "datetime_ops")] -/// # { /// use minarrow::structs::variants::datetime::tz::abbreviation_offset; /// /// assert_eq!(abbreviation_offset("AEST"), Some("+10:00")); /// assert_eq!(abbreviation_offset("AEDT"), Some("+11:00")); /// assert_eq!(abbreviation_offset("Australia/Sydney"), None); -/// # } /// ``` -#[cfg(feature = "datetime_ops")] pub fn abbreviation_offset(abbreviation: &str) -> Option<&'static str> { let offset = match abbreviation { // Common Standard Time Zones @@ -109,7 +108,6 @@ pub fn abbreviation_offset(abbreviation: &str) -> Option<&'static str> { Some(offset) } -#[cfg(all(feature = "datetime", feature = "datetime_ops"))] #[cfg(test)] mod tests { use super::*; diff --git a/src/traits/print.rs b/src/traits/print.rs index 8162636..06c6f43 100644 --- a/src/traits/print.rs +++ b/src/traits/print.rs @@ -300,6 +300,14 @@ pub(crate) fn print_ndarray_body( /// - `Timestamp` prints as `YYYY-MM-DD HH:MM:SS`, followed by the fraction /// digits of its time unit: 3 for milliseconds, 6 for microseconds and 9 for /// nanoseconds. The values of an array therefore print at one width. +/// - Timestamps with a time zone print the UTC value with its offset, as in +/// `2026-01-01 09:30:00+00:00`. +/// - `Time32` and `Time64` print the time of day as `HH:MM:SS`, with the +/// fraction digits of their time unit. +/// - `Duration32` and `Duration64` print the stored count with its time unit +/// suffix, as in `90s`. +/// +/// With `time_zones`, which adds about 400 KB to the binary: /// - Timestamps with a time zone print the wall time of that time zone and /// its UTC offset at that instant, as in `2026-01-01 14:30:00+05:00`. Time /// zone text other than an offset follows the value, as in @@ -311,10 +319,6 @@ pub(crate) fn print_ndarray_body( /// print as `+HH:MM:SS`. /// - Time zone text that is not an offset, an abbreviation or an IANA /// identifier prints the UTC value with `+00:00` and without that text. -/// - `Time32` and `Time64` print the time of day as `HH:MM:SS`, with the -/// fraction digits of their time unit. -/// - `Duration32` and `Duration64` print the stored count with its time unit -/// suffix, as in `90s`. /// /// Without `datetime_ops`, and for dates and timestamps outside the `time` /// crate's date range, the stored integer prints with its time unit suffix. @@ -372,7 +376,11 @@ where } Dt::Timestamp(_, Some(tz)) => { let utc_dt = DatetimeArray::::i64_to_datetime(value, unit); + #[cfg(feature = "time_zones")] let offset = utc_dt.and_then(|dt| timezone_offset(tz, dt.unix_timestamp())); + // Time zone conversion is part of the `time_zones` feature. + #[cfg(not(feature = "time_zones"))] + let offset: Option = None; let local_dt = utc_dt.and_then(|dt| dt.checked_to_offset(offset.unwrap_or(UtcOffset::UTC))); if let Some(local_dt) = local_dt { @@ -442,7 +450,7 @@ where /// - `UTC`, `Z` and offsets such as `+05:00` and `+0530` return that offset. /// /// Returns `None` for any other text. -#[cfg(all(feature = "datetime", feature = "datetime_ops"))] +#[cfg(feature = "time_zones")] fn timezone_offset(tz: &str, unix_seconds: i64) -> Option { use crate::structs::variants::datetime::tz::abbreviation_offset; use time::UtcOffset; @@ -673,7 +681,7 @@ mod tests { ); } - #[cfg(feature = "datetime_ops")] + #[cfg(feature = "time_zones")] #[test] fn test_timestamp_with_offset_prints_local_time_and_offset() { use crate::{Dt, TimeUnit}; @@ -693,7 +701,7 @@ mod tests { assert_datetime_text(arr, &["2026-01-01 01:30:00-08:00"]); } - #[cfg(feature = "datetime_ops")] + #[cfg(feature = "time_zones")] #[test] fn test_timestamp_with_named_zone_prints_local_time_offset_and_zone() { use crate::{Dt, TimeUnit}; @@ -716,6 +724,24 @@ mod tests { assert_datetime_text(arr, &["2026-01-01 09:30:00+00:00"]); } + #[cfg(all(feature = "datetime_ops", not(feature = "time_zones")))] + #[test] + fn test_timestamp_with_time_zone_prints_utc_value_without_time_zones() { + use crate::{Dt, TimeUnit}; + for tz in ["+05:00", "AEST", "Asia/Tokyo", "Australia/Sydney", "UTC"] { + let arr = timestamp_array( + &[Some(1_767_259_800), None], + Dt::Timestamp(TimeUnit::Seconds, Some(tz.into())), + ); + assert_datetime_text(arr, &["2026-01-01 09:30:00+00:00", "null"]); + } + let arr = timestamp_array( + &[Some(1_767_259_800_250_000)], + Dt::Timestamp(TimeUnit::Microseconds, Some("Australia/Sydney".into())), + ); + assert_datetime_text(arr, &["2026-01-01 09:30:00.250000+00:00"]); + } + #[cfg(feature = "datetime_ops")] #[test] fn test_timestamp_with_unresolved_zone_prints_utc_value_with_utc_offset() { @@ -734,7 +760,7 @@ mod tests { // Zone Database. It covers daylight saving in both hemispheres, the seconds // either side of a transition, historical rules, offsets of 30 and 45 // minutes, and local mean time offsets with seconds. - #[cfg(feature = "datetime_ops")] + #[cfg(feature = "time_zones")] #[test] fn test_timestamp_with_iana_zone_prints_wall_time_and_offset_of_the_instant() { use crate::{Dt, TimeUnit}; @@ -766,7 +792,7 @@ mod tests { } } - #[cfg(feature = "datetime_ops")] + #[cfg(feature = "time_zones")] #[test] fn test_timestamp_with_iana_zone_prints_fraction_digits_of_its_unit() { use crate::{Dt, TimeUnit}; @@ -784,12 +810,12 @@ mod tests { } // 1 January 2026 and 1 July 2026 at 09:30:00 UTC. - #[cfg(feature = "datetime_ops")] + #[cfg(feature = "time_zones")] const JANUARY: i64 = 1_767_259_800; - #[cfg(feature = "datetime_ops")] + #[cfg(feature = "time_zones")] const JULY: i64 = 1_782_898_200; - #[cfg(feature = "datetime_ops")] + #[cfg(feature = "time_zones")] fn offset_text(tz: &str, unix_seconds: i64) -> Option { timezone_offset(tz, unix_seconds).map(|offset| { let seconds = offset.whole_seconds(); @@ -798,7 +824,7 @@ mod tests { }) } - #[cfg(feature = "datetime_ops")] + #[cfg(feature = "time_zones")] #[test] fn test_timezone_offset_of_iana_identifiers() { assert_eq!(offset_text("Australia/Sydney", JULY).as_deref(), Some("+10:00")); @@ -812,7 +838,7 @@ mod tests { assert_eq!(offset_text("Pacific/Auckland", JANUARY).as_deref(), Some("+13:00")); } - #[cfg(feature = "datetime_ops")] + #[cfg(feature = "time_zones")] #[test] fn test_timezone_offset_of_abbreviations() { for (abbreviation, offset) in [ @@ -829,7 +855,7 @@ mod tests { } } - #[cfg(feature = "datetime_ops")] + #[cfg(feature = "time_zones")] #[test] fn test_timezone_offset_of_direct_offsets() { for offset in ["+10:00", "-05:00", "+00:00", "+05:30", "-03:30"] { @@ -839,7 +865,7 @@ mod tests { assert_eq!(offset_text("Z", JANUARY).as_deref(), Some("+00:00")); } - #[cfg(feature = "datetime_ops")] + #[cfg(feature = "time_zones")] #[test] fn test_timezone_offset_of_invalid_text() { assert_eq!(offset_text("Invalid/Timezone", JANUARY), None); @@ -847,7 +873,7 @@ mod tests { assert_eq!(offset_text("25:00", JANUARY), None); } - #[cfg(feature = "datetime_ops")] + #[cfg(feature = "time_zones")] #[test] fn test_timezone_offset_of_unusual_offsets() { assert_eq!(offset_text("Australia/Eucla", JANUARY).as_deref(), Some("+08:45")); @@ -859,7 +885,7 @@ mod tests { assert_eq!(offset_text("Pacific/Chatham", JANUARY).as_deref(), Some("+13:45")); } - #[cfg(feature = "datetime_ops")] + #[cfg(feature = "time_zones")] #[test] fn test_every_iana_identifier_has_an_offset() { for name in tzdb_data::TZ_NAMES { From d915e1bbe29883681f83c56239b202c32aab0ead Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 20 Nov 2026 05:11:55 +0000 Subject: [PATCH 09/13] Read the wall time of the time zone in datetime operations --- Cargo.toml | 8 +- README.md | 2 +- src/kernels/datetime.rs | 41 +- src/structs/variants/datetime/datetime_ops.rs | 1179 ++++++++++++++++- src/structs/variants/datetime/tz.rs | 147 ++ .../views/collections/temporal_array_view.rs | 11 +- src/traits/print.rs | 57 +- 7 files changed, 1374 insertions(+), 71 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6a484dc..47425f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -219,11 +219,13 @@ datetime_ops = ["dep:time", "datetime"] # - Wall times and UTC offsets for IANA identifiers such as `Australia/Sydney`, # including daylight saving and historical transitions # - Fixed offsets for abbreviations such as `AEST`, and for offsets such as `+10:00` +# - Display, component extraction, truncation and month arithmetic on the wall time +# of the time zone # -# The IANA Time Zone Database is compiled into the binary as static data, -# which adds about 400 KB to the binary. +# Stored values stay UTC integers. The IANA Time Zone Database is compiled into the +# binary as static data, which adds about 400 KB to the binary. # -# Without this feature, timestamps with a time zone are printed in UTC. +# Without this feature, timestamps with a time zone are printed and computed in UTC. time_zones = ["datetime_ops", "dep:tzdb_data"] # Adds string arithmetic kernels diff --git a/README.md b/README.md index 669cc09..25a8ace 100644 --- a/README.md +++ b/README.md @@ -260,7 +260,7 @@ Additional types: |---------|-------------| | `datetime` | Temporal array types as raw integer offsets | | `datetime_ops` | Datetime library functionality: ISO 8601 parsing, timezone-aware operations, arithmetic, component extraction | -| `time_zones` | Time zone conversion through the IANA Time Zone Database, including daylight saving and historical transitions. Adds about 400 KB to the binary. Without it, timestamps with a time zone are printed in UTC | +| `time_zones` | Time zone conversion through the IANA Time Zone Database, including daylight saving and historical transitions. Display, component extraction, truncation and month arithmetic use the wall time of the time zone, and stored values stay UTC. Adds about 400 KB to the binary. Without it, timestamps with a time zone are printed and computed in UTC | | `extended_numeric_types` | i8, i16, u8, u16 variants | | `default_categorical_8` | 8-bit default categorical width, with Categorical8 and Categorical32 both available | | `extended_categorical` | Adds Categorical16 and Categorical64 dictionary index widths | diff --git a/src/kernels/datetime.rs b/src/kernels/datetime.rs index d4cf96f..bfe38f7 100644 --- a/src/kernels/datetime.rs +++ b/src/kernels/datetime.rs @@ -50,6 +50,10 @@ use crate::{Bitmask, DatetimeArray}; /// Handles the full calendar range (`Year` through `Second`, plus `Week`) and the /// sub-second steps (`Millisecond`, `Microsecond`). Sub-second steps are no-ops on /// arrays whose stored resolution is already at or coarser than the target. +/// +/// With the `time_zones` feature, calendar periods of timestamps with a time zone are +/// floored on the wall time of that time zone, and `out` receives the UTC value of the +/// start of the period. pub fn truncate_into( src: &DatetimeArray, src_offset: usize, @@ -59,6 +63,8 @@ pub fn truncate_into( ) { let time_unit = src.time_unit(); let len = out.len(); + let wall_time_offset = src.wall_time_offset(); + let wall_time_values = src.wall_time_values(); // Resolve the unit scaling and sub-second divisor once for the whole window. // `None` for `per_second` identifies the `Days` unit. A divisor of 1 leaves @@ -89,7 +95,23 @@ pub fn truncate_into( .to_i64() .and_then(|v| match sub_second_divisor { Some(divisor) => v.div_euclid(divisor).checked_mul(divisor), - None => floor_calendar(v, period, per_second), + // Calendar periods are floored on the wall time of the array's + // time zone, and written as the UTC value of that wall time. + None => { + let offset = wall_time_offset(v); + v.checked_add(offset) + .and_then(|wall| floor_calendar(wall, period, per_second)) + .and_then(|floored| { + // The offset of the input is in force at the start of + // the period unless a transition lies between them. + let value = floored.checked_sub(offset)?; + if wall_time_offset(value) == offset { + Some(value) + } else { + Some(wall_time_values(floored).0) + } + }) + } }) .and_then(T::from_i64) { @@ -285,6 +307,9 @@ pub fn add_duration_into( /// A day that does not exist in the destination month is clamped to that month's last /// day, and time-of-day is preserved. A value whose result is not a valid datetime is /// marked null in `out_mask`. +/// +/// With the `time_zones` feature, the months of timestamps with a time zone are added +/// on the wall time of that time zone, and `out` receives the UTC value of the result. pub fn add_months_into( src: &DatetimeArray, src_offset: usize, @@ -293,14 +318,18 @@ pub fn add_months_into( mut out_mask: Option<&mut Bitmask>, ) { let time_unit = src.time_unit(); + let wall_time_offset = src.wall_time_offset(); + let wall_time_values = src.wall_time_values(); for i in 0..out.len() { let original = src.data[src_offset + i]; out[i] = original; let computed = if src.is_null(src_offset + i) { None } else { + // The months are added on the wall time of the array's time zone. original .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) .and_then(|v| DatetimeArray::::i64_to_datetime(v, time_unit)) .and_then(|dt| { let date = dt.date(); @@ -313,7 +342,8 @@ pub fn add_months_into( let new_date = time::Date::from_calendar_date(new_year, new_month_enum, day).ok()?; let new_dt = new_date.with_time(dt.time()).assume_utc(); - T::from_i64(DatetimeArray::::datetime_to_i64(new_dt, time_unit)) + let wall = DatetimeArray::::datetime_to_i64(new_dt, time_unit); + T::from_i64(wall_time_values(wall).1) }) }; let valid = match computed { @@ -333,6 +363,9 @@ pub fn add_months_into( /// `[src_offset, src_offset + out.len())`, writing into `out`. A null input or a /// value that is not a representable datetime writes `0` and clears its `out_mask` /// bit. The allocating extract methods on `DatetimeArray` pass `src_offset = 0`. +/// +/// With the `time_zones` feature, fields of timestamps with a time zone are those of +/// the wall time of that time zone. fn extract_i32_into( src: &DatetimeArray, src_offset: usize, @@ -344,12 +377,14 @@ fn extract_i32_into( F: Fn(time::OffsetDateTime) -> i32, { let time_unit = src.time_unit(); + let wall_time_offset = src.wall_time_offset(); for i in 0..out.len() { let dt = if src.is_null(src_offset + i) { None } else { src.data[src_offset + i] .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) .and_then(|v| DatetimeArray::::i64_to_datetime(v, time_unit)) }; let valid = match dt { @@ -456,9 +491,11 @@ pub fn extract_bool_into( F: Fn(time::OffsetDateTime) -> bool, { let time_unit = src.time_unit(); + let wall_time_offset = src.wall_time_offset(); for i in 0..out_bits.len() { match src.data[src_offset + i] .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) .and_then(|v| DatetimeArray::::i64_to_datetime(v, time_unit)) { // SAFETY: `i < out_bits.len()`, so the bit index is within the bitmask's diff --git a/src/structs/variants/datetime/datetime_ops.rs b/src/structs/variants/datetime/datetime_ops.rs index e8e6064..a2a61b4 100644 --- a/src/structs/variants/datetime/datetime_ops.rs +++ b/src/structs/variants/datetime/datetime_ops.rs @@ -35,6 +35,26 @@ //! For timezone operations, use `FieldArray::with_timezone()` and `FieldArray::to_utc()` which //! update metadata without modifying the underlying UTC data. //! +//! With the `time_zones` feature, operations on timestamps with a time zone read the +//! wall time of that time zone. The stored values stay UTC integers. Each operation +//! adds the UTC offset of the time zone at that instant to the stored value, runs the +//! same calendar arithmetic as for UTC values, and writes results that are timestamps +//! back as UTC values. +//! - Component extraction, such as `hour` and `day`, returns the components of the wall time. +//! - Truncation floors the wall time and writes the UTC value of the start of the period. +//! The offset in force at the input is used where it is in force at the start of the +//! period. Otherwise the result is the first instant at which the wall clock reads the +//! start of the period or later. +//! - `add_months` and `add_years` keep the wall time. Wall times that occur twice use the +//! earlier instant, and skipped wall times use the offset in force before the transition. +//! - `add_duration`, `sub_duration`, `add_days`, `diff`, the comparisons and +//! `cast_time_unit` operate on instants, and return the same values with or without a +//! time zone. `add_days` adds days of 24 hours. +//! +//! Offsets come from the IANA Time Zone Database, including daylight saving and historical +//! transitions. Without `time_zones`, every operation reads the UTC value, and timestamps +//! with a time zone print in UTC. +//! //! ## Result types //! The arithmetic and truncation operations return arrays of the input's `Dt`. //! `cast_time_unit` keeps the type's variant and timezone, and changes its unit. @@ -60,6 +80,8 @@ use crate::{ structs::variants::{boolean::BooleanArray, integer::IntegerArray}, traits::{masked_array::MaskedArray, type_unions::Integer}, }; +#[cfg(feature = "time_zones")] +use crate::structs::variants::datetime::tz::{utc_offset_seconds, wall_time_instants}; #[cfg(feature = "datetime_ops")] use ::vec64::Vec64; #[cfg(feature = "datetime_ops")] @@ -92,6 +114,93 @@ impl DatetimeArray { } } + /// Returns the UTC offset of each stored value, in the array's time unit, as + /// a function of the stored value. + /// + /// Stored values are UTC. A stored value plus its offset is the wall time of + /// the array's time zone in the same unit, and the calendar arithmetic of the + /// kernels reads that sum as it reads a UTC value. + /// + /// The offset is 0 for arrays without a time zone, for time zone text that + /// `utc_offset_seconds` does not resolve, and without the `time_zones` feature. + pub(crate) fn wall_time_offset(&self) -> impl Fn(i64) -> i64 { + #[cfg(feature = "time_zones")] + { + let zone = match &self.dtype { + Dt::Timestamp(unit, Some(tz)) => { + utc_offset_seconds(tz).zip(Self::values_per_second(*unit)) + } + _ => None, + }; + move |value: i64| match &zone { + Some((offset_seconds, per_second)) => { + offset_seconds(value.div_euclid(*per_second)).saturating_mul(*per_second) + } + None => 0, + } + } + #[cfg(not(feature = "time_zones"))] + { + |_value: i64| 0 + } + } + + /// Returns the stored UTC values for a wall time of the array's time zone, as + /// a function of the wall time in the array's time unit. + /// + /// The two values are those of `wall_time_instants`. The first is the first + /// stored value at which the wall clock reads the wall time or later, which + /// truncation writes for period starts on the other side of a transition from + /// their input. The second reads skipped wall times with the offset in force + /// before the transition, which calendar arithmetic writes. + /// + /// Both values are the wall time itself for arrays without a time zone, for + /// time zone text that `utc_offset_seconds` does not resolve, and without the + /// `time_zones` feature. + pub(crate) fn wall_time_values(&self) -> impl Fn(i64) -> (i64, i64) { + #[cfg(feature = "time_zones")] + { + let zone = match &self.dtype { + Dt::Timestamp(unit, Some(tz)) => { + utc_offset_seconds(tz).zip(Self::values_per_second(*unit)) + } + _ => None, + }; + move |wall: i64| match &zone { + Some((offset_seconds, per_second)) => { + let fraction = wall.rem_euclid(*per_second); + let (first, second) = + wall_time_instants(offset_seconds, wall.div_euclid(*per_second)); + let second_value = second.saturating_mul(*per_second).saturating_add(fraction); + // The instant of a transition is a whole second. + if first == second { + (second_value, second_value) + } else { + (first.saturating_mul(*per_second), second_value) + } + } + None => (wall, wall), + } + } + #[cfg(not(feature = "time_zones"))] + { + |wall: i64| (wall, wall) + } + } + + /// Returns the number of stored values per second for `unit`, or `None` for + /// the `Days` unit, which is not a unit of timestamps with a time zone. + #[cfg(feature = "time_zones")] + fn values_per_second(unit: TimeUnit) -> Option { + match unit { + TimeUnit::Seconds => Some(1), + TimeUnit::Milliseconds => Some(1_000), + TimeUnit::Microseconds => Some(1_000_000), + TimeUnit::Nanoseconds => Some(1_000_000_000), + TimeUnit::Days => None, + } + } + /// Convert OffsetDateTime back to i64 value based on time unit. #[inline(always)] pub(crate) fn datetime_to_i64(dt: time::OffsetDateTime, time_unit: TimeUnit) -> i64 { @@ -340,11 +449,16 @@ impl DatetimeOps for DatetimeArray { /// Extracts the year component from all datetime values. fn year(&self) -> IntegerArray { let mut result = IntegerArray::with_capacity(self.len(), self.is_nullable()); + let wall_time_offset = self.wall_time_offset(); for i in 0..self.len() { if self.is_null(i) { result.push_null(); - } else if let Some(dt) = self.value_to_datetime(i) { + } else if let Some(dt) = self.data[i] + .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) + .and_then(|v| Self::i64_to_datetime(v, self.time_unit())) + { result.push(dt.year()); } else { result.push_null(); @@ -357,11 +471,16 @@ impl DatetimeOps for DatetimeArray { /// Extracts the month component (1-12) from all datetime values. fn month(&self) -> IntegerArray { let mut result = IntegerArray::with_capacity(self.len(), self.is_nullable()); + let wall_time_offset = self.wall_time_offset(); for i in 0..self.len() { if self.is_null(i) { result.push_null(); - } else if let Some(dt) = self.value_to_datetime(i) { + } else if let Some(dt) = self.data[i] + .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) + .and_then(|v| Self::i64_to_datetime(v, self.time_unit())) + { result.push(dt.month() as i32); } else { result.push_null(); @@ -374,11 +493,16 @@ impl DatetimeOps for DatetimeArray { /// Extracts the day of month (1-31) from all datetime values. fn day(&self) -> IntegerArray { let mut result = IntegerArray::with_capacity(self.len(), self.is_nullable()); + let wall_time_offset = self.wall_time_offset(); for i in 0..self.len() { if self.is_null(i) { result.push_null(); - } else if let Some(dt) = self.value_to_datetime(i) { + } else if let Some(dt) = self.data[i] + .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) + .and_then(|v| Self::i64_to_datetime(v, self.time_unit())) + { result.push(dt.day() as i32); } else { result.push_null(); @@ -391,11 +515,16 @@ impl DatetimeOps for DatetimeArray { /// Extracts the hour component (0-23) from all datetime values. fn hour(&self) -> IntegerArray { let mut result = IntegerArray::with_capacity(self.len(), self.is_nullable()); + let wall_time_offset = self.wall_time_offset(); for i in 0..self.len() { if self.is_null(i) { result.push_null(); - } else if let Some(dt) = self.value_to_datetime(i) { + } else if let Some(dt) = self.data[i] + .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) + .and_then(|v| Self::i64_to_datetime(v, self.time_unit())) + { result.push(dt.hour() as i32); } else { result.push_null(); @@ -408,11 +537,16 @@ impl DatetimeOps for DatetimeArray { /// Extracts the minute component (0-59) from all datetime values. fn minute(&self) -> IntegerArray { let mut result = IntegerArray::with_capacity(self.len(), self.is_nullable()); + let wall_time_offset = self.wall_time_offset(); for i in 0..self.len() { if self.is_null(i) { result.push_null(); - } else if let Some(dt) = self.value_to_datetime(i) { + } else if let Some(dt) = self.data[i] + .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) + .and_then(|v| Self::i64_to_datetime(v, self.time_unit())) + { result.push(dt.minute() as i32); } else { result.push_null(); @@ -425,11 +559,16 @@ impl DatetimeOps for DatetimeArray { /// Extracts the second component (0-59) from all datetime values. fn second(&self) -> IntegerArray { let mut result = IntegerArray::with_capacity(self.len(), self.is_nullable()); + let wall_time_offset = self.wall_time_offset(); for i in 0..self.len() { if self.is_null(i) { result.push_null(); - } else if let Some(dt) = self.value_to_datetime(i) { + } else if let Some(dt) = self.data[i] + .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) + .and_then(|v| Self::i64_to_datetime(v, self.time_unit())) + { result.push(dt.second() as i32); } else { result.push_null(); @@ -442,11 +581,16 @@ impl DatetimeOps for DatetimeArray { /// Extracts the weekday (1=Sunday, 2=Monday, ..., 7=Saturday) from all datetime values. fn weekday(&self) -> IntegerArray { let mut result = IntegerArray::with_capacity(self.len(), self.is_nullable()); + let wall_time_offset = self.wall_time_offset(); for i in 0..self.len() { if self.is_null(i) { result.push_null(); - } else if let Some(dt) = self.value_to_datetime(i) { + } else if let Some(dt) = self.data[i] + .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) + .and_then(|v| Self::i64_to_datetime(v, self.time_unit())) + { result.push(dt.weekday().number_from_sunday() as i32); } else { result.push_null(); @@ -459,11 +603,16 @@ impl DatetimeOps for DatetimeArray { /// Extracts the day of year (1-366) from all datetime values. fn day_of_year(&self) -> IntegerArray { let mut result = IntegerArray::with_capacity(self.len(), self.is_nullable()); + let wall_time_offset = self.wall_time_offset(); for i in 0..self.len() { if self.is_null(i) { result.push_null(); - } else if let Some(dt) = self.value_to_datetime(i) { + } else if let Some(dt) = self.data[i] + .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) + .and_then(|v| Self::i64_to_datetime(v, self.time_unit())) + { result.push(dt.ordinal() as i32); } else { result.push_null(); @@ -476,11 +625,16 @@ impl DatetimeOps for DatetimeArray { /// Extracts the ISO week number (1-53) from all datetime values. fn iso_week(&self) -> IntegerArray { let mut result = IntegerArray::with_capacity(self.len(), self.is_nullable()); + let wall_time_offset = self.wall_time_offset(); for i in 0..self.len() { if self.is_null(i) { result.push_null(); - } else if let Some(dt) = self.value_to_datetime(i) { + } else if let Some(dt) = self.data[i] + .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) + .and_then(|v| Self::i64_to_datetime(v, self.time_unit())) + { result.push(dt.iso_week() as i32); } else { result.push_null(); @@ -493,11 +647,16 @@ impl DatetimeOps for DatetimeArray { /// Extracts the quarter (1-4) from all datetime values. fn quarter(&self) -> IntegerArray { let mut result = IntegerArray::with_capacity(self.len(), self.is_nullable()); + let wall_time_offset = self.wall_time_offset(); for i in 0..self.len() { if self.is_null(i) { result.push_null(); - } else if let Some(dt) = self.value_to_datetime(i) { + } else if let Some(dt) = self.data[i] + .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) + .and_then(|v| Self::i64_to_datetime(v, self.time_unit())) + { let month = dt.month() as i32; let quarter = ((month - 1) / 3) + 1; result.push(quarter); @@ -513,11 +672,16 @@ impl DatetimeOps for DatetimeArray { /// Week 0 contains days before the first Sunday. fn week_of_year(&self) -> IntegerArray { let mut result = IntegerArray::with_capacity(self.len(), self.is_nullable()); + let wall_time_offset = self.wall_time_offset(); for i in 0..self.len() { if self.is_null(i) { result.push_null(); - } else if let Some(dt) = self.value_to_datetime(i) { + } else if let Some(dt) = self.data[i] + .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) + .and_then(|v| Self::i64_to_datetime(v, self.time_unit())) + { let day_of_year = dt.ordinal() as i32; let weekday = dt.weekday().number_from_sunday() as i32; // Calculate week based on day of year and weekday (Sunday = 1) @@ -1640,3 +1804,996 @@ mod tests { assert!(date32.cast_time_unit(TimeUnit::Seconds).is_err()); } } + +#[cfg(all(test, feature = "time_zones"))] +mod time_zone_tests { + use std::sync::Arc; + + use super::*; + use crate::kernels::datetime::{hour_into, minute_into}; + use crate::{Array, TemporalArray, TemporalArrayV}; + + // The tables are from Python's `zoneinfo`, which reads the IANA Time Zone + // Database. They cover daylight saving in both hemispheres, offsets of 30 and + // 45 minutes, daylight saving of 30 minutes, transitions at midnight, the + // seconds either side of each transition of 2026, and historical rules. + // + // Truncation floors the wall time and reads it with the offset in force at + // the input. Where that offset is not in force at the start of the period, + // the result is the first instant at which the wall clock reads the start of + // the period or later. Month arithmetic keeps the wall time: wall times that + // occur twice use the earlier instant, and skipped wall times use the offset + // in force before the transition. + + /// Time zone, instant in seconds, then year, month, day, hour, minute, second, + /// weekday from 1 for Sunday, day of year, ISO week, quarter, week of year, and + /// whether the year is a leap year. + const COMPONENTS: &[(&str, i64, [i32; 11], bool)] = &[ + ("Australia/Sydney", 1767259800, [2026, 1, 1, 20, 30, 0, 5, 1, 1, 1, 0], false), + ("Australia/Sydney", 1767277800, [2026, 1, 2, 1, 30, 0, 6, 2, 1, 1, 0], false), + ("Australia/Sydney", 1775313000, [2026, 4, 5, 1, 30, 0, 1, 95, 14, 2, 14], false), + ("Australia/Sydney", 1775318399, [2026, 4, 5, 2, 59, 59, 1, 95, 14, 2, 14], false), + ("Australia/Sydney", 1775318400, [2026, 4, 5, 2, 0, 0, 1, 95, 14, 2, 14], false), + ("Australia/Sydney", 1775320200, [2026, 4, 5, 2, 30, 0, 1, 95, 14, 2, 14], false), + ("Australia/Sydney", 1775323800, [2026, 4, 5, 3, 30, 0, 1, 95, 14, 2, 14], false), + ("Australia/Sydney", 1782898200, [2026, 7, 1, 19, 30, 0, 4, 182, 27, 3, 26], false), + ("Australia/Sydney", 1791037800, [2026, 10, 4, 0, 30, 0, 1, 277, 40, 4, 40], false), + ("Australia/Sydney", 1791043199, [2026, 10, 4, 1, 59, 59, 1, 277, 40, 4, 40], false), + ("Australia/Sydney", 1791043200, [2026, 10, 4, 3, 0, 0, 1, 277, 40, 4, 40], false), + ("Australia/Sydney", 1791045000, [2026, 10, 4, 3, 30, 0, 1, 277, 40, 4, 40], false), + ("Australia/Sydney", 1791048600, [2026, 10, 4, 4, 30, 0, 1, 277, 40, 4, 40], false), + ("America/New_York", 1142856000, [2006, 3, 20, 7, 0, 0, 2, 79, 12, 1, 12], false), + ("America/New_York", 1767259800, [2026, 1, 1, 4, 30, 0, 5, 1, 1, 1, 0], false), + ("America/New_York", 1767277800, [2026, 1, 1, 9, 30, 0, 5, 1, 1, 1, 0], false), + ("America/New_York", 1772947800, [2026, 3, 8, 0, 30, 0, 1, 67, 10, 1, 10], false), + ("America/New_York", 1772953199, [2026, 3, 8, 1, 59, 59, 1, 67, 10, 1, 10], false), + ("America/New_York", 1772953200, [2026, 3, 8, 3, 0, 0, 1, 67, 10, 1, 10], false), + ("America/New_York", 1772955000, [2026, 3, 8, 3, 30, 0, 1, 67, 10, 1, 10], false), + ("America/New_York", 1772958600, [2026, 3, 8, 4, 30, 0, 1, 67, 10, 1, 10], false), + ("America/New_York", 1782898200, [2026, 7, 1, 5, 30, 0, 4, 182, 27, 3, 26], false), + ("America/New_York", 1793507400, [2026, 11, 1, 0, 30, 0, 1, 305, 44, 4, 44], false), + ("America/New_York", 1793512799, [2026, 11, 1, 1, 59, 59, 1, 305, 44, 4, 44], false), + ("America/New_York", 1793512800, [2026, 11, 1, 1, 0, 0, 1, 305, 44, 4, 44], false), + ("America/New_York", 1793514600, [2026, 11, 1, 1, 30, 0, 1, 305, 44, 4, 44], false), + ("America/New_York", 1793518200, [2026, 11, 1, 2, 30, 0, 1, 305, 44, 4, 44], false), + ("Europe/London", 0, [1970, 1, 1, 1, 0, 0, 5, 1, 1, 1, 0], false), + ("Europe/London", 1767259800, [2026, 1, 1, 9, 30, 0, 5, 1, 1, 1, 0], false), + ("Europe/London", 1767277800, [2026, 1, 1, 14, 30, 0, 5, 1, 1, 1, 0], false), + ("Europe/London", 1774740600, [2026, 3, 28, 23, 30, 0, 7, 87, 13, 1, 12], false), + ("Europe/London", 1774745999, [2026, 3, 29, 0, 59, 59, 1, 88, 13, 1, 13], false), + ("Europe/London", 1774746000, [2026, 3, 29, 2, 0, 0, 1, 88, 13, 1, 13], false), + ("Europe/London", 1774747800, [2026, 3, 29, 2, 30, 0, 1, 88, 13, 1, 13], false), + ("Europe/London", 1774751400, [2026, 3, 29, 3, 30, 0, 1, 88, 13, 1, 13], false), + ("Europe/London", 1782898200, [2026, 7, 1, 10, 30, 0, 4, 182, 27, 3, 26], false), + ("Europe/London", 1792884600, [2026, 10, 25, 0, 30, 0, 1, 298, 43, 4, 43], false), + ("Europe/London", 1792889999, [2026, 10, 25, 1, 59, 59, 1, 298, 43, 4, 43], false), + ("Europe/London", 1792890000, [2026, 10, 25, 1, 0, 0, 1, 298, 43, 4, 43], false), + ("Europe/London", 1792891800, [2026, 10, 25, 1, 30, 0, 1, 298, 43, 4, 43], false), + ("Europe/London", 1792895400, [2026, 10, 25, 2, 30, 0, 1, 298, 43, 4, 43], false), + ("Australia/Lord_Howe", 1767259800, [2026, 1, 1, 20, 30, 0, 5, 1, 1, 1, 0], false), + ("Australia/Lord_Howe", 1767277800, [2026, 1, 2, 1, 30, 0, 6, 2, 1, 1, 0], false), + ("Australia/Lord_Howe", 1775309400, [2026, 4, 5, 0, 30, 0, 1, 95, 14, 2, 14], false), + ("Australia/Lord_Howe", 1775314799, [2026, 4, 5, 1, 59, 59, 1, 95, 14, 2, 14], false), + ("Australia/Lord_Howe", 1775314800, [2026, 4, 5, 1, 30, 0, 1, 95, 14, 2, 14], false), + ("Australia/Lord_Howe", 1775316600, [2026, 4, 5, 2, 0, 0, 1, 95, 14, 2, 14], false), + ("Australia/Lord_Howe", 1775320200, [2026, 4, 5, 3, 0, 0, 1, 95, 14, 2, 14], false), + ("Australia/Lord_Howe", 1782898200, [2026, 7, 1, 20, 0, 0, 4, 182, 27, 3, 26], false), + ("Australia/Lord_Howe", 1791036000, [2026, 10, 4, 0, 30, 0, 1, 277, 40, 4, 40], false), + ("Australia/Lord_Howe", 1791041399, [2026, 10, 4, 1, 59, 59, 1, 277, 40, 4, 40], false), + ("Australia/Lord_Howe", 1791041400, [2026, 10, 4, 2, 30, 0, 1, 277, 40, 4, 40], false), + ("Australia/Lord_Howe", 1791043200, [2026, 10, 4, 3, 0, 0, 1, 277, 40, 4, 40], false), + ("Australia/Lord_Howe", 1791046800, [2026, 10, 4, 4, 0, 0, 1, 277, 40, 4, 40], false), + ("Asia/Kolkata", 1767259800, [2026, 1, 1, 15, 0, 0, 5, 1, 1, 1, 0], false), + ("Asia/Kolkata", 1767277800, [2026, 1, 1, 20, 0, 0, 5, 1, 1, 1, 0], false), + ("Asia/Kolkata", 1782898200, [2026, 7, 1, 15, 0, 0, 4, 182, 27, 3, 26], false), + ("Asia/Kathmandu", 1767259800, [2026, 1, 1, 15, 15, 0, 5, 1, 1, 1, 0], false), + ("Asia/Kathmandu", 1767277800, [2026, 1, 1, 20, 15, 0, 5, 1, 1, 1, 0], false), + ("Asia/Kathmandu", 1782898200, [2026, 7, 1, 15, 15, 0, 4, 182, 27, 3, 26], false), + ("America/Havana", 1767259800, [2026, 1, 1, 4, 30, 0, 5, 1, 1, 1, 0], false), + ("America/Havana", 1767277800, [2026, 1, 1, 9, 30, 0, 5, 1, 1, 1, 0], false), + ("America/Havana", 1772940600, [2026, 3, 7, 22, 30, 0, 7, 66, 10, 1, 9], false), + ("America/Havana", 1772945999, [2026, 3, 7, 23, 59, 59, 7, 66, 10, 1, 9], false), + ("America/Havana", 1772946000, [2026, 3, 8, 1, 0, 0, 1, 67, 10, 1, 10], false), + ("America/Havana", 1772947800, [2026, 3, 8, 1, 30, 0, 1, 67, 10, 1, 10], false), + ("America/Havana", 1772951400, [2026, 3, 8, 2, 30, 0, 1, 67, 10, 1, 10], false), + ("America/Havana", 1782898200, [2026, 7, 1, 5, 30, 0, 4, 182, 27, 3, 26], false), + ("America/Havana", 1793503800, [2026, 10, 31, 23, 30, 0, 7, 304, 44, 4, 43], false), + ("America/Havana", 1793509199, [2026, 11, 1, 0, 59, 59, 1, 305, 44, 4, 44], false), + ("America/Havana", 1793509200, [2026, 11, 1, 0, 0, 0, 1, 305, 44, 4, 44], false), + ("America/Havana", 1793511000, [2026, 11, 1, 0, 30, 0, 1, 305, 44, 4, 44], false), + ("America/Havana", 1793514600, [2026, 11, 1, 1, 30, 0, 1, 305, 44, 4, 44], false), + ("Asia/Beirut", 1767259800, [2026, 1, 1, 11, 30, 0, 5, 1, 1, 1, 0], false), + ("Asia/Beirut", 1767277800, [2026, 1, 1, 16, 30, 0, 5, 1, 1, 1, 0], false), + ("Asia/Beirut", 1774729800, [2026, 3, 28, 22, 30, 0, 7, 87, 13, 1, 12], false), + ("Asia/Beirut", 1774735199, [2026, 3, 28, 23, 59, 59, 7, 87, 13, 1, 12], false), + ("Asia/Beirut", 1774735200, [2026, 3, 29, 1, 0, 0, 1, 88, 13, 1, 13], false), + ("Asia/Beirut", 1774737000, [2026, 3, 29, 1, 30, 0, 1, 88, 13, 1, 13], false), + ("Asia/Beirut", 1774740600, [2026, 3, 29, 2, 30, 0, 1, 88, 13, 1, 13], false), + ("Asia/Beirut", 1782898200, [2026, 7, 1, 12, 30, 0, 4, 182, 27, 3, 26], false), + ("Asia/Beirut", 1792870200, [2026, 10, 24, 22, 30, 0, 7, 297, 43, 4, 42], false), + ("Asia/Beirut", 1792875599, [2026, 10, 24, 23, 59, 59, 7, 297, 43, 4, 42], false), + ("Asia/Beirut", 1792875600, [2026, 10, 24, 23, 0, 0, 7, 297, 43, 4, 42], false), + ("Asia/Beirut", 1792877400, [2026, 10, 24, 23, 30, 0, 7, 297, 43, 4, 42], false), + ("Asia/Beirut", 1792881000, [2026, 10, 25, 0, 30, 0, 1, 298, 43, 4, 43], false), + ("America/Santiago", 1767259800, [2026, 1, 1, 6, 30, 0, 5, 1, 1, 1, 0], false), + ("America/Santiago", 1767277800, [2026, 1, 1, 11, 30, 0, 5, 1, 1, 1, 0], false), + ("America/Santiago", 1775352600, [2026, 4, 4, 22, 30, 0, 7, 94, 14, 2, 13], false), + ("America/Santiago", 1775357999, [2026, 4, 4, 23, 59, 59, 7, 94, 14, 2, 13], false), + ("America/Santiago", 1775358000, [2026, 4, 4, 23, 0, 0, 7, 94, 14, 2, 13], false), + ("America/Santiago", 1775359800, [2026, 4, 4, 23, 30, 0, 7, 94, 14, 2, 13], false), + ("America/Santiago", 1775363400, [2026, 4, 5, 0, 30, 0, 1, 95, 14, 2, 14], false), + ("America/Santiago", 1782898200, [2026, 7, 1, 5, 30, 0, 4, 182, 27, 3, 26], false), + ("America/Santiago", 1788661800, [2026, 9, 5, 22, 30, 0, 7, 248, 36, 3, 35], false), + ("America/Santiago", 1788667199, [2026, 9, 5, 23, 59, 59, 7, 248, 36, 3, 35], false), + ("America/Santiago", 1788667200, [2026, 9, 6, 1, 0, 0, 1, 249, 36, 3, 36], false), + ("America/Santiago", 1788669000, [2026, 9, 6, 1, 30, 0, 1, 249, 36, 3, 36], false), + ("America/Santiago", 1788672600, [2026, 9, 6, 2, 30, 0, 1, 249, 36, 3, 36], false), + ]; + + /// Time zone, period, instant in seconds, and the instant of the start of the period. + const TRUNCATIONS: &[(&str, &str, i64, i64)] = &[ + ("Australia/Sydney", "year", 1767259800, 1767186000), + ("Australia/Sydney", "month", 1767259800, 1767186000), + ("Australia/Sydney", "week", 1767259800, 1766840400), + ("Australia/Sydney", "day", 1767259800, 1767186000), + ("Australia/Sydney", "hour", 1767259800, 1767258000), + ("Australia/Sydney", "minute", 1767259800, 1767259800), + ("Australia/Sydney", "year", 1767277800, 1767186000), + ("Australia/Sydney", "month", 1767277800, 1767186000), + ("Australia/Sydney", "week", 1767277800, 1766840400), + ("Australia/Sydney", "day", 1767277800, 1767272400), + ("Australia/Sydney", "hour", 1767277800, 1767276000), + ("Australia/Sydney", "minute", 1767277800, 1767277800), + ("Australia/Sydney", "year", 1775313000, 1767186000), + ("Australia/Sydney", "month", 1775313000, 1774962000), + ("Australia/Sydney", "week", 1775313000, 1775307600), + ("Australia/Sydney", "day", 1775313000, 1775307600), + ("Australia/Sydney", "hour", 1775313000, 1775311200), + ("Australia/Sydney", "minute", 1775313000, 1775313000), + ("Australia/Sydney", "year", 1775318399, 1767186000), + ("Australia/Sydney", "month", 1775318399, 1774962000), + ("Australia/Sydney", "week", 1775318399, 1775307600), + ("Australia/Sydney", "day", 1775318399, 1775307600), + ("Australia/Sydney", "hour", 1775318399, 1775314800), + ("Australia/Sydney", "minute", 1775318399, 1775318340), + ("Australia/Sydney", "year", 1775318400, 1767186000), + ("Australia/Sydney", "month", 1775318400, 1774962000), + ("Australia/Sydney", "week", 1775318400, 1775307600), + ("Australia/Sydney", "day", 1775318400, 1775307600), + ("Australia/Sydney", "hour", 1775318400, 1775318400), + ("Australia/Sydney", "minute", 1775318400, 1775318400), + ("Australia/Sydney", "year", 1775320200, 1767186000), + ("Australia/Sydney", "month", 1775320200, 1774962000), + ("Australia/Sydney", "week", 1775320200, 1775307600), + ("Australia/Sydney", "day", 1775320200, 1775307600), + ("Australia/Sydney", "hour", 1775320200, 1775318400), + ("Australia/Sydney", "minute", 1775320200, 1775320200), + ("Australia/Sydney", "year", 1775323800, 1767186000), + ("Australia/Sydney", "month", 1775323800, 1774962000), + ("Australia/Sydney", "week", 1775323800, 1775307600), + ("Australia/Sydney", "day", 1775323800, 1775307600), + ("Australia/Sydney", "hour", 1775323800, 1775322000), + ("Australia/Sydney", "minute", 1775323800, 1775323800), + ("Australia/Sydney", "year", 1782898200, 1767186000), + ("Australia/Sydney", "month", 1782898200, 1782828000), + ("Australia/Sydney", "week", 1782898200, 1782568800), + ("Australia/Sydney", "day", 1782898200, 1782828000), + ("Australia/Sydney", "hour", 1782898200, 1782896400), + ("Australia/Sydney", "minute", 1782898200, 1782898200), + ("Australia/Sydney", "year", 1791037800, 1767186000), + ("Australia/Sydney", "month", 1791037800, 1790776800), + ("Australia/Sydney", "week", 1791037800, 1791036000), + ("Australia/Sydney", "day", 1791037800, 1791036000), + ("Australia/Sydney", "hour", 1791037800, 1791036000), + ("Australia/Sydney", "minute", 1791037800, 1791037800), + ("Australia/Sydney", "year", 1791043199, 1767186000), + ("Australia/Sydney", "month", 1791043199, 1790776800), + ("Australia/Sydney", "week", 1791043199, 1791036000), + ("Australia/Sydney", "day", 1791043199, 1791036000), + ("Australia/Sydney", "hour", 1791043199, 1791039600), + ("Australia/Sydney", "minute", 1791043199, 1791043140), + ("Australia/Sydney", "year", 1791043200, 1767186000), + ("Australia/Sydney", "month", 1791043200, 1790776800), + ("Australia/Sydney", "week", 1791043200, 1791036000), + ("Australia/Sydney", "day", 1791043200, 1791036000), + ("Australia/Sydney", "hour", 1791043200, 1791043200), + ("Australia/Sydney", "minute", 1791043200, 1791043200), + ("Australia/Sydney", "year", 1791045000, 1767186000), + ("Australia/Sydney", "month", 1791045000, 1790776800), + ("Australia/Sydney", "week", 1791045000, 1791036000), + ("Australia/Sydney", "day", 1791045000, 1791036000), + ("Australia/Sydney", "hour", 1791045000, 1791043200), + ("Australia/Sydney", "minute", 1791045000, 1791045000), + ("Australia/Sydney", "year", 1791048600, 1767186000), + ("Australia/Sydney", "month", 1791048600, 1790776800), + ("Australia/Sydney", "week", 1791048600, 1791036000), + ("Australia/Sydney", "day", 1791048600, 1791036000), + ("Australia/Sydney", "hour", 1791048600, 1791046800), + ("Australia/Sydney", "minute", 1791048600, 1791048600), + ("America/New_York", "year", 1142856000, 1136091600), + ("America/New_York", "month", 1142856000, 1141189200), + ("America/New_York", "week", 1142856000, 1142744400), + ("America/New_York", "day", 1142856000, 1142830800), + ("America/New_York", "hour", 1142856000, 1142856000), + ("America/New_York", "minute", 1142856000, 1142856000), + ("America/New_York", "year", 1767259800, 1767243600), + ("America/New_York", "month", 1767259800, 1767243600), + ("America/New_York", "week", 1767259800, 1766898000), + ("America/New_York", "day", 1767259800, 1767243600), + ("America/New_York", "hour", 1767259800, 1767258000), + ("America/New_York", "minute", 1767259800, 1767259800), + ("America/New_York", "year", 1767277800, 1767243600), + ("America/New_York", "month", 1767277800, 1767243600), + ("America/New_York", "week", 1767277800, 1766898000), + ("America/New_York", "day", 1767277800, 1767243600), + ("America/New_York", "hour", 1767277800, 1767276000), + ("America/New_York", "minute", 1767277800, 1767277800), + ("America/New_York", "year", 1772947800, 1767243600), + ("America/New_York", "month", 1772947800, 1772341200), + ("America/New_York", "week", 1772947800, 1772946000), + ("America/New_York", "day", 1772947800, 1772946000), + ("America/New_York", "hour", 1772947800, 1772946000), + ("America/New_York", "minute", 1772947800, 1772947800), + ("America/New_York", "year", 1772953199, 1767243600), + ("America/New_York", "month", 1772953199, 1772341200), + ("America/New_York", "week", 1772953199, 1772946000), + ("America/New_York", "day", 1772953199, 1772946000), + ("America/New_York", "hour", 1772953199, 1772949600), + ("America/New_York", "minute", 1772953199, 1772953140), + ("America/New_York", "year", 1772953200, 1767243600), + ("America/New_York", "month", 1772953200, 1772341200), + ("America/New_York", "week", 1772953200, 1772946000), + ("America/New_York", "day", 1772953200, 1772946000), + ("America/New_York", "hour", 1772953200, 1772953200), + ("America/New_York", "minute", 1772953200, 1772953200), + ("America/New_York", "year", 1772955000, 1767243600), + ("America/New_York", "month", 1772955000, 1772341200), + ("America/New_York", "week", 1772955000, 1772946000), + ("America/New_York", "day", 1772955000, 1772946000), + ("America/New_York", "hour", 1772955000, 1772953200), + ("America/New_York", "minute", 1772955000, 1772955000), + ("America/New_York", "year", 1772958600, 1767243600), + ("America/New_York", "month", 1772958600, 1772341200), + ("America/New_York", "week", 1772958600, 1772946000), + ("America/New_York", "day", 1772958600, 1772946000), + ("America/New_York", "hour", 1772958600, 1772956800), + ("America/New_York", "minute", 1772958600, 1772958600), + ("America/New_York", "year", 1782898200, 1767243600), + ("America/New_York", "month", 1782898200, 1782878400), + ("America/New_York", "week", 1782898200, 1782619200), + ("America/New_York", "day", 1782898200, 1782878400), + ("America/New_York", "hour", 1782898200, 1782896400), + ("America/New_York", "minute", 1782898200, 1782898200), + ("America/New_York", "year", 1793507400, 1767243600), + ("America/New_York", "month", 1793507400, 1793505600), + ("America/New_York", "week", 1793507400, 1793505600), + ("America/New_York", "day", 1793507400, 1793505600), + ("America/New_York", "hour", 1793507400, 1793505600), + ("America/New_York", "minute", 1793507400, 1793507400), + ("America/New_York", "year", 1793512799, 1767243600), + ("America/New_York", "month", 1793512799, 1793505600), + ("America/New_York", "week", 1793512799, 1793505600), + ("America/New_York", "day", 1793512799, 1793505600), + ("America/New_York", "hour", 1793512799, 1793509200), + ("America/New_York", "minute", 1793512799, 1793512740), + ("America/New_York", "year", 1793512800, 1767243600), + ("America/New_York", "month", 1793512800, 1793505600), + ("America/New_York", "week", 1793512800, 1793505600), + ("America/New_York", "day", 1793512800, 1793505600), + ("America/New_York", "hour", 1793512800, 1793512800), + ("America/New_York", "minute", 1793512800, 1793512800), + ("America/New_York", "year", 1793514600, 1767243600), + ("America/New_York", "month", 1793514600, 1793505600), + ("America/New_York", "week", 1793514600, 1793505600), + ("America/New_York", "day", 1793514600, 1793505600), + ("America/New_York", "hour", 1793514600, 1793512800), + ("America/New_York", "minute", 1793514600, 1793514600), + ("America/New_York", "year", 1793518200, 1767243600), + ("America/New_York", "month", 1793518200, 1793505600), + ("America/New_York", "week", 1793518200, 1793505600), + ("America/New_York", "day", 1793518200, 1793505600), + ("America/New_York", "hour", 1793518200, 1793516400), + ("America/New_York", "minute", 1793518200, 1793518200), + ("Europe/London", "year", 0, -3600), + ("Europe/London", "month", 0, -3600), + ("Europe/London", "week", 0, -349200), + ("Europe/London", "day", 0, -3600), + ("Europe/London", "hour", 0, 0), + ("Europe/London", "minute", 0, 0), + ("Europe/London", "year", 1767259800, 1767225600), + ("Europe/London", "month", 1767259800, 1767225600), + ("Europe/London", "week", 1767259800, 1766880000), + ("Europe/London", "day", 1767259800, 1767225600), + ("Europe/London", "hour", 1767259800, 1767258000), + ("Europe/London", "minute", 1767259800, 1767259800), + ("Europe/London", "year", 1767277800, 1767225600), + ("Europe/London", "month", 1767277800, 1767225600), + ("Europe/London", "week", 1767277800, 1766880000), + ("Europe/London", "day", 1767277800, 1767225600), + ("Europe/London", "hour", 1767277800, 1767276000), + ("Europe/London", "minute", 1767277800, 1767277800), + ("Europe/London", "year", 1774740600, 1767225600), + ("Europe/London", "month", 1774740600, 1772323200), + ("Europe/London", "week", 1774740600, 1774137600), + ("Europe/London", "day", 1774740600, 1774656000), + ("Europe/London", "hour", 1774740600, 1774738800), + ("Europe/London", "minute", 1774740600, 1774740600), + ("Europe/London", "year", 1774745999, 1767225600), + ("Europe/London", "month", 1774745999, 1772323200), + ("Europe/London", "week", 1774745999, 1774742400), + ("Europe/London", "day", 1774745999, 1774742400), + ("Europe/London", "hour", 1774745999, 1774742400), + ("Europe/London", "minute", 1774745999, 1774745940), + ("Europe/London", "year", 1774746000, 1767225600), + ("Europe/London", "month", 1774746000, 1772323200), + ("Europe/London", "week", 1774746000, 1774742400), + ("Europe/London", "day", 1774746000, 1774742400), + ("Europe/London", "hour", 1774746000, 1774746000), + ("Europe/London", "minute", 1774746000, 1774746000), + ("Europe/London", "year", 1774747800, 1767225600), + ("Europe/London", "month", 1774747800, 1772323200), + ("Europe/London", "week", 1774747800, 1774742400), + ("Europe/London", "day", 1774747800, 1774742400), + ("Europe/London", "hour", 1774747800, 1774746000), + ("Europe/London", "minute", 1774747800, 1774747800), + ("Europe/London", "year", 1774751400, 1767225600), + ("Europe/London", "month", 1774751400, 1772323200), + ("Europe/London", "week", 1774751400, 1774742400), + ("Europe/London", "day", 1774751400, 1774742400), + ("Europe/London", "hour", 1774751400, 1774749600), + ("Europe/London", "minute", 1774751400, 1774751400), + ("Europe/London", "year", 1782898200, 1767225600), + ("Europe/London", "month", 1782898200, 1782860400), + ("Europe/London", "week", 1782898200, 1782601200), + ("Europe/London", "day", 1782898200, 1782860400), + ("Europe/London", "hour", 1782898200, 1782896400), + ("Europe/London", "minute", 1782898200, 1782898200), + ("Europe/London", "year", 1792884600, 1767225600), + ("Europe/London", "month", 1792884600, 1790809200), + ("Europe/London", "week", 1792884600, 1792882800), + ("Europe/London", "day", 1792884600, 1792882800), + ("Europe/London", "hour", 1792884600, 1792882800), + ("Europe/London", "minute", 1792884600, 1792884600), + ("Europe/London", "year", 1792889999, 1767225600), + ("Europe/London", "month", 1792889999, 1790809200), + ("Europe/London", "week", 1792889999, 1792882800), + ("Europe/London", "day", 1792889999, 1792882800), + ("Europe/London", "hour", 1792889999, 1792886400), + ("Europe/London", "minute", 1792889999, 1792889940), + ("Europe/London", "year", 1792890000, 1767225600), + ("Europe/London", "month", 1792890000, 1790809200), + ("Europe/London", "week", 1792890000, 1792882800), + ("Europe/London", "day", 1792890000, 1792882800), + ("Europe/London", "hour", 1792890000, 1792890000), + ("Europe/London", "minute", 1792890000, 1792890000), + ("Europe/London", "year", 1792891800, 1767225600), + ("Europe/London", "month", 1792891800, 1790809200), + ("Europe/London", "week", 1792891800, 1792882800), + ("Europe/London", "day", 1792891800, 1792882800), + ("Europe/London", "hour", 1792891800, 1792890000), + ("Europe/London", "minute", 1792891800, 1792891800), + ("Europe/London", "year", 1792895400, 1767225600), + ("Europe/London", "month", 1792895400, 1790809200), + ("Europe/London", "week", 1792895400, 1792882800), + ("Europe/London", "day", 1792895400, 1792882800), + ("Europe/London", "hour", 1792895400, 1792893600), + ("Europe/London", "minute", 1792895400, 1792895400), + ("Australia/Lord_Howe", "year", 1767259800, 1767186000), + ("Australia/Lord_Howe", "month", 1767259800, 1767186000), + ("Australia/Lord_Howe", "week", 1767259800, 1766840400), + ("Australia/Lord_Howe", "day", 1767259800, 1767186000), + ("Australia/Lord_Howe", "hour", 1767259800, 1767258000), + ("Australia/Lord_Howe", "minute", 1767259800, 1767259800), + ("Australia/Lord_Howe", "year", 1767277800, 1767186000), + ("Australia/Lord_Howe", "month", 1767277800, 1767186000), + ("Australia/Lord_Howe", "week", 1767277800, 1766840400), + ("Australia/Lord_Howe", "day", 1767277800, 1767272400), + ("Australia/Lord_Howe", "hour", 1767277800, 1767276000), + ("Australia/Lord_Howe", "minute", 1767277800, 1767277800), + ("Australia/Lord_Howe", "year", 1775309400, 1767186000), + ("Australia/Lord_Howe", "month", 1775309400, 1774962000), + ("Australia/Lord_Howe", "week", 1775309400, 1775307600), + ("Australia/Lord_Howe", "day", 1775309400, 1775307600), + ("Australia/Lord_Howe", "hour", 1775309400, 1775307600), + ("Australia/Lord_Howe", "minute", 1775309400, 1775309400), + ("Australia/Lord_Howe", "year", 1775314799, 1767186000), + ("Australia/Lord_Howe", "month", 1775314799, 1774962000), + ("Australia/Lord_Howe", "week", 1775314799, 1775307600), + ("Australia/Lord_Howe", "day", 1775314799, 1775307600), + ("Australia/Lord_Howe", "hour", 1775314799, 1775311200), + ("Australia/Lord_Howe", "minute", 1775314799, 1775314740), + ("Australia/Lord_Howe", "year", 1775314800, 1767186000), + ("Australia/Lord_Howe", "month", 1775314800, 1774962000), + ("Australia/Lord_Howe", "week", 1775314800, 1775307600), + ("Australia/Lord_Howe", "day", 1775314800, 1775307600), + ("Australia/Lord_Howe", "hour", 1775314800, 1775311200), + ("Australia/Lord_Howe", "minute", 1775314800, 1775314800), + ("Australia/Lord_Howe", "year", 1775316600, 1767186000), + ("Australia/Lord_Howe", "month", 1775316600, 1774962000), + ("Australia/Lord_Howe", "week", 1775316600, 1775307600), + ("Australia/Lord_Howe", "day", 1775316600, 1775307600), + ("Australia/Lord_Howe", "hour", 1775316600, 1775316600), + ("Australia/Lord_Howe", "minute", 1775316600, 1775316600), + ("Australia/Lord_Howe", "year", 1775320200, 1767186000), + ("Australia/Lord_Howe", "month", 1775320200, 1774962000), + ("Australia/Lord_Howe", "week", 1775320200, 1775307600), + ("Australia/Lord_Howe", "day", 1775320200, 1775307600), + ("Australia/Lord_Howe", "hour", 1775320200, 1775320200), + ("Australia/Lord_Howe", "minute", 1775320200, 1775320200), + ("Australia/Lord_Howe", "year", 1782898200, 1767186000), + ("Australia/Lord_Howe", "month", 1782898200, 1782826200), + ("Australia/Lord_Howe", "week", 1782898200, 1782567000), + ("Australia/Lord_Howe", "day", 1782898200, 1782826200), + ("Australia/Lord_Howe", "hour", 1782898200, 1782898200), + ("Australia/Lord_Howe", "minute", 1782898200, 1782898200), + ("Australia/Lord_Howe", "year", 1791036000, 1767186000), + ("Australia/Lord_Howe", "month", 1791036000, 1790775000), + ("Australia/Lord_Howe", "week", 1791036000, 1791034200), + ("Australia/Lord_Howe", "day", 1791036000, 1791034200), + ("Australia/Lord_Howe", "hour", 1791036000, 1791034200), + ("Australia/Lord_Howe", "minute", 1791036000, 1791036000), + ("Australia/Lord_Howe", "year", 1791041399, 1767186000), + ("Australia/Lord_Howe", "month", 1791041399, 1790775000), + ("Australia/Lord_Howe", "week", 1791041399, 1791034200), + ("Australia/Lord_Howe", "day", 1791041399, 1791034200), + ("Australia/Lord_Howe", "hour", 1791041399, 1791037800), + ("Australia/Lord_Howe", "minute", 1791041399, 1791041340), + ("Australia/Lord_Howe", "year", 1791041400, 1767186000), + ("Australia/Lord_Howe", "month", 1791041400, 1790775000), + ("Australia/Lord_Howe", "week", 1791041400, 1791034200), + ("Australia/Lord_Howe", "day", 1791041400, 1791034200), + ("Australia/Lord_Howe", "hour", 1791041400, 1791041400), + ("Australia/Lord_Howe", "minute", 1791041400, 1791041400), + ("Australia/Lord_Howe", "year", 1791043200, 1767186000), + ("Australia/Lord_Howe", "month", 1791043200, 1790775000), + ("Australia/Lord_Howe", "week", 1791043200, 1791034200), + ("Australia/Lord_Howe", "day", 1791043200, 1791034200), + ("Australia/Lord_Howe", "hour", 1791043200, 1791043200), + ("Australia/Lord_Howe", "minute", 1791043200, 1791043200), + ("Australia/Lord_Howe", "year", 1791046800, 1767186000), + ("Australia/Lord_Howe", "month", 1791046800, 1790775000), + ("Australia/Lord_Howe", "week", 1791046800, 1791034200), + ("Australia/Lord_Howe", "day", 1791046800, 1791034200), + ("Australia/Lord_Howe", "hour", 1791046800, 1791046800), + ("Australia/Lord_Howe", "minute", 1791046800, 1791046800), + ("Asia/Kolkata", "year", 1767259800, 1767205800), + ("Asia/Kolkata", "month", 1767259800, 1767205800), + ("Asia/Kolkata", "week", 1767259800, 1766860200), + ("Asia/Kolkata", "day", 1767259800, 1767205800), + ("Asia/Kolkata", "hour", 1767259800, 1767259800), + ("Asia/Kolkata", "minute", 1767259800, 1767259800), + ("Asia/Kolkata", "year", 1767277800, 1767205800), + ("Asia/Kolkata", "month", 1767277800, 1767205800), + ("Asia/Kolkata", "week", 1767277800, 1766860200), + ("Asia/Kolkata", "day", 1767277800, 1767205800), + ("Asia/Kolkata", "hour", 1767277800, 1767277800), + ("Asia/Kolkata", "minute", 1767277800, 1767277800), + ("Asia/Kolkata", "year", 1782898200, 1767205800), + ("Asia/Kolkata", "month", 1782898200, 1782844200), + ("Asia/Kolkata", "week", 1782898200, 1782585000), + ("Asia/Kolkata", "day", 1782898200, 1782844200), + ("Asia/Kolkata", "hour", 1782898200, 1782898200), + ("Asia/Kolkata", "minute", 1782898200, 1782898200), + ("Asia/Kathmandu", "year", 1767259800, 1767204900), + ("Asia/Kathmandu", "month", 1767259800, 1767204900), + ("Asia/Kathmandu", "week", 1767259800, 1766859300), + ("Asia/Kathmandu", "day", 1767259800, 1767204900), + ("Asia/Kathmandu", "hour", 1767259800, 1767258900), + ("Asia/Kathmandu", "minute", 1767259800, 1767259800), + ("Asia/Kathmandu", "year", 1767277800, 1767204900), + ("Asia/Kathmandu", "month", 1767277800, 1767204900), + ("Asia/Kathmandu", "week", 1767277800, 1766859300), + ("Asia/Kathmandu", "day", 1767277800, 1767204900), + ("Asia/Kathmandu", "hour", 1767277800, 1767276900), + ("Asia/Kathmandu", "minute", 1767277800, 1767277800), + ("Asia/Kathmandu", "year", 1782898200, 1767204900), + ("Asia/Kathmandu", "month", 1782898200, 1782843300), + ("Asia/Kathmandu", "week", 1782898200, 1782584100), + ("Asia/Kathmandu", "day", 1782898200, 1782843300), + ("Asia/Kathmandu", "hour", 1782898200, 1782897300), + ("Asia/Kathmandu", "minute", 1782898200, 1782898200), + ("America/Havana", "year", 1767259800, 1767243600), + ("America/Havana", "month", 1767259800, 1767243600), + ("America/Havana", "week", 1767259800, 1766898000), + ("America/Havana", "day", 1767259800, 1767243600), + ("America/Havana", "hour", 1767259800, 1767258000), + ("America/Havana", "minute", 1767259800, 1767259800), + ("America/Havana", "year", 1767277800, 1767243600), + ("America/Havana", "month", 1767277800, 1767243600), + ("America/Havana", "week", 1767277800, 1766898000), + ("America/Havana", "day", 1767277800, 1767243600), + ("America/Havana", "hour", 1767277800, 1767276000), + ("America/Havana", "minute", 1767277800, 1767277800), + ("America/Havana", "year", 1772940600, 1767243600), + ("America/Havana", "month", 1772940600, 1772341200), + ("America/Havana", "week", 1772940600, 1772341200), + ("America/Havana", "day", 1772940600, 1772859600), + ("America/Havana", "hour", 1772940600, 1772938800), + ("America/Havana", "minute", 1772940600, 1772940600), + ("America/Havana", "year", 1772945999, 1767243600), + ("America/Havana", "month", 1772945999, 1772341200), + ("America/Havana", "week", 1772945999, 1772341200), + ("America/Havana", "day", 1772945999, 1772859600), + ("America/Havana", "hour", 1772945999, 1772942400), + ("America/Havana", "minute", 1772945999, 1772945940), + ("America/Havana", "year", 1772946000, 1767243600), + ("America/Havana", "month", 1772946000, 1772341200), + ("America/Havana", "week", 1772946000, 1772946000), + ("America/Havana", "day", 1772946000, 1772946000), + ("America/Havana", "hour", 1772946000, 1772946000), + ("America/Havana", "minute", 1772946000, 1772946000), + ("America/Havana", "year", 1772947800, 1767243600), + ("America/Havana", "month", 1772947800, 1772341200), + ("America/Havana", "week", 1772947800, 1772946000), + ("America/Havana", "day", 1772947800, 1772946000), + ("America/Havana", "hour", 1772947800, 1772946000), + ("America/Havana", "minute", 1772947800, 1772947800), + ("America/Havana", "year", 1772951400, 1767243600), + ("America/Havana", "month", 1772951400, 1772341200), + ("America/Havana", "week", 1772951400, 1772946000), + ("America/Havana", "day", 1772951400, 1772946000), + ("America/Havana", "hour", 1772951400, 1772949600), + ("America/Havana", "minute", 1772951400, 1772951400), + ("America/Havana", "year", 1782898200, 1767243600), + ("America/Havana", "month", 1782898200, 1782878400), + ("America/Havana", "week", 1782898200, 1782619200), + ("America/Havana", "day", 1782898200, 1782878400), + ("America/Havana", "hour", 1782898200, 1782896400), + ("America/Havana", "minute", 1782898200, 1782898200), + ("America/Havana", "year", 1793503800, 1767243600), + ("America/Havana", "month", 1793503800, 1790827200), + ("America/Havana", "week", 1793503800, 1792900800), + ("America/Havana", "day", 1793503800, 1793419200), + ("America/Havana", "hour", 1793503800, 1793502000), + ("America/Havana", "minute", 1793503800, 1793503800), + ("America/Havana", "year", 1793509199, 1767243600), + ("America/Havana", "month", 1793509199, 1793505600), + ("America/Havana", "week", 1793509199, 1793505600), + ("America/Havana", "day", 1793509199, 1793505600), + ("America/Havana", "hour", 1793509199, 1793505600), + ("America/Havana", "minute", 1793509199, 1793509140), + ("America/Havana", "year", 1793509200, 1767243600), + ("America/Havana", "month", 1793509200, 1793509200), + ("America/Havana", "week", 1793509200, 1793509200), + ("America/Havana", "day", 1793509200, 1793509200), + ("America/Havana", "hour", 1793509200, 1793509200), + ("America/Havana", "minute", 1793509200, 1793509200), + ("America/Havana", "year", 1793511000, 1767243600), + ("America/Havana", "month", 1793511000, 1793509200), + ("America/Havana", "week", 1793511000, 1793509200), + ("America/Havana", "day", 1793511000, 1793509200), + ("America/Havana", "hour", 1793511000, 1793509200), + ("America/Havana", "minute", 1793511000, 1793511000), + ("America/Havana", "year", 1793514600, 1767243600), + ("America/Havana", "month", 1793514600, 1793509200), + ("America/Havana", "week", 1793514600, 1793509200), + ("America/Havana", "day", 1793514600, 1793509200), + ("America/Havana", "hour", 1793514600, 1793512800), + ("America/Havana", "minute", 1793514600, 1793514600), + ("Asia/Beirut", "year", 1767259800, 1767218400), + ("Asia/Beirut", "month", 1767259800, 1767218400), + ("Asia/Beirut", "week", 1767259800, 1766872800), + ("Asia/Beirut", "day", 1767259800, 1767218400), + ("Asia/Beirut", "hour", 1767259800, 1767258000), + ("Asia/Beirut", "minute", 1767259800, 1767259800), + ("Asia/Beirut", "year", 1767277800, 1767218400), + ("Asia/Beirut", "month", 1767277800, 1767218400), + ("Asia/Beirut", "week", 1767277800, 1766872800), + ("Asia/Beirut", "day", 1767277800, 1767218400), + ("Asia/Beirut", "hour", 1767277800, 1767276000), + ("Asia/Beirut", "minute", 1767277800, 1767277800), + ("Asia/Beirut", "year", 1774729800, 1767218400), + ("Asia/Beirut", "month", 1774729800, 1772316000), + ("Asia/Beirut", "week", 1774729800, 1774130400), + ("Asia/Beirut", "day", 1774729800, 1774648800), + ("Asia/Beirut", "hour", 1774729800, 1774728000), + ("Asia/Beirut", "minute", 1774729800, 1774729800), + ("Asia/Beirut", "year", 1774735199, 1767218400), + ("Asia/Beirut", "month", 1774735199, 1772316000), + ("Asia/Beirut", "week", 1774735199, 1774130400), + ("Asia/Beirut", "day", 1774735199, 1774648800), + ("Asia/Beirut", "hour", 1774735199, 1774731600), + ("Asia/Beirut", "minute", 1774735199, 1774735140), + ("Asia/Beirut", "year", 1774735200, 1767218400), + ("Asia/Beirut", "month", 1774735200, 1772316000), + ("Asia/Beirut", "week", 1774735200, 1774735200), + ("Asia/Beirut", "day", 1774735200, 1774735200), + ("Asia/Beirut", "hour", 1774735200, 1774735200), + ("Asia/Beirut", "minute", 1774735200, 1774735200), + ("Asia/Beirut", "year", 1774737000, 1767218400), + ("Asia/Beirut", "month", 1774737000, 1772316000), + ("Asia/Beirut", "week", 1774737000, 1774735200), + ("Asia/Beirut", "day", 1774737000, 1774735200), + ("Asia/Beirut", "hour", 1774737000, 1774735200), + ("Asia/Beirut", "minute", 1774737000, 1774737000), + ("Asia/Beirut", "year", 1774740600, 1767218400), + ("Asia/Beirut", "month", 1774740600, 1772316000), + ("Asia/Beirut", "week", 1774740600, 1774735200), + ("Asia/Beirut", "day", 1774740600, 1774735200), + ("Asia/Beirut", "hour", 1774740600, 1774738800), + ("Asia/Beirut", "minute", 1774740600, 1774740600), + ("Asia/Beirut", "year", 1782898200, 1767218400), + ("Asia/Beirut", "month", 1782898200, 1782853200), + ("Asia/Beirut", "week", 1782898200, 1782594000), + ("Asia/Beirut", "day", 1782898200, 1782853200), + ("Asia/Beirut", "hour", 1782898200, 1782896400), + ("Asia/Beirut", "minute", 1782898200, 1782898200), + ("Asia/Beirut", "year", 1792870200, 1767218400), + ("Asia/Beirut", "month", 1792870200, 1790802000), + ("Asia/Beirut", "week", 1792870200, 1792270800), + ("Asia/Beirut", "day", 1792870200, 1792789200), + ("Asia/Beirut", "hour", 1792870200, 1792868400), + ("Asia/Beirut", "minute", 1792870200, 1792870200), + ("Asia/Beirut", "year", 1792875599, 1767218400), + ("Asia/Beirut", "month", 1792875599, 1790802000), + ("Asia/Beirut", "week", 1792875599, 1792270800), + ("Asia/Beirut", "day", 1792875599, 1792789200), + ("Asia/Beirut", "hour", 1792875599, 1792872000), + ("Asia/Beirut", "minute", 1792875599, 1792875540), + ("Asia/Beirut", "year", 1792875600, 1767218400), + ("Asia/Beirut", "month", 1792875600, 1790802000), + ("Asia/Beirut", "week", 1792875600, 1792270800), + ("Asia/Beirut", "day", 1792875600, 1792789200), + ("Asia/Beirut", "hour", 1792875600, 1792875600), + ("Asia/Beirut", "minute", 1792875600, 1792875600), + ("Asia/Beirut", "year", 1792877400, 1767218400), + ("Asia/Beirut", "month", 1792877400, 1790802000), + ("Asia/Beirut", "week", 1792877400, 1792270800), + ("Asia/Beirut", "day", 1792877400, 1792789200), + ("Asia/Beirut", "hour", 1792877400, 1792875600), + ("Asia/Beirut", "minute", 1792877400, 1792877400), + ("Asia/Beirut", "year", 1792881000, 1767218400), + ("Asia/Beirut", "month", 1792881000, 1790802000), + ("Asia/Beirut", "week", 1792881000, 1792879200), + ("Asia/Beirut", "day", 1792881000, 1792879200), + ("Asia/Beirut", "hour", 1792881000, 1792879200), + ("Asia/Beirut", "minute", 1792881000, 1792881000), + ("America/Santiago", "year", 1767259800, 1767236400), + ("America/Santiago", "month", 1767259800, 1767236400), + ("America/Santiago", "week", 1767259800, 1766890800), + ("America/Santiago", "day", 1767259800, 1767236400), + ("America/Santiago", "hour", 1767259800, 1767258000), + ("America/Santiago", "minute", 1767259800, 1767259800), + ("America/Santiago", "year", 1767277800, 1767236400), + ("America/Santiago", "month", 1767277800, 1767236400), + ("America/Santiago", "week", 1767277800, 1766890800), + ("America/Santiago", "day", 1767277800, 1767236400), + ("America/Santiago", "hour", 1767277800, 1767276000), + ("America/Santiago", "minute", 1767277800, 1767277800), + ("America/Santiago", "year", 1775352600, 1767236400), + ("America/Santiago", "month", 1775352600, 1775012400), + ("America/Santiago", "week", 1775352600, 1774753200), + ("America/Santiago", "day", 1775352600, 1775271600), + ("America/Santiago", "hour", 1775352600, 1775350800), + ("America/Santiago", "minute", 1775352600, 1775352600), + ("America/Santiago", "year", 1775357999, 1767236400), + ("America/Santiago", "month", 1775357999, 1775012400), + ("America/Santiago", "week", 1775357999, 1774753200), + ("America/Santiago", "day", 1775357999, 1775271600), + ("America/Santiago", "hour", 1775357999, 1775354400), + ("America/Santiago", "minute", 1775357999, 1775357940), + ("America/Santiago", "year", 1775358000, 1767236400), + ("America/Santiago", "month", 1775358000, 1775012400), + ("America/Santiago", "week", 1775358000, 1774753200), + ("America/Santiago", "day", 1775358000, 1775271600), + ("America/Santiago", "hour", 1775358000, 1775358000), + ("America/Santiago", "minute", 1775358000, 1775358000), + ("America/Santiago", "year", 1775359800, 1767236400), + ("America/Santiago", "month", 1775359800, 1775012400), + ("America/Santiago", "week", 1775359800, 1774753200), + ("America/Santiago", "day", 1775359800, 1775271600), + ("America/Santiago", "hour", 1775359800, 1775358000), + ("America/Santiago", "minute", 1775359800, 1775359800), + ("America/Santiago", "year", 1775363400, 1767236400), + ("America/Santiago", "month", 1775363400, 1775012400), + ("America/Santiago", "week", 1775363400, 1775361600), + ("America/Santiago", "day", 1775363400, 1775361600), + ("America/Santiago", "hour", 1775363400, 1775361600), + ("America/Santiago", "minute", 1775363400, 1775363400), + ("America/Santiago", "year", 1782898200, 1767236400), + ("America/Santiago", "month", 1782898200, 1782878400), + ("America/Santiago", "week", 1782898200, 1782619200), + ("America/Santiago", "day", 1782898200, 1782878400), + ("America/Santiago", "hour", 1782898200, 1782896400), + ("America/Santiago", "minute", 1782898200, 1782898200), + ("America/Santiago", "year", 1788661800, 1767236400), + ("America/Santiago", "month", 1788661800, 1788235200), + ("America/Santiago", "week", 1788661800, 1788062400), + ("America/Santiago", "day", 1788661800, 1788580800), + ("America/Santiago", "hour", 1788661800, 1788660000), + ("America/Santiago", "minute", 1788661800, 1788661800), + ("America/Santiago", "year", 1788667199, 1767236400), + ("America/Santiago", "month", 1788667199, 1788235200), + ("America/Santiago", "week", 1788667199, 1788062400), + ("America/Santiago", "day", 1788667199, 1788580800), + ("America/Santiago", "hour", 1788667199, 1788663600), + ("America/Santiago", "minute", 1788667199, 1788667140), + ("America/Santiago", "year", 1788667200, 1767236400), + ("America/Santiago", "month", 1788667200, 1788235200), + ("America/Santiago", "week", 1788667200, 1788667200), + ("America/Santiago", "day", 1788667200, 1788667200), + ("America/Santiago", "hour", 1788667200, 1788667200), + ("America/Santiago", "minute", 1788667200, 1788667200), + ("America/Santiago", "year", 1788669000, 1767236400), + ("America/Santiago", "month", 1788669000, 1788235200), + ("America/Santiago", "week", 1788669000, 1788667200), + ("America/Santiago", "day", 1788669000, 1788667200), + ("America/Santiago", "hour", 1788669000, 1788667200), + ("America/Santiago", "minute", 1788669000, 1788669000), + ("America/Santiago", "year", 1788672600, 1767236400), + ("America/Santiago", "month", 1788672600, 1788235200), + ("America/Santiago", "week", 1788672600, 1788667200), + ("America/Santiago", "day", 1788672600, 1788667200), + ("America/Santiago", "hour", 1788672600, 1788670800), + ("America/Santiago", "minute", 1788672600, 1788672600), + ]; + + /// Time zone, instant in seconds, months added, and the resulting instant. + const MONTHS: &[(&str, i64, i32, i64)] = &[ + ("Australia/Sydney", 1788453000, 1, 1791045000), + ("Australia/Sydney", 1772638200, 1, 1775316600), + ("Australia/Sydney", 1773529200, 1, 1776211200), + ("Australia/Sydney", 1769807700, 1, 1772226900), + ("Australia/Sydney", 1782871200, 6, 1798765200), + ("Australia/Sydney", 1782871200, -6, 1767229200), + ("America/New_York", 1770535800, 1, 1772955000), + ("America/New_York", 1790832600, 1, 1793511000), + ("America/New_York", 1768485600, 12, 1800021600), + ("America/New_York", 1709215200, 12, 1740751200), + ("Europe/London", 1772242200, 1, 1774661400), + ("Europe/London", 1772242200, 13, 1806197400), + ("Australia/Lord_Howe", 1788450300, 1, 1791042300), + ("America/Havana", 1770528600, 1, 1772947800), + ("America/Havana", 1790829000, 1, 1793507400), + ("Asia/Kolkata", 1769884140, 1, 1772303340), + ("Asia/Kathmandu", 1780189200, -3, 1772240400), + ]; + + const UNITS: [(TimeUnit, i64); 4] = [ + (TimeUnit::Seconds, 1), + (TimeUnit::Milliseconds, 1_000), + (TimeUnit::Microseconds, 1_000_000), + (TimeUnit::Nanoseconds, 1_000_000_000), + ]; + + fn zoned(values: &[i64], tz: &str, unit: TimeUnit) -> DatetimeArray { + DatetimeArray::::from_slice(values, Dt::Timestamp(unit, Some(tz.into()))) + } + + fn components(arr: &DatetimeArray, row: usize) -> [i32; 11] { + [ + arr.year().data[row], + arr.month().data[row], + arr.day().data[row], + arr.hour().data[row], + arr.minute().data[row], + arr.second().data[row], + arr.weekday().data[row], + arr.day_of_year().data[row], + arr.iso_week().data[row], + arr.quarter().data[row], + arr.week_of_year().data[row], + ] + } + + #[test] + fn test_components_read_the_wall_time_of_the_time_zone() { + for (unit, scale) in UNITS { + for (tz, instant, fields, leap) in COMPONENTS { + // A fraction of a second is added for the sub-second units. + let value = instant * scale + scale / 4; + let arr = zoned(&[value], tz, unit); + assert_eq!(components(&arr, 0), *fields, "{tz} at {instant} in {unit:?}"); + assert_eq!(arr.is_leap_year().get(0), Some(*leap), "{tz} at {instant}"); + // The stored value is the UTC value. + assert_eq!(arr.data[0], value); + } + } + } + + #[test] + fn test_truncation_writes_the_utc_value_of_the_period_start_on_the_wall_clock() { + for (unit, scale) in UNITS { + for (tz, period, instant, start) in TRUNCATIONS { + let value = instant * scale + scale / 4; + let arr = zoned(&[value], tz, unit); + let truncated = arr.truncate(*period); + assert_eq!( + truncated.data[0], + start * scale, + "{tz} at {instant} to the {period} in {unit:?}" + ); + assert_eq!(truncated.dtype, arr.dtype); + assert_eq!(arr.data[0], value); + } + } + } + + #[test] + fn test_add_months_keeps_the_wall_time_and_writes_its_utc_value() { + for (unit, scale) in UNITS { + for (tz, instant, months, result) in MONTHS { + let value = instant * scale + scale / 4; + let arr = zoned(&[value], tz, unit); + let added = arr.add_months(*months).unwrap(); + assert_eq!( + added.data[0], + result * scale + scale / 4, + "{tz} at {instant} plus {months} months in {unit:?}" + ); + assert_eq!(added.dtype, arr.dtype); + assert_eq!(arr.data[0], value); + } + } + } + + #[test] + fn test_add_years_adds_twelve_months_on_the_wall_time() { + for (tz, instant, months, result) in MONTHS.iter().filter(|case| case.2 == 12) { + let arr = zoned(&[*instant], tz, TimeUnit::Seconds); + assert_eq!(arr.add_years(months / 12).unwrap().data[0], *result, "{tz} at {instant}"); + } + } + + #[test] + fn test_null_rows_stay_null_and_other_rows_read_their_wall_time() { + let rows: Vec<&(&str, i64, [i32; 11], bool)> = COMPONENTS + .iter() + .filter(|row| row.0 == "Australia/Sydney") + .collect(); + let values: Vec = rows.iter().map(|row| row.1).collect(); + let mut arr = zoned(&values, "Australia/Sydney", TimeUnit::Seconds); + let mut mask = Bitmask::new_set_all(values.len(), true); + mask.set(1, false); + arr.null_mask = Some(mask); + + let hours = arr.hour(); + let days = arr.truncate(TimePeriod::Day); + for (i, row) in rows.iter().enumerate() { + assert_eq!(hours.is_null(i), i == 1); + assert_eq!(days.is_null(i), i == 1); + if i != 1 { + assert_eq!(hours.data[i], row.2[3], "row {i}"); + } + } + assert_eq!(&arr.data[..], &values[..]); + } + + #[test] + fn test_views_and_the_temporal_enum_read_the_wall_time_of_the_time_zone() { + let rows: Vec<&(&str, i64, [i32; 11], bool)> = COMPONENTS + .iter() + .filter(|row| row.0 == "America/New_York") + .collect(); + let values: Vec = rows.iter().map(|row| row.1).collect(); + let temporal = TemporalArray::Datetime64(Arc::new(zoned( + &values, + "America/New_York", + TimeUnit::Seconds, + ))); + + let hours = temporal.hour(); + let days = temporal.day(); + let leap = temporal.is_leap_year(); + for (i, row) in rows.iter().enumerate() { + assert_eq!(hours.data[i], row.2[3], "enum row {i}"); + assert_eq!(days.data[i], row.2[2], "enum row {i}"); + assert_eq!(leap.get(i), Some(row.3), "enum row {i}"); + } + + // The view covers the rows after the first one. + let view = TemporalArrayV::new(temporal, 1, values.len() - 1); + let hours = view.hour(); + let days = view.day(); + let weekdays = view.weekday(); + let leap = view.is_leap_year(); + for (i, row) in rows.iter().skip(1).enumerate() { + assert_eq!(hours.data[i], row.2[3], "view row {i}"); + assert_eq!(days.data[i], row.2[2], "view row {i}"); + assert_eq!(weekdays.data[i], row.2[6], "view row {i}"); + assert_eq!(leap.get(i), Some(row.3), "view row {i}"); + } + } + + #[test] + fn test_output_buffer_kernels_read_the_wall_time_of_the_time_zone() { + let rows: Vec<&(&str, i64, [i32; 11], bool)> = COMPONENTS + .iter() + .filter(|row| row.0 == "Australia/Lord_Howe") + .collect(); + let values: Vec = rows.iter().map(|row| row.1).collect(); + let arr = zoned(&values, "Australia/Lord_Howe", TimeUnit::Seconds); + + // The window covers the rows after the first one. + let len = values.len() - 1; + let mut hours = vec![0i32; len]; + let mut minutes = vec![0i32; len]; + let mut mask = Bitmask::new_set_all(len, true); + hour_into(&arr, 1, &mut hours, Some(&mut mask)); + minute_into(&arr, 1, &mut minutes, None); + let mut leap = Bitmask::new_set_all(len, false); + is_leap_year_into(&arr, 1, &mut leap, None); + for (i, row) in rows.iter().skip(1).enumerate() { + assert_eq!((hours[i], minutes[i]), (row.2[3], row.2[4]), "row {i}"); + assert_eq!(leap.get(i), row.3, "row {i}"); + assert!(mask.get(i)); + } + } + + #[test] + fn test_instant_operations_return_the_values_of_arrays_without_a_time_zone() { + let values: Vec = COMPONENTS.iter().map(|row| row.1 * 1_000 + 250).collect(); + let later: Vec = values.iter().map(|value| value + 5_400_000).collect(); + let plain = DatetimeArray::::from_slice(&values, Dt::Timestamp(TimeUnit::Milliseconds, None)); + let plain_later = + DatetimeArray::::from_slice(&later, Dt::Timestamp(TimeUnit::Milliseconds, None)); + let arr = zoned(&values, "Australia/Sydney", TimeUnit::Milliseconds); + let arr_later = zoned(&later, "Australia/Sydney", TimeUnit::Milliseconds); + + let duration = Duration::hours(36); + assert_eq!( + &arr.add_duration(duration).unwrap().data[..], + &plain.add_duration(duration).unwrap().data[..] + ); + assert_eq!( + &arr.sub_duration(duration).unwrap().data[..], + &plain.sub_duration(duration).unwrap().data[..] + ); + // `add_days` adds days of 24 hours to the instant. + assert_eq!(&arr.add_days(1).unwrap().data[..], &plain.add_days(1).unwrap().data[..]); + assert_eq!( + &arr_later.diff(&arr, TimeUnit::Seconds).unwrap().data[..], + &plain_later.diff(&plain, TimeUnit::Seconds).unwrap().data[..] + ); + assert_eq!(arr.is_before(&arr_later).unwrap(), plain.is_before(&plain_later).unwrap()); + assert_eq!(arr.is_after(&arr_later).unwrap(), plain.is_after(&plain_later).unwrap()); + assert_eq!( + &arr.cast_time_unit(TimeUnit::Seconds).unwrap().data[..], + &plain.cast_time_unit(TimeUnit::Seconds).unwrap().data[..] + ); + // Truncation to seconds is not affected by offsets of whole seconds. + assert_eq!(&arr.sec().data[..], &plain.sec().data[..]); + } + + #[test] + fn test_unresolved_time_zone_text_is_read_as_utc() { + let values: Vec = COMPONENTS.iter().map(|row| row.1).collect(); + let plain = DatetimeArray::::from_slice(&values, Dt::Timestamp(TimeUnit::Seconds, None)); + let arr = zoned(&values, "Mars/Olympus_Mons", TimeUnit::Seconds); + assert_eq!(&arr.hour().data[..], &plain.hour().data[..]); + assert_eq!(&arr.day().data[..], &plain.day().data[..]); + assert_eq!( + &arr.truncate(TimePeriod::Day).data[..], + &plain.truncate(TimePeriod::Day).data[..] + ); + assert_eq!(&arr.add_months(1).unwrap().data[..], &plain.add_months(1).unwrap().data[..]); + } + + #[test] + fn test_offsets_and_abbreviations_shift_the_wall_time_by_their_fixed_offset() { + // 2026-01-01 09:30:00 UTC. + let arr = zoned(&[1_767_259_800], "+05:30", TimeUnit::Seconds); + assert_eq!((arr.hour().data[0], arr.minute().data[0]), (15, 0)); + let arr = zoned(&[1_767_259_800], "-08:00", TimeUnit::Seconds); + assert_eq!((arr.day().data[0], arr.hour().data[0]), (1, 1)); + let arr = zoned(&[1_767_259_800], "AEST", TimeUnit::Seconds); + assert_eq!((arr.hour().data[0], arr.minute().data[0]), (19, 30)); + // The day starts at 14:00 UTC of the previous day at ten hours ahead of UTC. + assert_eq!(arr.truncate(TimePeriod::Day).data[0], 1_767_189_600); + } + + #[test] + fn test_printed_text_and_components_read_the_same_wall_time() { + for (tz, instant, fields, _) in COMPONENTS { + let arr = zoned(&[*instant], tz, TimeUnit::Seconds); + let text = Array::from_datetime_i64(arr.clone()).value_to_string(0); + // The text is `YYYY-MM-DD HH:MM:SS` followed by the offset and the time zone. + let printed: Vec = [0..4, 5..7, 8..10, 11..13, 14..16, 17..19] + .into_iter() + .map(|range| text[range].parse().unwrap()) + .collect(); + assert_eq!(printed, fields[..6], "{tz} at {instant} prints {text}"); + assert_eq!(components(&arr, 0)[..6], fields[..6]); + } + } +} diff --git a/src/structs/variants/datetime/tz.rs b/src/structs/variants/datetime/tz.rs index 1c9ef33..245574b 100644 --- a/src/structs/variants/datetime/tz.rs +++ b/src/structs/variants/datetime/tz.rs @@ -30,6 +30,8 @@ //! This module is part of the `time_zones` feature, which compiles the IANA //! Time Zone Database into the binary and adds about 400 KB to it. +use tzdb_data::find_tz; + /// Returns the fixed UTC offset of a time zone abbreviation in `±HH:MM` form. /// /// Returns `None` for text that is not a listed abbreviation. @@ -108,6 +110,132 @@ pub fn abbreviation_offset(abbreviation: &str) -> Option<&'static str> { Some(offset) } +/// Returns the UTC offset of the time zone text `tz`, in seconds, as a function +/// of the instant in seconds since the Unix epoch. +/// +/// The time zone is resolved once, and the returned function is called for +/// each instant. +/// +/// ## Behaviour +/// - Time zone abbreviations listed in `abbreviation_offset` have their fixed offset. +/// - IANA identifiers have the offset of each instant from the IANA Time Zone +/// Database, which includes daylight saving and historical transitions. +/// - `UTC`, `Z` and offsets such as `+05:00` and `+0530` have that offset. +/// +/// Returns `None` for any other text. +pub(crate) fn utc_offset_seconds(tz: &str) -> Option i64> { + let zone = match abbreviation_offset(tz) { + Some(_) => None, + None => find_tz(tz.as_bytes()), + }; + let fixed = match zone { + Some(_) => 0, + None => offset_text_seconds(abbreviation_offset(tz).unwrap_or(tz))?, + }; + Some(move |unix_seconds: i64| match zone { + Some(zone) => zone + .find_local_time_type(unix_seconds) + .map_or(0, |local| i64::from(local.ut_offset())), + None => fixed, + }) +} + +/// Returns the offset in seconds of offset text such as `+05:00`, `-0800`, +/// `UTC` and `Z`, or `None` for any other text. +fn offset_text_seconds(text: &str) -> Option { + let text = text.trim(); + + // Handle UTC specially + if text.eq_ignore_ascii_case("UTC") || text.eq_ignore_ascii_case("Z") { + return Some(0); + } + + // Parse offset strings like "+05:00", "-08:00", "+0530" + if !text.starts_with('+') && !text.starts_with('-') { + return None; + } + + let (sign, rest) = text.split_at(1); + let sign = if sign == "+" { 1 } else { -1 }; + + // Try parsing HH:MM format + if let Some((hours_str, mins_str)) = rest.split_once(':') { + let hours: i8 = hours_str.parse().ok()?; + let mins: i8 = mins_str.parse().ok()?; + return Some(sign * (hours as i64 * 3600 + mins as i64 * 60)); + } + + // Try parsing HHMM format + if rest.len() == 4 { + let hours: i8 = rest[0..2].parse().ok()?; + let mins: i8 = rest[2..4].parse().ok()?; + return Some(sign * (hours as i64 * 3600 + mins as i64 * 60)); + } + + None +} + +/// Seconds either side of a wall time within which its instants lie. +/// +/// UTC offsets in the IANA Time Zone Database are within 16 hours of UTC, and +/// consecutive transitions of a time zone are more than 32 hours apart. +const WALL_TIME_WINDOW: i64 = 16 * 3_600; + +/// Returns the instants, in seconds since the Unix epoch, for the wall time +/// `wall_seconds` of a time zone. +/// +/// `offset_seconds` is the function that `utc_offset_seconds` returns for the +/// time zone, and `wall_seconds` is the wall time as seconds since the Unix +/// epoch on the wall clock. +/// +/// ## Behaviour +/// - Wall times that occur once return their instant in both positions. +/// - Wall times that occur twice, where the clocks move back, return the +/// earlier instant in both positions. +/// - Wall times that are skipped, where the clocks move forward, return the +/// instant of the transition first. The second position reads the wall time +/// with the offset in force before the transition, which is later than the +/// transition by the distance of the wall time into the skipped interval. +/// +/// The first position is therefore the first instant at which the wall clock +/// reads `wall_seconds` or later. +pub(crate) fn wall_time_instants( + offset_seconds: &impl Fn(i64) -> i64, + wall_seconds: i64, +) -> (i64, i64) { + let before = offset_seconds(wall_seconds.saturating_sub(WALL_TIME_WINDOW)); + let after = offset_seconds(wall_seconds.saturating_add(WALL_TIME_WINDOW)); + let with_before = wall_seconds.saturating_sub(before); + let with_after = wall_seconds.saturating_sub(after); + if before == after { + return (with_before, with_before); + } + let before_holds = offset_seconds(with_before) == before; + let after_holds = offset_seconds(with_after) == after; + match (before_holds, after_holds) { + (true, true) => { + let first = with_before.min(with_after); + (first, first) + } + (true, false) => (with_before, with_before), + (false, true) => (with_after, with_after), + (false, false) => { + // The wall time is skipped. The transition is the first instant in + // `(with_after, with_before]` at the offset in force after it. + let (mut low, mut high) = (with_after, with_before); + while high - low > 1 { + let middle = low + (high - low) / 2; + if offset_seconds(middle) == after { + high = middle; + } else { + low = middle; + } + } + (high, with_before) + } + } +} + #[cfg(test)] mod tests { use super::*; @@ -122,6 +250,25 @@ mod tests { assert_eq!(abbreviation_offset("JST"), Some("+09:00")); } + // `wall_time_instants` reads the offsets 16 hours either side of a wall time. + #[test] + fn test_database_offsets_and_transitions_fit_the_wall_time_window() { + for name in tzdb_data::TZ_NAMES { + let zone = find_tz(name.as_bytes()).unwrap(); + for local in zone.local_time_types() { + assert!( + i64::from(local.ut_offset()).abs() < WALL_TIME_WINDOW, + "{name} has the offset {}", + local.ut_offset() + ); + } + for pair in zone.transitions().windows(2) { + let apart = pair[1].unix_leap_time() - pair[0].unix_leap_time(); + assert!(apart > 2 * WALL_TIME_WINDOW, "{name} has transitions {apart} seconds apart"); + } + } + } + #[test] fn test_text_other_than_abbreviations_has_no_offset() { assert_eq!(abbreviation_offset("Australia/Sydney"), None); diff --git a/src/structs/views/collections/temporal_array_view.rs b/src/structs/views/collections/temporal_array_view.rs index 95d45f0..6a16c5f 100644 --- a/src/structs/views/collections/temporal_array_view.rs +++ b/src/structs/views/collections/temporal_array_view.rs @@ -470,10 +470,14 @@ macro_rules! windowed_component { macro_rules! windowed_component_inner { ($arr:expr, $offset:expr, $len:expr, $extract:expr) => {{ let mut result = IntegerArray::with_capacity($len, $arr.is_nullable()); + let wall_time_offset = $arr.wall_time_offset(); for i in $offset..$offset + $len { if $arr.is_null(i) { result.push_null(); - } else if let Some(val_i64) = $arr.data[i].to_i64() { + } else if let Some(val_i64) = $arr.data[i] + .to_i64() + .and_then(|v| v.checked_add(wall_time_offset(v))) + { if let Some(dt) = DatetimeArray::::i64_to_datetime(val_i64, $arr.time_unit()) { #[allow(clippy::redundant_closure_call)] result.push(($extract)(&dt)); @@ -704,10 +708,13 @@ fn is_leap_year_windowed( len: usize, ) -> BooleanArray<()> { let mut result = BooleanArray::with_capacity(len, arr.is_nullable()); + let wall_time_offset = arr.wall_time_offset(); for i in offset..offset + len { if arr.is_null(i) { result.push_null(); - } else if let Some(val_i64) = arr.data[i].to_i64() { + } else if let Some(val_i64) = + arr.data[i].to_i64().and_then(|v| v.checked_add(wall_time_offset(v))) + { if let Some(dt) = DatetimeArray::::i64_to_datetime(val_i64, arr.time_unit()) { result.push(time::util::is_leap_year(dt.year())); } else { diff --git a/src/traits/print.rs b/src/traits/print.rs index 06c6f43..6d24c05 100644 --- a/src/traits/print.rs +++ b/src/traits/print.rs @@ -441,62 +441,15 @@ where format!("{v}{suffix}") } -/// Returns the UTC offset in effect at `unix_seconds` for the time zone text `tz`. -/// -/// ## Behaviour -/// - Time zone abbreviations listed in `abbreviation_offset` return their fixed offset. -/// - IANA identifiers return the offset of that instant from the IANA Time -/// Zone Database, which includes daylight saving and historical transitions. -/// - `UTC`, `Z` and offsets such as `+05:00` and `+0530` return that offset. -/// -/// Returns `None` for any other text. +/// Returns the UTC offset in effect at `unix_seconds` for the time zone text +/// `tz`, or `None` for text that `utc_offset_seconds` does not resolve. #[cfg(feature = "time_zones")] fn timezone_offset(tz: &str, unix_seconds: i64) -> Option { - use crate::structs::variants::datetime::tz::abbreviation_offset; + use crate::structs::variants::datetime::tz::utc_offset_seconds; use time::UtcOffset; - let tz = match abbreviation_offset(tz) { - Some(offset) => offset, - None => { - if let Some(zone) = tzdb_data::find_tz(tz.as_bytes()) { - let seconds = zone.find_local_time_type(unix_seconds).ok()?.ut_offset(); - return UtcOffset::from_whole_seconds(seconds).ok(); - } - tz - } - } - .trim(); - - // Handle UTC specially - if tz.eq_ignore_ascii_case("UTC") || tz.eq_ignore_ascii_case("Z") { - return Some(UtcOffset::UTC); - } - - // Parse offset strings like "+05:00", "-08:00", "+0530" - if !tz.starts_with('+') && !tz.starts_with('-') { - return None; - } - - let (sign, rest) = tz.split_at(1); - let sign = if sign == "+" { 1 } else { -1 }; - - // Try parsing HH:MM format - if let Some((hours_str, mins_str)) = rest.split_once(':') { - let hours: i8 = hours_str.parse().ok()?; - let mins: i8 = mins_str.parse().ok()?; - let seconds = sign * (hours as i32 * 3600 + mins as i32 * 60); - return UtcOffset::from_whole_seconds(seconds).ok(); - } - - // Try parsing HHMM format - if rest.len() == 4 { - let hours: i8 = rest[0..2].parse().ok()?; - let mins: i8 = rest[2..4].parse().ok()?; - let seconds = sign * (hours as i32 * 3600 + mins as i32 * 60); - return UtcOffset::from_whole_seconds(seconds).ok(); - } - - None + let seconds = utc_offset_seconds(tz)?(unix_seconds); + UtcOffset::from_whole_seconds(i32::try_from(seconds).ok()?).ok() } #[cfg(test)] From cb830ee841f44d883a19b5c47f0ac55e55c286c7 Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 20 Nov 2026 05:28:01 +0000 Subject: [PATCH 10/13] Reuse time zone offsets across days with one offset --- src/structs/variants/datetime/datetime_ops.rs | 49 +++++++++++++++++ src/structs/variants/datetime/tz.rs | 54 +++++++++++++++++-- 2 files changed, 99 insertions(+), 4 deletions(-) diff --git a/src/structs/variants/datetime/datetime_ops.rs b/src/structs/variants/datetime/datetime_ops.rs index a2a61b4..130299f 100644 --- a/src/structs/variants/datetime/datetime_ops.rs +++ b/src/structs/variants/datetime/datetime_ops.rs @@ -2695,6 +2695,55 @@ mod time_zone_tests { } } + // Arrays of many rows reuse the offsets of the days they have read. Each row + // must equal the result of an array holding that row alone, in time order, + // in reverse order and in an order that moves between distant days. + #[test] + fn test_rows_of_one_array_equal_the_results_of_single_row_arrays() { + for tz in ["Australia/Sydney", "America/New_York", "Australia/Lord_Howe", "America/Havana"] { + // Every 20 minutes from 20 days before to 20 days after each transition of 2026. + let transitions: Vec = TRUNCATIONS + .iter() + .filter(|row| row.0 == tz && row.1 == "day") + .map(|row| row.2) + .collect(); + let mut values: Vec = Vec::new(); + for transition in [transitions[3], transitions[transitions.len() - 3]] { + values.extend((-1_440..1_440).map(|step| transition + step * 1_200)); + } + let reversed: Vec = values.iter().rev().copied().collect(); + let half = values.len() / 2; + let interleaved: Vec = (0..half).flat_map(|i| [values[i], values[half + i]]).collect(); + + for order in [&values, &reversed, &interleaved] { + let arr = zoned(order, tz, TimeUnit::Seconds); + let hours = arr.hour(); + let days = arr.truncate(TimePeriod::Day); + let months = arr.truncate(TimePeriod::Month); + let added = arr.add_months(1).unwrap(); + for (i, value) in order.iter().enumerate() { + let single = zoned(&[*value], tz, TimeUnit::Seconds); + assert_eq!(hours.data[i], single.hour().data[0], "{tz} hour at {value}"); + assert_eq!( + days.data[i], + single.truncate(TimePeriod::Day).data[0], + "{tz} day at {value}" + ); + assert_eq!( + months.data[i], + single.truncate(TimePeriod::Month).data[0], + "{tz} month at {value}" + ); + assert_eq!( + added.data[i], + single.add_months(1).unwrap().data[0], + "{tz} plus one month at {value}" + ); + } + } + } + } + #[test] fn test_output_buffer_kernels_read_the_wall_time_of_the_time_zone() { let rows: Vec<&(&str, i64, [i32; 11], bool)> = COMPONENTS diff --git a/src/structs/variants/datetime/tz.rs b/src/structs/variants/datetime/tz.rs index 245574b..df743a1 100644 --- a/src/structs/variants/datetime/tz.rs +++ b/src/structs/variants/datetime/tz.rs @@ -30,8 +30,12 @@ //! This module is part of the `time_zones` feature, which compiles the IANA //! Time Zone Database into the binary and adds about 400 KB to it. +use std::cell::Cell; + use tzdb_data::find_tz; +const SECONDS_PER_DAY: i64 = 86_400; + /// Returns the fixed UTC offset of a time zone abbreviation in `±HH:MM` form. /// /// Returns `None` for text that is not a listed abbreviation. @@ -114,7 +118,10 @@ pub fn abbreviation_offset(abbreviation: &str) -> Option<&'static str> { /// of the instant in seconds since the Unix epoch. /// /// The time zone is resolved once, and the returned function is called for -/// each instant. +/// each instant. The function remembers the ranges of UTC days that it has +/// found to have one offset throughout, and instants in those ranges reuse the +/// offset. Values in time order therefore search the database about once per +/// day of data. /// /// ## Behaviour /// - Time zone abbreviations listed in `abbreviation_offset` have their fixed offset. @@ -132,10 +139,49 @@ pub(crate) fn utc_offset_seconds(tz: &str) -> Option i64> { Some(_) => 0, None => offset_text_seconds(abbreviation_offset(tz).unwrap_or(tz))?, }; + // Two ranges of UTC days found to have one offset throughout, as the first + // day, the last day and the offset. A range is empty when its first day is + // after its last day. Truncation and month arithmetic read offsets near their + // input and near their result, which the two ranges hold apart. + let ranges = Cell::new([(1i64, 0i64, 0i64); 2]); Some(move |unix_seconds: i64| match zone { - Some(zone) => zone - .find_local_time_type(unix_seconds) - .map_or(0, |local| i64::from(local.ut_offset())), + Some(zone) => { + let offset_at = |seconds: i64| { + zone.find_local_time_type(seconds) + .map_or(0, |local| i64::from(local.ut_offset())) + }; + let day = unix_seconds.div_euclid(SECONDS_PER_DAY); + let mut found = ranges.get(); + for (first_day, last_day, offset) in found { + if first_day <= day && day <= last_day { + return offset; + } + } + // Transitions are more than a day apart, so equal offsets at the first + // and last second of a day hold for the whole day. + let day_start = day.saturating_mul(SECONDS_PER_DAY); + let first = offset_at(day_start); + let last = offset_at(day_start.saturating_add(SECONDS_PER_DAY - 1)); + if first != last { + return offset_at(unix_seconds); + } + // The day extends a range that it adjoins at the same offset, and + // otherwise replaces the range found less recently. + let adjoined = found.iter_mut().find(|(first_day, last_day, offset)| { + first_day <= last_day + && *offset == first + && (day == last_day.saturating_add(1) || day.saturating_add(1) == *first_day) + }); + match adjoined { + Some(range) => { + range.0 = range.0.min(day); + range.1 = range.1.max(day); + } + None => found = [(day, day, first), found[0]], + } + ranges.set(found); + first + } None => fixed, }) } From 61cfa95f9bcf73b59a01065d47dce0fdbe281a89 Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 20 Nov 2026 06:00:02 +0000 Subject: [PATCH 11/13] State the binary size of time_zones once --- Cargo.toml | 3 +-- README.md | 2 +- src/structs/variants/datetime/tz.rs | 2 +- src/traits/print.rs | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 47425f9..d6cf092 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,6 @@ polars-core = { version = "0.55.2", default-features = false, features = [ polars-arrow = { version = "0.55.2", optional = true } time = { version = "0.3", optional = true, features = ["parsing"] } # IANA Time Zone Database as static data, for the `time_zones` feature. -# Adds about 400 KB to the binary. tzdb_data = { version = "0.2.5", optional = true } num-traits = "0.2.19" rayon = { version = "1.11.0", optional = true } @@ -223,7 +222,7 @@ datetime_ops = ["dep:time", "datetime"] # of the time zone # # Stored values stay UTC integers. The IANA Time Zone Database is compiled into the -# binary as static data, which adds about 400 KB to the binary. +# binary as static data, which adds about 440 KB to a release binary. # # Without this feature, timestamps with a time zone are printed and computed in UTC. time_zones = ["datetime_ops", "dep:tzdb_data"] diff --git a/README.md b/README.md index 25a8ace..b5b7c88 100644 --- a/README.md +++ b/README.md @@ -260,7 +260,7 @@ Additional types: |---------|-------------| | `datetime` | Temporal array types as raw integer offsets | | `datetime_ops` | Datetime library functionality: ISO 8601 parsing, timezone-aware operations, arithmetic, component extraction | -| `time_zones` | Time zone conversion through the IANA Time Zone Database, including daylight saving and historical transitions. Display, component extraction, truncation and month arithmetic use the wall time of the time zone, and stored values stay UTC. Adds about 400 KB to the binary. Without it, timestamps with a time zone are printed and computed in UTC | +| `time_zones` | Time zone conversion through the IANA Time Zone Database, including daylight saving and historical transitions. Display, component extraction, truncation and month arithmetic use the wall time of the time zone, and stored values stay UTC. Without it, timestamps with a time zone are printed and computed in UTC | | `extended_numeric_types` | i8, i16, u8, u16 variants | | `default_categorical_8` | 8-bit default categorical width, with Categorical8 and Categorical32 both available | | `extended_categorical` | Adds Categorical16 and Categorical64 dictionary index widths | diff --git a/src/structs/variants/datetime/tz.rs b/src/structs/variants/datetime/tz.rs index df743a1..9738832 100644 --- a/src/structs/variants/datetime/tz.rs +++ b/src/structs/variants/datetime/tz.rs @@ -28,7 +28,7 @@ //! where an exact reading is required. //! //! This module is part of the `time_zones` feature, which compiles the IANA -//! Time Zone Database into the binary and adds about 400 KB to it. +//! Time Zone Database into the binary. use std::cell::Cell; diff --git a/src/traits/print.rs b/src/traits/print.rs index 6d24c05..0b709e8 100644 --- a/src/traits/print.rs +++ b/src/traits/print.rs @@ -307,7 +307,7 @@ pub(crate) fn print_ndarray_body( /// - `Duration32` and `Duration64` print the stored count with its time unit /// suffix, as in `90s`. /// -/// With `time_zones`, which adds about 400 KB to the binary: +/// With `time_zones`: /// - Timestamps with a time zone print the wall time of that time zone and /// its UTC offset at that instant, as in `2026-01-01 14:30:00+05:00`. Time /// zone text other than an offset follows the value, as in From b5af82ddac7f6d85c430fc7451a76198af22a7dd Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 20 Nov 2026 06:11:03 +0000 Subject: [PATCH 12/13] Update Cargo.toml --- Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d6cf092..b3a0391 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -221,8 +221,9 @@ datetime_ops = ["dep:time", "datetime"] # - Display, component extraction, truncation and month arithmetic on the wall time # of the time zone # -# Stored values stay UTC integers. The IANA Time Zone Database is compiled into the -# binary as static data, which adds about 440 KB to a release binary. +# Stored values are still UTC integers with this feature on. The IANA Time Zone Database +# is compiled into the binary as static data, which adds about 440 KB to the release binary +# (roughly ~%40 of the total size). # # Without this feature, timestamps with a time zone are printed and computed in UTC. time_zones = ["datetime_ops", "dep:tzdb_data"] From dc06c622483508f81749e06869a3a03e57a02d29 Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 20 Nov 2026 06:13:29 +0000 Subject: [PATCH 13/13] Reword the time zone doc comments --- src/kernels/datetime.rs | 5 +- src/structs/variants/datetime/datetime_ops.rs | 41 +++++---- src/structs/variants/datetime/tz.rs | 89 ++++++++++--------- src/traits/print.rs | 10 +-- 4 files changed, 75 insertions(+), 70 deletions(-) diff --git a/src/kernels/datetime.rs b/src/kernels/datetime.rs index bfe38f7..f6cf30a 100644 --- a/src/kernels/datetime.rs +++ b/src/kernels/datetime.rs @@ -102,8 +102,9 @@ pub fn truncate_into( v.checked_add(offset) .and_then(|wall| floor_calendar(wall, period, per_second)) .and_then(|floored| { - // The offset of the input is in force at the start of - // the period unless a transition lies between them. + // Use the input's offset for the start of the period. + // Resolve the wall time when a transition lies between + // the start of the period and the input. let value = floored.checked_sub(offset)?; if wall_time_offset(value) == offset { Some(value) diff --git a/src/structs/variants/datetime/datetime_ops.rs b/src/structs/variants/datetime/datetime_ops.rs index 130299f..fd69a28 100644 --- a/src/structs/variants/datetime/datetime_ops.rs +++ b/src/structs/variants/datetime/datetime_ops.rs @@ -114,15 +114,15 @@ impl DatetimeArray { } } - /// Returns the UTC offset of each stored value, in the array's time unit, as - /// a function of the stored value. + /// Returns the UTC offset lookup for the array's time zone. /// - /// Stored values are UTC. A stored value plus its offset is the wall time of - /// the array's time zone in the same unit, and the calendar arithmetic of the - /// kernels reads that sum as it reads a UTC value. + /// The lookup receives a stored UTC value and returns the offset of the time + /// zone at that instant, in the array's time unit. Adding the offset to the + /// stored value produces the wall time in the same unit. The kernels run + /// their calendar arithmetic on that wall time, and stored values stay in UTC. /// - /// The offset is 0 for arrays without a time zone, for time zone text that - /// `utc_offset_seconds` does not resolve, and without the `time_zones` feature. + /// The offset is 0 when the array has no time zone, when `utc_offset_seconds` + /// cannot resolve the time zone text, and when the `time_zones` feature is off. pub(crate) fn wall_time_offset(&self) -> impl Fn(i64) -> i64 { #[cfg(feature = "time_zones")] { @@ -145,18 +145,19 @@ impl DatetimeArray { } } - /// Returns the stored UTC values for a wall time of the array's time zone, as - /// a function of the wall time in the array's time unit. + /// Returns the conversion from wall times of the array's time zone to stored + /// UTC values. /// - /// The two values are those of `wall_time_instants`. The first is the first - /// stored value at which the wall clock reads the wall time or later, which - /// truncation writes for period starts on the other side of a transition from - /// their input. The second reads skipped wall times with the offset in force - /// before the transition, which calendar arithmetic writes. + /// The conversion receives a wall time in the array's time unit and returns + /// two UTC values, as `wall_time_instants` defines them: + /// - The first value is the earliest UTC value where the wall clock shows the + /// wall time or later. Truncation uses it. + /// - The second value resolves skipped wall times with the offset from before + /// the transition. Month arithmetic uses it. /// - /// Both values are the wall time itself for arrays without a time zone, for - /// time zone text that `utc_offset_seconds` does not resolve, and without the - /// `time_zones` feature. + /// Both values equal the wall time when the array has no time zone, when + /// `utc_offset_seconds` cannot resolve the time zone text, and when the + /// `time_zones` feature is off. pub(crate) fn wall_time_values(&self) -> impl Fn(i64) -> (i64, i64) { #[cfg(feature = "time_zones")] { @@ -188,8 +189,10 @@ impl DatetimeArray { } } - /// Returns the number of stored values per second for `unit`, or `None` for - /// the `Days` unit, which is not a unit of timestamps with a time zone. + /// Returns the number of stored values per second for `unit`. + /// + /// Returns `None` for `Days`, because timestamps with a time zone are not + /// stored in days. #[cfg(feature = "time_zones")] fn values_per_second(unit: TimeUnit) -> Option { match unit { diff --git a/src/structs/variants/datetime/tz.rs b/src/structs/variants/datetime/tz.rs index 9738832..3e686b8 100644 --- a/src/structs/variants/datetime/tz.rs +++ b/src/structs/variants/datetime/tz.rs @@ -17,10 +17,10 @@ //! Maps time zone abbreviations, such as `AEST` and `EDT`, to their fixed UTC //! offsets. //! -//! IANA identifiers, such as `Australia/Sydney`, are resolved through the IANA -//! Time Zone Database, which includes daylight saving and historical -//! transitions. Abbreviations refer to one offset throughout the year, and are -//! listed in this module. +//! IANA identifiers, such as `Australia/Sydney`, use the IANA Time Zone +//! Database, including daylight saving and historical transitions. +//! Abbreviations refer to one offset throughout the year, and are listed in +//! this module. //! //! Some abbreviations are ambiguous. For example, `CST` refers to Central //! Standard Time, China Standard Time and Cuba Standard Time. The most common @@ -114,22 +114,23 @@ pub fn abbreviation_offset(abbreviation: &str) -> Option<&'static str> { Some(offset) } -/// Returns the UTC offset of the time zone text `tz`, in seconds, as a function -/// of the instant in seconds since the Unix epoch. +/// Resolves the time zone text `tz` and returns its UTC offset lookup. /// -/// The time zone is resolved once, and the returned function is called for -/// each instant. The function remembers the ranges of UTC days that it has -/// found to have one offset throughout, and instants in those ranges reuse the -/// offset. Values in time order therefore search the database about once per -/// day of data. +/// The lookup receives an instant in seconds since the Unix epoch and returns +/// the UTC offset in seconds at that instant. The time zone is resolved once +/// here, and the kernels call the lookup for each row. /// /// ## Behaviour -/// - Time zone abbreviations listed in `abbreviation_offset` have their fixed offset. -/// - IANA identifiers have the offset of each instant from the IANA Time Zone -/// Database, which includes daylight saving and historical transitions. -/// - `UTC`, `Z` and offsets such as `+05:00` and `+0530` have that offset. +/// - Abbreviations listed in `abbreviation_offset` use their fixed offset. +/// - IANA identifiers use the IANA Time Zone Database, including daylight +/// saving and historical transitions. +/// - `UTC`, `Z` and offsets such as `+05:00` and `+0530` use that offset. +/// - Any other text returns `None`. /// -/// Returns `None` for any other text. +/// ## Details +/// - The lookup keeps two ranges of UTC days that each have a single offset. +/// Instants inside those ranges return the offset without a database search. +/// - Days that contain a transition are searched for every instant. pub(crate) fn utc_offset_seconds(tz: &str) -> Option i64> { let zone = match abbreviation_offset(tz) { Some(_) => None, @@ -139,10 +140,10 @@ pub(crate) fn utc_offset_seconds(tz: &str) -> Option i64> { Some(_) => 0, None => offset_text_seconds(abbreviation_offset(tz).unwrap_or(tz))?, }; - // Two ranges of UTC days found to have one offset throughout, as the first - // day, the last day and the offset. A range is empty when its first day is - // after its last day. Truncation and month arithmetic read offsets near their - // input and near their result, which the two ranges hold apart. + // Cache of two ranges of UTC days that each have a single offset, stored as + // (first day, last day, offset). An empty range has its first day after its + // last day. Two ranges are kept because truncation and month arithmetic look + // up offsets near the input and near the result. let ranges = Cell::new([(1i64, 0i64, 0i64); 2]); Some(move |unix_seconds: i64| match zone { Some(zone) => { @@ -165,8 +166,8 @@ pub(crate) fn utc_offset_seconds(tz: &str) -> Option i64> { if first != last { return offset_at(unix_seconds); } - // The day extends a range that it adjoins at the same offset, and - // otherwise replaces the range found less recently. + // Extend an adjacent range with the same offset. Otherwise replace + // the older range. let adjoined = found.iter_mut().find(|(first_day, last_day, offset)| { first_day <= last_day && *offset == first @@ -186,8 +187,9 @@ pub(crate) fn utc_offset_seconds(tz: &str) -> Option i64> { }) } -/// Returns the offset in seconds of offset text such as `+05:00`, `-0800`, -/// `UTC` and `Z`, or `None` for any other text. +/// Parses offset text such as `+05:00`, `-0800`, `UTC` and `Z` into seconds. +/// +/// Returns `None` for any other text. fn offset_text_seconds(text: &str) -> Option { let text = text.trim(); @@ -221,30 +223,29 @@ fn offset_text_seconds(text: &str) -> Option { None } -/// Seconds either side of a wall time within which its instants lie. +/// Search distance in seconds around a wall time when resolving its instants. /// -/// UTC offsets in the IANA Time Zone Database are within 16 hours of UTC, and -/// consecutive transitions of a time zone are more than 32 hours apart. +/// Every UTC offset in the IANA Time Zone Database is smaller than 16 hours, +/// and consecutive transitions of a time zone are more than 32 hours apart. +/// The search range around a wall time therefore holds at most one transition. const WALL_TIME_WINDOW: i64 = 16 * 3_600; -/// Returns the instants, in seconds since the Unix epoch, for the wall time -/// `wall_seconds` of a time zone. +/// Resolves the wall time `wall_seconds` of a time zone to instants. /// -/// `offset_seconds` is the function that `utc_offset_seconds` returns for the -/// time zone, and `wall_seconds` is the wall time as seconds since the Unix -/// epoch on the wall clock. +/// `offset_seconds` is the lookup from `utc_offset_seconds`. `wall_seconds` is +/// the wall clock reading in seconds since the Unix epoch. Both returned +/// instants are in seconds since the Unix epoch. /// -/// ## Behaviour -/// - Wall times that occur once return their instant in both positions. -/// - Wall times that occur twice, where the clocks move back, return the -/// earlier instant in both positions. -/// - Wall times that are skipped, where the clocks move forward, return the -/// instant of the transition first. The second position reads the wall time -/// with the offset in force before the transition, which is later than the -/// transition by the distance of the wall time into the skipped interval. +/// Most wall times map to one instant, and both values are that instant. The +/// two values differ only for wall times that a transition skips. /// -/// The first position is therefore the first instant at which the wall clock -/// reads `wall_seconds` or later. +/// ## Behaviour +/// - Wall times that occur once: both values are that instant. +/// - Wall times that occur twice, when clocks move back: both values are the +/// earlier instant. +/// - Wall times that are skipped, when clocks move forward: the first value is +/// the instant of the transition. The second value applies the offset from +/// before the transition, and is later than the transition. pub(crate) fn wall_time_instants( offset_seconds: &impl Fn(i64) -> i64, wall_seconds: i64, @@ -266,8 +267,8 @@ pub(crate) fn wall_time_instants( (true, false) => (with_before, with_before), (false, true) => (with_after, with_after), (false, false) => { - // The wall time is skipped. The transition is the first instant in - // `(with_after, with_before]` at the offset in force after it. + // The wall time is skipped. Find the transition, the first instant + // in `(with_after, with_before]` that has the later offset. let (mut low, mut high) = (with_after, with_before); while high - low > 1 { let middle = low + (high - low) / 2; diff --git a/src/traits/print.rs b/src/traits/print.rs index 0b709e8..8a39508 100644 --- a/src/traits/print.rs +++ b/src/traits/print.rs @@ -312,11 +312,11 @@ pub(crate) fn print_ndarray_body( /// its UTC offset at that instant, as in `2026-01-01 14:30:00+05:00`. Time /// zone text other than an offset follows the value, as in /// `2026-01-01 20:30:00+11:00 Australia/Sydney`. -/// - IANA identifiers are resolved through the IANA Time Zone Database, which -/// includes daylight saving and historical transitions. The same time zone -/// therefore prints `+11:00` in January and `+10:00` in July for Sydney. -/// - Offsets with seconds, which occur before standard time was adopted, -/// print as `+HH:MM:SS`. +/// - IANA identifiers use the IANA Time Zone Database, including daylight +/// saving and historical transitions. Sydney prints `+11:00` in January and +/// `+10:00` in July. +/// - Offsets from before standard time can include seconds, and print as +/// `+HH:MM:SS`. /// - Time zone text that is not an offset, an abbreviation or an IANA /// identifier prints the UTC value with `+00:00` and without that text. ///