Skip to content

fix: handle ambiguous and non-existent local times#3865

Open
matthewalex4 wants to merge 6 commits intoapache:mainfrom
matthewalex4:fix-ambiguous-time-early
Open

fix: handle ambiguous and non-existent local times#3865
matthewalex4 wants to merge 6 commits intoapache:mainfrom
matthewalex4:fix-ambiguous-time-early

Conversation

@matthewalex4
Copy link
Copy Markdown

Which issue does this PR close?

Closes #3864.

Rationale for this change

timestamp_ntz_to_timestamp panics when a local time is ambiguous or non-existent due to DST transitions. Further explanation in issue description.

What changes are included in this PR?

  • The result of from_local_datetime(...) is handled for cases of ambiguous and non-existent local times.
  • For ambiguous local times we choose the earlier option
  • For non-existent local times we shift to an hour before, convert and shift back

How are these changes tested?

Unit tests provided for both ambiguous and non-existent local times.

@matthewalex4 matthewalex4 changed the title fix: handle ambiguous and non-existent local times in timestamp_ntz_to_timestamp fix: handle ambiguous and non-existent local times Apr 1, 2026
LocalResult::Ambiguous(dt, _) => dt,
LocalResult::None => {
// Interpret nonexistent local time by shifting from one hour earlier.
let shift = TimeDelta::hours(1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 1-hour shift works for standard DST transitions, but some timezones have non-standard gaps (e.g., Australia/Lord_Howe has a 30-minute DST transition). Yes, this is an edge case so it may be fine to ignore, but we should at least document this as an incompatibility.

https://www.timeanddate.com/time/change/australia/lord-howe-island

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment in d622e44

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm handling the DST gap in #3884. Perhaps you can wait for this to pass CI and then re-use.


#[test]
fn test_timestamp_ntz_to_timestamp_handles_non_existent_time() {
let result = std::panic::catch_unwind(|| {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do these tests still need catch_unwind?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No not necessary, removed in d622e44

@andygrove
Copy link
Copy Markdown
Member

Thanks @matthewalex4. Could you also add an end-to-end Spark test, perhaps in CometTemporalExpressionSuite?

@matthewalex4
Copy link
Copy Markdown
Author

Thanks @matthewalex4. Could you also add an end-to-end Spark test, perhaps in CometTemporalExpressionSuite?

Yes, have added a test in 998f975

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

timestamp_ntz_to_timestamp panics on ambiguous or non-existent local times (DST transitions)

3 participants