Fix timezone handling in to_timestamp functions#136
Merged
rampage644 merged 2 commits intomainfrom Apr 23, 2026
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes timezone handling in the
to_timestampfamily 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_ntzshould strip timezone information).Key Changes
return_type()to preserve the input timestamp's unit while applying the function's timezone policy, rather than returning the input type unchangedinvoke()to cast timestamp inputs to the target timezone when they differ from the function's policyquery_timestamp_with_timezone_to_timestampto reflect correct behavior (timestamp without timezone indicator instead of with 'Z' suffix)Implementation Details
self.timezone()to enforce the function's timezone semanticscast_with_options()when the input timezone differs from the target timezoneto_timestamp_ntzproperly strip timezone information from timestamp inputs, whileto_timestampvariants apply their respective timezone policieshttps://claude.ai/code/session_01YUH8HvzyjxmHtjrNcALJXj