diff --git a/r/R/dplyr-datetime-helpers.R b/r/R/dplyr-datetime-helpers.R index 9acf8b18435..0295dd35409 100644 --- a/r/R/dplyr-datetime-helpers.R +++ b/r/R/dplyr-datetime-helpers.R @@ -142,13 +142,9 @@ binding_as_date_numeric <- function(x, origin = "1970-01-01") { if (origin != "1970-01-01") { delta_in_sec <- call_binding("difftime", origin, "1970-01-01") - # TODO: revisit once either of these issues is addressed: - # https://issues.apache.org/jira/browse/ARROW-16253 (helper function for - # casting from double to duration) or - # https://issues.apache.org/jira/browse/ARROW-15862 (casting from int32 - # -> duration or double -> duration) - delta_in_sec <- build_expr("cast", delta_in_sec, options = cast_options(to_type = int64())) - delta_in_days <- (delta_in_sec / 86400L)$cast(int32()) + # TODO revisit once https://issues.apache.org/jira/browse/ARROW-15862 + # (casting from int32 -> duration or double -> duration) is addressed + delta_in_days <- (delta_in_sec$cast(int64()) / 86400L)$cast(int32()) x <- build_expr("+", x, delta_in_days) } diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 4d7ea050a0a..abf9a2056e1 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -351,8 +351,8 @@ register_bindings_datetime_conversion <- function() { fraction <- decimal - y delta <- build_expr("floor", seconds * fraction) - delta <- delta$cast(int64()) - start + delta$cast(duration("s")) + delta <- make_duration(delta, "s") + start + delta }) } @@ -412,9 +412,8 @@ register_bindings_duration <- function() { if (call_binding("is.character", x)) { x <- build_expr("strptime", x, options = list(format = format, unit = 0L)) - # complex casting only due to cast type restrictions: time64 -> int64 -> duration(us) - # and then we cast to duration ("s") at the end - x <- x$cast(time64("us"))$cast(int64())$cast(duration("us")) + # we do a final cast to duration ("s") at the end + x <- make_duration(x$cast(time64("us")), unit = "us") } # numeric -> duration not supported in Arrow yet so we use int64() as an @@ -459,8 +458,7 @@ register_bindings_duration_constructor <- function() { duration <- duration_from_chunks(chunks) } - duration <- build_expr("cast", duration, options = cast_options(to_type = int64())) - duration$cast(duration("s")) + make_duration(duration, "s") }) }