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 1/9] 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 2/9] 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 3/9] 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 4/9] 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 5/9] 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 6/9] 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 7/9] 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 8/9] 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 74f2abdd16e00f610e9b44dc9578d5470757cd3a Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 20 Nov 2026 04:31:17 +0000 Subject: [PATCH 9/9] Print timestamps with a time zone in UTC, leaving time zone conversion to a separate change --- Cargo.lock | 70 ++- Cargo.toml | 17 +- README.md | 1 - src/structs/variants/datetime/mod.rs | 1 - src/structs/variants/datetime/tz.rs | 676 +++++++++++++++++++++++---- src/traits/print.rs | 336 +------------ 6 files changed, 650 insertions(+), 451 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9f7e674..5a15162 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", + "phf 0.12.1", ] [[package]] @@ -616,6 +616,12 @@ 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" @@ -908,13 +914,13 @@ dependencies = [ "memchr", "num-traits", "parking_lot", + "phf 0.13.1", "polars-arrow", "polars-core", "rayon", "regex", "ryu", "time", - "tzdb_data", "vec64", ] @@ -1044,7 +1050,41 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "913273894cec178f401a31ec4b656318d95473527be05c0752cc41cdc32be8b7" dependencies = [ - "phf_shared", + "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", ] [[package]] @@ -1056,6 +1096,15 @@ 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" @@ -1702,21 +1751,6 @@ 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 6a484dc..2fad13b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,9 +41,7 @@ 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 `time_zones` feature. -# Adds about 400 KB to the binary. -tzdb_data = { version = "0.2.5", optional = true } +phf = { version = "0.13.1", features = ["macros"], optional = true } num-traits = "0.2.19" rayon = { version = "1.11.0", optional = true } ryu = { version = "1.0.23", optional = true } @@ -213,18 +211,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", "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"] +datetime_ops = ["dep:time", "dep:phf", "datetime"] # Adds string arithmetic kernels # Includes (small) external dependencies, and supports diff --git a/README.md b/README.md index 669cc09..3e25c85 100644 --- a/README.md +++ b/README.md @@ -260,7 +260,6 @@ 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 70f567f..a17a615 100644 --- a/src/structs/variants/datetime/mod.rs +++ b/src/structs/variants/datetime/mod.rs @@ -77,7 +77,6 @@ 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 1c9ef33..fc9c272 100644 --- a/src/structs/variants/datetime/tz.rs +++ b/src/structs/variants/datetime/tz.rs @@ -12,122 +12,602 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! # **Time Zone Abbreviations** - *Fixed UTC Offsets* +//! # **Timezone Database** - *IANA Timezone Mappings* //! -//! Maps time zone abbreviations, such as `AEST` and `EDT`, to their 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") //! -//! 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. +//! 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. //! -//! 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. -//! -//! 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. +//! If you would like to update a timezone, please file a PR or issue. + +#[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" }, -/// Returns the fixed UTC offset of a time zone abbreviation in `±HH:MM` form. + // 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 +/// +/// 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 +/// +/// # Arguments +/// * `tz_str` - Timezone string (e.g., "Australia/Sydney", "AEST", "+10:00") /// -/// Returns `None` for text that is not a listed abbreviation. +/// # Returns +/// Standard offset string in ±HH:MM format, or None if not found /// -/// # Example +/// # Examples /// ``` -/// use minarrow::structs::variants::datetime::tz::abbreviation_offset; +/// use minarrow::structs::variants::datetime::tz::lookup_timezone; /// -/// 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")] +/// # { +/// 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")); +/// # } /// ``` -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(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()) + } } +#[cfg(all(feature = "datetime", feature = "datetime_ops"))] #[cfg(test)] mod tests { use super::*; #[test] - 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")); + 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")); } #[test] - 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); + 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 + ); + } + } } } diff --git a/src/traits/print.rs b/src/traits/print.rs index 06c6f43..1064a0c 100644 --- a/src/traits/print.rs +++ b/src/traits/print.rs @@ -300,26 +300,13 @@ 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`. +/// - Timestamps with a time zone print their UTC value followed by `+00:00`, +/// 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 -/// `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. -/// /// 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`. @@ -336,7 +323,7 @@ where #[cfg(feature = "datetime_ops")] { use crate::Dt; - use time::{OffsetDateTime, UtcOffset}; + use time::OffsetDateTime; let unit = arr.time_unit(); let value = arr.data[idx].to_i64().unwrap(); @@ -351,16 +338,6 @@ where 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 => { @@ -369,44 +346,20 @@ where return format_date(dt); } } - Dt::Timestamp(_, None) => { + Dt::Timestamp(_, tz) => { if let Some(dt) = DatetimeArray::::i64_to_datetime(value, unit) { - return format_timestamp(dt); - } - } - 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 { - let seconds = local_dt.offset().whole_seconds(); - let sign = if seconds < 0 { '-' } else { '+' }; - let mut text = format!( - "{}{}{:02}:{:02}", - format_timestamp(local_dt), - sign, - seconds.abs() / 3_600, - seconds.abs() / 60 % 60 + // Timestamps are stored in UTC. Values with a time zone print + // that UTC value with its offset. + let offset = if tz.is_some() { "+00:00" } else { "" }; + return format!( + "{} {:02}:{:02}:{:02}{}{}", + format_date(dt), + dt.hour(), + dt.minute(), + dt.second(), + fraction(dt.nanosecond()), + offset ); - 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") - || tz.eq_ignore_ascii_case("Z"); - // 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 - }; } } Dt::Time32(_) | Dt::Time64(_) if value >= 0 && unit != TimeUnit::Days => { @@ -441,64 +394,6 @@ 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. -#[cfg(feature = "time_zones")] -fn timezone_offset(tz: &str, unix_seconds: i64) -> Option { - use crate::structs::variants::datetime::tz::abbreviation_offset; - 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 -} - #[cfg(test)] mod tests { use super::*; @@ -681,54 +576,11 @@ mod tests { ); } - #[cfg(feature = "time_zones")] - #[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.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"]); - } - - #[cfg(feature = "time_zones")] - #[test] - 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], - Dt::Timestamp(TimeUnit::Milliseconds, Some("Asia/Tokyo".into())), - ); - 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"]); - } - - #[cfg(all(feature = "datetime_ops", not(feature = "time_zones")))] + #[cfg(feature = "datetime_ops")] #[test] - fn test_timestamp_with_time_zone_prints_utc_value_without_time_zones() { + fn test_timestamp_with_time_zone_prints_utc_value_with_utc_offset() { use crate::{Dt, TimeUnit}; - for tz in ["+05:00", "AEST", "Asia/Tokyo", "Australia/Sydney", "UTC"] { + for tz in ["+05:00", "AEST", "Asia/Tokyo", "Australia/Sydney", "UTC", "Mars/Olympus_Mons"] { let arr = timestamp_array( &[Some(1_767_259_800), None], Dt::Timestamp(TimeUnit::Seconds, Some(tz.into())), @@ -742,158 +594,6 @@ mod tests { 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() { - 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 09:30:00+00:00", "null"], - ); - } - - // 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 = "time_zones")] - #[test] - 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 = "time_zones")] - #[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_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", - ], - ); - } - - // 1 January 2026 and 1 July 2026 at 09:30:00 UTC. - #[cfg(feature = "time_zones")] - const JANUARY: i64 = 1_767_259_800; - #[cfg(feature = "time_zones")] - const JULY: i64 = 1_782_898_200; - - #[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(); - let sign = if seconds < 0 { '-' } else { '+' }; - format!("{sign}{:02}:{:02}", seconds.abs() / 3_600, seconds.abs() / 60 % 60) - }) - } - - #[cfg(feature = "time_zones")] - #[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 = "time_zones")] - #[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 = "time_zones")] - #[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 = "time_zones")] - #[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 = "time_zones")] - #[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 = "time_zones")] - #[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() {