codephage2020 commented on code in PR #9345:
URL: https://github.com/apache/arrow-rs/pull/9345#discussion_r2785670187


##########
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:
   Updated in the latest push. `from_datetime` now returns `Option<i64>` and 
uses checked arithmetic (consistent with `make_value`) for millisecond and 
microsecond precision to avoid overflow. Also added 
`timestamp_from_datetime_overflow` test to verify the behavior.



##########
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:
   Done — added the note that `tz=None` is equivalent to `Self::make_value`. 
Happy to work on deprecating `make_value` in a follow-up PR.



-- 
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]

Reply via email to