thisisnic commented on code in PR #46206:
URL: https://github.com/apache/arrow/pull/46206#discussion_r2055513372


##########
r/R/dplyr-funcs-datetime.R:
##########
@@ -826,3 +827,55 @@ register_bindings_datetime_rounding <- function() {
     }
   )
 }
+
+register_bindings_hms <- function() {
+  numeric_to_time32 <- function(x) {
+    # The only numeric which can be cast to time32 is int32 so double cast to 
make sure
+    cast(cast(x, int32()), time32(unit = "s"))
+  }
+
+  register_binding(
+    "hms::hms",
+    function(seconds = NULL, minutes = NULL, hours = NULL, days = NULL) {
+      total_secs <- seconds +
+        Expression$create("multiply_checked", minutes, 60) +
+        Expression$create("multiply_checked", hours, 3600) +
+        Expression$create("multiply_checked", days, 86400)
+
+      return(numeric_to_time32(total_secs))
+    }
+  )
+
+  register_binding(
+    "hms::as_hms",
+    function(x = numeric()) {
+      datetime_to_int64 <- function(datetime) {
+        hour <- call_binding("hour", datetime)
+        min <- call_binding("minute", datetime)
+        sec <- call_binding("second", datetime)
+
+        # Convert to time with origin so we can get integer value in seconds
+        temptime <- call_binding("lubridate::make_datetime", hour = hour, min 
= min, sec = sec)
+        # Cast to int64 as this is the only thing we can cast a timestamp to
+        cast(temptime, to = int64())

Review Comment:
   Can't we just feed `hour`/`min`/`sec` here into the `hms::hms()` binding 
defined above?



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to