mzabaluev commented on issue #9183:
URL: https://github.com/apache/arrow-rs/issues/9183#issuecomment-5378450419
A somewhat pressing issue with `chrono-tz` is lack of support for tzdb
footer information, which leads to the DST not applied past tzdb's current
horizon of 2099. This diverges from Java's date formatter, for example.
Here's an example that demonstrates jiff is not susceptible to this issue.
However, it also shows jiff's more limited `-9999..=9999` year range:
```rust
use chrono::{Offset, TimeZone as _};
use chrono_tz::Tz;
use jiff::civil::date;
use jiff::tz::TimeZone;
fn jiff_offset(zone_name: &str, year: i32) -> String {
let Ok(year) = i16::try_from(year) else {
return "N/A (out of jiff's range)".to_string();
};
let tz = TimeZone::get(zone_name).expect("valid tz name");
let dt = date(year, 7, 15).at(12, 0, 0, 0);
match tz.to_zoned(dt) {
Ok(zoned) => zoned.offset().to_string(),
Err(_) => "N/A (out of jiff's range)".to_string(),
}
}
fn chrono_offset(zone_name: &str, year: i32) -> String {
let tz: Tz = zone_name.parse().expect("valid tz name");
match chrono::NaiveDate::from_ymd_opt(year, 7, 15).and_then(|d|
d.and_hms_opt(12, 0, 0)) {
Some(naive) => match tz.from_local_datetime(&naive) {
chrono::LocalResult::Single(dt) => dt.offset().fix().to_string(),
other => format!("{other:?}"),
},
None => "N/A (out of chrono's range)".to_string(),
}
}
fn check_zone(zone_name: &str) {
println!("{zone_name}:");
for year in [2099, 2100, 9999, 262_142] {
println!(
" {year}: jiff offset = {}, chrono_tz offset = {}",
jiff_offset(zone_name, year),
chrono_offset(zone_name, year),
);
}
}
fn main() {
for zone in ["Europe/Helsinki", "America/New_York", "Australia/Sydney"] {
check_zone(zone);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]