From 8bd2e85a00cb90af0a6c0a3035f10ce72052ed0e Mon Sep 17 00:00:00 2001 From: Danielle Navarro Date: Tue, 25 Jan 2022 10:49:53 +1100 Subject: [PATCH 1/4] add bindings and tests --- r/R/dplyr-funcs-datetime.R | 9 +++++++++ r/tests/testthat/test-dplyr-funcs-datetime.R | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 15a38997e7c..04c0214fdfb 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -139,4 +139,13 @@ register_bindings_datetime <- function() { year <- Expression$create("year", date) (year %% 4 == 0) & ((year %% 100 != 0) | (year %% 400 == 0)) }) + + register_binding("am", function(x) { + hour <- Expression$create("hour", x) + hour < 12 + }) + register_binding("pm", function(x) { + !call_binding("am", x) + }) + } diff --git a/r/tests/testthat/test-dplyr-funcs-datetime.R b/r/tests/testthat/test-dplyr-funcs-datetime.R index 228eca56add..ccee58d70c8 100644 --- a/r/tests/testthat/test-dplyr-funcs-datetime.R +++ b/r/tests/testthat/test-dplyr-funcs-datetime.R @@ -684,3 +684,23 @@ test_that("leap_year mirror lubridate", { ) }) + +test_that("am/pm mirror lubridate", { + + compare_dplyr_binding( + .input %>% + mutate( + am = am(test_time), + pm = pm(test_time) + ) %>% + collect(), + data.frame( + test_time = strptime(c( + "2022-01-25 11:50:59", + "2022-01-25 12:00:00", + "2022-01-25 00:00:00" + ), format = "%Y-%m-%d %H:%M:%S") + ) + ) + +}) From 85abaf90ffe28d944f1a89da27a1938cbdc1be7d Mon Sep 17 00:00:00 2001 From: Danielle Navarro Date: Thu, 27 Jan 2022 10:37:44 +1100 Subject: [PATCH 2/4] force empty string timezone on windows --- r/tests/testthat/test-dplyr-funcs-datetime.R | 22 +++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/r/tests/testthat/test-dplyr-funcs-datetime.R b/r/tests/testthat/test-dplyr-funcs-datetime.R index ccee58d70c8..10b9e6c3ced 100644 --- a/r/tests/testthat/test-dplyr-funcs-datetime.R +++ b/r/tests/testthat/test-dplyr-funcs-datetime.R @@ -687,6 +687,13 @@ test_that("leap_year mirror lubridate", { test_that("am/pm mirror lubridate", { + # TODO: revisit once ARROW-13168 is resolved + if (tolower(Sys.info()[["sysname"]]) == "windows") { + tzone = "" + } else { + tzone = "UTC" + } + compare_dplyr_binding( .input %>% mutate( @@ -695,11 +702,16 @@ test_that("am/pm mirror lubridate", { ) %>% collect(), data.frame( - test_time = strptime(c( - "2022-01-25 11:50:59", - "2022-01-25 12:00:00", - "2022-01-25 00:00:00" - ), format = "%Y-%m-%d %H:%M:%S") + test_time = strptime( + x = c( + "2022-01-25 11:50:59", + "2022-01-25 12:00:00", + "2022-01-25 00:00:00" + ), + format = "%Y-%m-%d %H:%M:%S", + tz = tzone + ) + ) ) From 9558b64d7bc2350cf9bdd133d2721db1fa1d8c02 Mon Sep 17 00:00:00 2001 From: Danielle Navarro Date: Thu, 27 Jan 2022 11:33:31 +1100 Subject: [PATCH 3/4] sigh. skip test on windows pending Arrow-13168 --- r/tests/testthat/test-dplyr-funcs-datetime.R | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/r/tests/testthat/test-dplyr-funcs-datetime.R b/r/tests/testthat/test-dplyr-funcs-datetime.R index 10b9e6c3ced..0f21f722969 100644 --- a/r/tests/testthat/test-dplyr-funcs-datetime.R +++ b/r/tests/testthat/test-dplyr-funcs-datetime.R @@ -687,12 +687,8 @@ test_that("leap_year mirror lubridate", { test_that("am/pm mirror lubridate", { - # TODO: revisit once ARROW-13168 is resolved - if (tolower(Sys.info()[["sysname"]]) == "windows") { - tzone = "" - } else { - tzone = "UTC" - } + # https://issues.apache.org/jira/browse/ARROW-13168 + skip_on_os("windows") compare_dplyr_binding( .input %>% From 256ec3d8cbf44957fe2eb273b6940be15ea1a67d Mon Sep 17 00:00:00 2001 From: Danielle Navarro Date: Thu, 27 Jan 2022 11:53:00 +1100 Subject: [PATCH 4/4] remove silly error --- r/tests/testthat/test-dplyr-funcs-datetime.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/r/tests/testthat/test-dplyr-funcs-datetime.R b/r/tests/testthat/test-dplyr-funcs-datetime.R index 0f21f722969..a7a705678c1 100644 --- a/r/tests/testthat/test-dplyr-funcs-datetime.R +++ b/r/tests/testthat/test-dplyr-funcs-datetime.R @@ -704,8 +704,7 @@ test_that("am/pm mirror lubridate", { "2022-01-25 12:00:00", "2022-01-25 00:00:00" ), - format = "%Y-%m-%d %H:%M:%S", - tz = tzone + format = "%Y-%m-%d %H:%M:%S" ) )