dragosmg commented on a change in pull request #12506:
URL: https://github.com/apache/arrow/pull/12506#discussion_r828156190
##########
File path: r/tests/testthat/test-dplyr-funcs-datetime.R
##########
@@ -974,3 +974,181 @@ test_that("date() errors with unsupported inputs", {
regexp = "Unsupported cast from double to date32 using function
cast_date32"
)
})
+
+test_that("difftime works correctly", {
+ test_df <- tibble(
+ time1 = as.POSIXct(
+ c("2021-02-20", "2021-07-31 0:0:0", "2021-10-30", "2021-01-31 0:0:0")
+ ),
+ time2 = as.POSIXct(
+ c("2021-02-20 00:02:01", "2021-07-31 00:03:54", "2021-10-30 00:05:45",
"2021-01-31 00:07:36")
+ ),
+ secs = c(121L, 234L, 345L, 456L)
+ )
+
+ compare_dplyr_binding(
+ .input %>%
+ mutate(
+ secs2 = difftime(time1, time2, units = "secs")
+ ) %>%
+ collect(),
+ test_df,
+ ignore_attr = TRUE
+ )
+
+ compare_dplyr_binding(
+ .input %>%
+ mutate(
+ secs2 = difftime(as.POSIXct("2022-03-07"), time1, units = "secs")
+ ) %>%
+ collect(),
+ test_df,
+ ignore_attr = TRUE
+ )
+
+ # units other than "secs" not supported in arrow
+ compare_dplyr_binding(
+ .input %>%
+ mutate(
+ mins = difftime(time1, time2, units = "mins")
+ ) %>%
+ collect(),
+ test_df,
+ warning = TRUE,
+ ignore_attr = TRUE
+ )
+
+ compare_dplyr_binding(
+ .input %>%
+ mutate(
+ hours = difftime(time1, time2, units = "hours")
+ ) %>%
+ collect(),
+ test_df,
+ warning = TRUE,
+ ignore_attr = TRUE
+ )
+
+ compare_dplyr_binding(
+ .input %>%
+ mutate(
+ days = difftime(time1, time2, units = "days")
+ ) %>%
+ collect(),
+ test_df,
+ warning = TRUE,
+ ignore_attr = TRUE
+ )
+
+ compare_dplyr_binding(
+ .input %>%
+ mutate(
+ weeks = difftime(time1, time2, units = "weeks")
+ ) %>%
+ collect(),
+ test_df,
+ warning = TRUE,
+ ignore_attr = TRUE
+ )
+
+ skip_on_os("windows")
+ test_df_with_tz <- tibble(
+ time1 = as.POSIXct(
+ c("2021-02-20", "2021-07-31", "2021-10-30", "2021-01-31"),
+ tz = "Europe/London"
+ ),
+ time2 = as.POSIXct(
+ c("2021-02-20 00:02:01", "2021-07-31 00:03:54", "2021-10-30 00:05:45",
"2021-01-31 00:07:36"),
+ tz = "America/Chicago"
+ ),
Review comment:
Sure. This is a bit of a leftover too, initially `difftime()` was being
called with `tz = "Pacific/Marquesas"` as the improbable timezone both `time1`
and `time2` were to be converted to.
--
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]