feat: Add from_datetime method to Timestamp types#9345
Open
codephage2020 wants to merge 13 commits intoapache:mainfrom
Open
feat: Add from_datetime method to Timestamp types#9345codephage2020 wants to merge 13 commits intoapache:mainfrom
codephage2020 wants to merge 13 commits intoapache:mainfrom
Conversation
a0e087f to
6a39b1c
Compare
6a39b1c to
617a44d
Compare
…into issue-9337
1. Introduce from_datetime<Tz: TimeZone> and a from_naive_datetime default to the ArrowTimestampType trait to provide a unified, timezone-aware way to create timestamp values. Implement these methods for all Timestamp* types . 2. Update and refactor tests to exercise UTC and FixedOffset conversions, subsecond precision, and naive-datetime-to-timezone roundtrips.
sdf-jkl
reviewed
Feb 4, 2026
sdf-jkl
reviewed
Feb 4, 2026
Contributor
sdf-jkl
left a comment
There was a problem hiding this comment.
Everything LGTM, but one comment below
Contributor
Author
alamb
reviewed
Feb 7, 2026
Contributor
alamb
left a comment
There was a problem hiding this comment.
Thanks @codephage2020 and @sdf-jkl -- this looks great to me, except for one question (on returning Option). Let me know what you think
| } | ||
|
|
||
| fn from_datetime<Tz: TimeZone>(datetime: DateTime<Tz>) -> i64 { | ||
| datetime.timestamp_nanos_opt().expect("timestamp overflow") |
Contributor
There was a problem hiding this comment.
🤔 this panic is unfortunate. Perhaps we should change the signature to return Option to avoid this?
| /// # Arguments | ||
| /// | ||
| /// * `naive` - The local datetime to convert | ||
| /// * `tz` - Optional timezone. If `None`, interprets as UTC. |
Contributor
There was a problem hiding this comment.
Can you also add a note here that that passing None is the same as calling Self::make_value?
And while we are considering this, I think it it would be worth deprecating make_value entirely and suggesting everyone uses from_naive_datetime (as a follow on PR, not in this one). Thoughts?
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.
Which issue does this PR close?
Closes #9337
Rationale for this change
What changes are included in this PR?
Are these changes tested?
YES
Are there any user-facing changes?
YES, Now it is possible to directly convert from datatime to timestamp.