Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestamp Interval Arithmetic Ignores Timezone #4457

Closed
tustvold opened this issue Jun 28, 2023 · 3 comments · Fixed by #4546
Closed

Timestamp Interval Arithmetic Ignores Timezone #4457

tustvold opened this issue Jun 28, 2023 · 3 comments · Fixed by #4546
Labels
arrow Changes to the arrow crate bug

Comments

@tustvold
Copy link
Contributor

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

The timestamp arithmetic added in #4038 fails to correctly account for timezones

#[test]
fn test_timezone_interval() {
    let tz_str = "-01:00";
    let tz: Tz = tz_str.parse().unwrap();

    let array =
        TimestampNanosecondArray::from(vec![2419200000000000]).with_timezone(tz_str);

    let value = array.value_as_datetime_with_tz(0, tz).unwrap();
    assert_eq!(value.to_rfc3339(), "1970-01-28T23:00:00-01:00");

    // Add 1 month
    let interval = IntervalYearMonthArray::from(vec![1]);
    let date = add_dyn(&array, &interval).unwrap();
    let output = date.as_primitive::<TimestampNanosecondType>();

    let value = output.value_as_datetime_with_tz(0, tz).unwrap();
    assert_eq!(value.to_rfc3339(), "1970-02-28T23:00:00-01:00");
}

The above test should pass but it instead fails with the result 1970-02-27T23:00:00-01:00. This is because the month addition is done in the UTC epoch instead of the epoch of the array's timezone.

Describe the solution you'd like

Describe alternatives you've considered

Additional context

@tustvold tustvold added enhancement Any new improvement worthy of a entry in the changelog bug and removed enhancement Any new improvement worthy of a entry in the changelog labels Jun 28, 2023
@alexandreyc
Copy link
Contributor

I started working on this one 🐛

@tustvold
Copy link
Contributor Author

Thank you, let me know if you get stuck. I would recommend making use of https://docs.rs/arrow-array/latest/arrow_array/temporal_conversions/fn.as_datetime_with_timezone.html and punting the non-trivial timezone logic onto chrono. In particular correctly handling DST is complex

@tustvold
Copy link
Contributor Author

label_issue.py automatically added labels {'arrow'} from #4546

@tustvold tustvold added the arrow Changes to the arrow crate label Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants