Skip to content

Fix timezone handling in to_timestamp functions#136

Merged
rampage644 merged 2 commits intomainfrom
claude/rebase-pr-116-edHv3
Apr 23, 2026
Merged

Fix timezone handling in to_timestamp functions#136
rampage644 merged 2 commits intomainfrom
claude/rebase-pr-116-edHv3

Conversation

@rampage644
Copy link
Copy Markdown
Contributor

Summary

This PR fixes timezone handling in the to_timestamp family of functions to properly apply each function's timezone policy when the input is already a timestamp type. Previously, timestamp inputs were returned as-is without applying the target function's timezone semantics (e.g., to_timestamp_ntz should strip timezone information).

Key Changes

  • Schema inference fix: Updated return_type() to preserve the input timestamp's unit while applying the function's timezone policy, rather than returning the input type unchanged
  • Runtime evaluation fix: Added timezone conversion logic in invoke() to cast timestamp inputs to the target timezone when they differ from the function's policy
  • Test snapshot update: Updated expected output for query_timestamp_with_timezone_to_timestamp to reflect correct behavior (timestamp without timezone indicator instead of with 'Z' suffix)

Implementation Details

  • When a timestamp input is detected, the code now extracts the time unit and applies self.timezone() to enforce the function's timezone semantics
  • Added a cast operation using cast_with_options() when the input timezone differs from the target timezone
  • The fix ensures functions like to_timestamp_ntz properly strip timezone information from timestamp inputs, while to_timestamp variants apply their respective timezone policies
  • Minor cleanup: removed an outdated comment in test utilities

https://claude.ai/code/session_01YUH8HvzyjxmHtjrNcALJXj

rampage644 and others added 2 commits April 23, 2026 19:40
to_timestamp_ntz had early-return paths in return_field_from_args and
invoke_with_args that preserved the input timestamp type as-is, including
its timezone. This caused convert_timezone(...)::TIMESTAMP_NTZ to return
timestamp_tz instead of timestamp_ntz. Now both paths apply the function's
timezone policy via self.timezone(), which returns None for NTZ variants.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
TimeUnit implements Copy, so unit.clone() triggers clippy::clone_on_copy
(denied via clippy::all in workspace lints). Use *unit to satisfy the lint.

https://claude.ai/code/session_01YUH8HvzyjxmHtjrNcALJXj
@rampage644 rampage644 merged commit 7fbd000 into main Apr 23, 2026
3 checks passed
@rampage644 rampage644 deleted the claude/rebase-pr-116-edHv3 branch April 23, 2026 21:00
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.

2 participants