sdf-jkl commented on code in PR #9345:
URL: https://github.com/apache/arrow-rs/pull/9345#discussion_r2788823475
##########
arrow-array/src/types.rs:
##########
@@ -325,6 +325,34 @@ pub trait ArrowTimestampType: ArrowTemporalType<Native =
i64> {
///
/// See [`DataType::Timestamp`] for more information on timezone handling
fn make_value(naive: NaiveDateTime) -> Option<i64>;
+
+ /// Creates a timestamp value from a [`DateTime`] in any timezone.
+ ///
+ /// Returns `None` if the timestamp value would overflow the i64 range
+ /// (e.g., for nanosecond precision with extreme datetime values).
+ ///
+ /// # Arguments
+ ///
+ /// * `datetime` - The datetime to convert
+ fn from_datetime<Tz: TimeZone>(datetime: DateTime<Tz>) -> Option<i64>;
+
+ /// Creates a timestamp value from a [`NaiveDateTime`] interpreted in the
given timezone.
+ ///
+ /// # Arguments
+ ///
+ /// * `naive` - The local datetime to convert
+ /// * `tz` - Optional timezone. If `None`, interprets as UTC
+ /// (equivalent to calling [`Self::make_value`]).
+ fn from_naive_datetime(naive: NaiveDateTime, tz: Option<&Tz>) ->
Option<i64> {
+ match tz {
+ Some(tz) => match tz.from_local_datetime(&naive) {
+ chrono::offset::LocalResult::Single(dt) =>
Self::from_datetime(dt),
+ chrono::offset::LocalResult::Ambiguous(dt1, _) =>
Self::from_datetime(dt1),
+ chrono::offset::LocalResult::None => None,
+ },
+ None => Self::make_value(naive),
Review Comment:
I like that we can reuse `make_value` here instead of reimplementing
`from_naive_datetime` for every timestamp type.
Maybe instead of fully deprecating `make_value`, we move it out of the the
pub trait `ArrowTimestampType` and use it for `from_naive_datetime`?
Also do we have a use case for `from_datetime` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]