alamb commented on code in PR #9345:
URL: https://github.com/apache/arrow-rs/pull/9345#discussion_r2777496874
##########
arrow-array/src/types.rs:
##########
@@ -360,6 +396,10 @@ impl ArrowTimestampType for TimestampNanosecondType {
let nanos = utc.timestamp().checked_mul(1_000_000_000)?;
nanos.checked_add(utc.timestamp_subsec_nanos() as i64)
}
+
+ fn from_datetime<Tz: TimeZone>(datetime: DateTime<Tz>) -> i64 {
+ datetime.timestamp_nanos_opt().expect("timestamp overflow")
Review Comment:
🤔 this panic is unfortunate. Perhaps we should change the signature to
return Option<i64> to avoid this?
##########
arrow-array/src/types.rs:
##########
@@ -325,6 +325,30 @@ 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.
+ ///
+ /// # Arguments
+ ///
+ /// * `datetime` - The datetime to convert
+ fn from_datetime<Tz: TimeZone>(datetime: DateTime<Tz>) -> 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.
Review 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 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]