jonkeane commented on code in PR #46206: URL: https://github.com/apache/arrow/pull/46206#discussion_r2080865478
########## r/R/dplyr-funcs-datetime.R: ########## @@ -826,3 +827,54 @@ 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 = 0, minutes = 0, hours = 0, days = 0) { + 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_time32 <- function(datetime) { + hour <- call_binding("hour", datetime) + min <- call_binding("minute", datetime) + sec <- call_binding("second", datetime) + + return(call_binding("hms::hms", seconds = sec, minutes = min, hours = hour)) + } Review Comment: Any reason not to put this up on the same level as `numeric_to_time32()`? -- 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