You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "MarcoGorelli (via GitHub)" <gi...@apache.org> on 2023/06/16 14:24:10 UTC
[GitHub] [arrow] MarcoGorelli commented on issue #36110: [C++][Python] Wrong result when converting time zones after 2038
MarcoGorelli commented on issue #36110:
URL: https://github.com/apache/arrow/issues/36110#issuecomment-1594774767
thanks for looking into this so deeply!
sure but the zoneinfo one still looks more correct? e.g. in the UK the DST transition happens on the last Sunday of October and of March, and (unfortunately) hasn't announced that they intend to change this. zoneinfo seems to extrapolate that correctly beyond 2038:
```python
In [29]:
...: string = '2058-10-28 00:00:00.000000'
...:
...: dt = datetime.fromisoformat(string)
...: dt = dt.replace(tzinfo=ZoneInfo('Europe/London'))
...: tz = ZoneInfo('UTC')
...: converted_dt = dt.astimezone(tz)
...: print(converted_dt)
2058-10-28 00:00:00+00:00
In [30]:
...: string = '2058-10-27 00:00:00.000000'
...:
...: dt = datetime.fromisoformat(string)
...: dt = dt.replace(tzinfo=ZoneInfo('Europe/London'))
...: tz = ZoneInfo('UTC')
...: converted_dt = dt.astimezone(tz)
...: print(converted_dt)
2058-10-26 23:00:00+00:00
In [31]: dt.strftime('%a')
Out[31]: 'Sun'
```
For reference, same with chrono-tz (haven't looked into how, but this is just to say - the fact `chrono-tz` extrapolates forwards differently to `arrow` explains the discrepancy when converting polars to pyarrow (or to pandas))
```Rust
use chrono::{NaiveDateTime, TimeZone};
use chrono_tz::Tz;
fn main() {
let dt = NaiveDateTime::parse_from_str("2058-10-28 00:00:00", "%Y-%m-%d %H:%M:%S").unwrap();
let tz = Tz::Europe__London;
let dt = tz.from_local_datetime(&dt).unwrap();
println!("converted: {:?}", dt);
let dt = NaiveDateTime::parse_from_str("2058-10-27 00:00:00", "%Y-%m-%d %H:%M:%S").unwrap();
let tz = Tz::Europe__London;
let dt = tz.from_local_datetime(&dt).unwrap();
println!("converted: {:?}", dt);
}
```
outputs
```
converted: 2058-10-28T00:00:00GMT
converted: 2058-10-27T00:00:00BST
```
---
copied from https://github.com/apache/arrow/issues/15047#issuecomment-1594706777
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org