dragosmg commented on a change in pull request #12506:
URL: https://github.com/apache/arrow/pull/12506#discussion_r827897864
##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -189,6 +189,70 @@ register_bindings_datetime <- function() {
})
}
+register_bindings_duration <- function() {
+ register_binding("difftime", function(time1,
+ time2,
+ tz,
+ units = c("auto", "secs", "mins",
+ "hours", "days", "weeks")) {
+ units <- match.arg(units)
+ if (units != "secs") {
+ abort("`difftime()` with units other than seconds not supported in
Arrow")
+ }
+
+ # for time32() we do not need to worry about timezone
+ if (call_binding("is.instant", time1) & call_binding("is.instant", time2))
{
+ if (missing(tz)) {
+ time1 <- build_expr("cast", time1, options = cast_options(to_type =
timestamp(unit = "s")))
+ time2 <- build_expr("cast", time2, options = cast_options(to_type =
timestamp(unit = "s")))
+ } else {
+ time1 <- build_expr("cast", time1, options = cast_options(to_type =
timestamp(timezone = tz, unit = "s")))
+ time2 <- build_expr("cast", time2, options = cast_options(to_type =
timestamp(timezone = tz, unit = "s")))
+ }
+ }
+
+ build_expr("cast", time1 - time2, options = cast_options(to_type =
duration("s")))
+ })
+
+ 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)
+ }
Review comment:
I think it's probably best to remove the `tz` argument from here too.
Especially since `tz` with times-only does not have any impact, `tz` is not
supported in the `strptime` binding, and, in base R, only impacts `difftime()`
with `POSIXlt`.
--
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]