kumarUjjawal commented on code in PR #22610:
URL: https://github.com/apache/datafusion/pull/22610#discussion_r3378791381


##########
datafusion/functions/src/datetime/date_bin.rs:
##########
@@ -420,14 +418,46 @@ fn date_bin_months_interval(stride_months: i64, source: 
i64, origin: i64) -> Res
 }
 
 fn to_utc_date_time(nanos: i64) -> Result<DateTime<Utc>> {
-    let secs = nanos / NANOS_PER_SEC;
-    let nsec = (nanos % NANOS_PER_SEC) as u32;
+    // DateTime::from_timestamp requires a non-negative nanosecond part.
+    let secs = nanos.div_euclid(NANOS_PER_SEC);
+    let nsec = nanos.rem_euclid(NANOS_PER_SEC) as u32;

Review Comment:
   This fixes negative sub second timestamps. Normal `/` and `%` can produce a 
negative nanosecond remainder, but `DateTime::from_timestamp` requires nanos to 
be non-negative.`div_euclid` / `rem_euclid` normalize the timestamp into valid 
seconds + nanos.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to