dragosmg commented on a change in pull request #12506: URL: https://github.com/apache/arrow/pull/12506#discussion_r823609052
########## File path: r/R/dplyr-funcs-type.R ########## @@ -120,6 +120,42 @@ register_bindings_type_cast <- function() { } build_expr("cast", x, options = cast_options(to_type = date32())) }) + register_binding("as.difftime", function(x, + format = "%X", + units = "auto", + tz = "UTC") { + # windows doesn't seem to like "%X" + if (format == "%X" & tolower(Sys.info()[["sysname"]]) == "windows") { + format <- "%H:%M:%S" + } + + if (units != "secs") { + abort("`as.difftime()` with units other than seconds not supported in Arrow") + } + + if (call_binding("is.character", x)) { + x <- build_expr("strptime", x, options = list(format = format, tz = tz, unit = 0L)) + y <- build_expr("strptime", "0:0:0", options = list(format = "%H:%M:%S", tz = tz, unit = 0L)) + diff_x_y <- call_binding("difftime", x, y, units = "secs", tz = tz) + return(diff_x_y) + } + + # numeric -> duration not supported in Arrow yet so we use time23() as + # intermediate step + # TODO revisit once https://issues.apache.org/jira/browse/ARROW-15862 done + if (call_binding("is.numeric", x)) { + if (call_binding("is.integer", x)) { + x <- build_expr("cast", x, options = cast_options(to_type = time32(unit = "s"))) + y <- build_expr("cast", 0L, options = cast_options(to_type = time32(unit = "s"))) + diff_x_y <- call_binding("difftime", x, y, units = "secs", tz = tz) + return(diff_x_y) + } else { + abort("`as.difftime()` with double/float inputs not supported in Arrow ") Review comment: Realigned / restyled my work. This was most likely a residual from rebasing. Done -- 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