thisisnic commented on code in PR #14093:
URL: https://github.com/apache/arrow/pull/14093#discussion_r1064476780


##########
r/R/dplyr-funcs-datetime.R:
##########
@@ -429,6 +430,78 @@ register_bindings_datetime_conversion <- function() {
   })
 }
 
+register_bindings_datetime_timezone <- function() {
+  register_binding(
+    "lubridate::force_tz",
+    function(time, tzone = "", roll_dst = c("error", "post")) {
+      if (length(roll_dst) == 1L) {
+        roll_dst <- c(roll_dst, roll_dst)
+      } else if (length(roll_dst) != 2L) {
+        arrow_not_supported("`roll_dst` length != 1 or 2")
+      }
+
+      nonexistent <- switch(
+        roll_dst[1],
+        "error" = 0L,
+        "boundary" = 2L,
+        arrow_not_supported("`roll_dst` != 'error' or 'boundary' for 
nonexistent times")

Review Comment:
   ```suggestion
           arrow_not_supported("`roll_dst` value must be 'error' or 'boundary' 
for non-existent times; other values")
   ```
   



##########
r/R/dplyr-funcs-datetime.R:
##########
@@ -429,6 +430,78 @@ register_bindings_datetime_conversion <- function() {
   })
 }
 
+register_bindings_datetime_timezone <- function() {
+  register_binding(
+    "lubridate::force_tz",
+    function(time, tzone = "", roll_dst = c("error", "post")) {
+      if (length(roll_dst) == 1L) {
+        roll_dst <- c(roll_dst, roll_dst)
+      } else if (length(roll_dst) != 2L) {
+        arrow_not_supported("`roll_dst` length != 1 or 2")
+      }
+
+      nonexistent <- switch(
+        roll_dst[1],
+        "error" = 0L,
+        "boundary" = 2L,
+        arrow_not_supported("`roll_dst` != 'error' or 'boundary' for 
nonexistent times")
+      )
+
+      ambiguous <- switch(
+        roll_dst[2],
+        "error" = 0L,
+        "pre" = 1L,
+        "post" = 2L,
+        arrow_not_supported("`roll_dst` != 'error', 'pre', or 'post' for 
ambiguous times")

Review Comment:
   This one too



##########
r/R/dplyr-funcs-datetime.R:
##########
@@ -429,6 +430,78 @@ register_bindings_datetime_conversion <- function() {
   })
 }
 
+register_bindings_datetime_timezone <- function() {
+  register_binding(
+    "lubridate::force_tz",
+    function(time, tzone = "", roll_dst = c("error", "post")) {
+      if (length(roll_dst) == 1L) {
+        roll_dst <- c(roll_dst, roll_dst)
+      } else if (length(roll_dst) != 2L) {
+        arrow_not_supported("`roll_dst` length != 1 or 2")

Review Comment:
   ```suggestion
           arrow_not_supported("`roll_dst` must be 1 or 2 items long; other 
lengths")
   ```
   This phrasing could be a bit clearer here - I've updated this to be more 
descriptive, and use "must" phrasing, as per the tidyverse style guide.



##########
r/R/dplyr-funcs-datetime.R:
##########
@@ -429,6 +430,78 @@ register_bindings_datetime_conversion <- function() {
   })
 }
 
+register_bindings_datetime_timezone <- function() {
+  register_binding(
+    "lubridate::force_tz",
+    function(time, tzone = "", roll_dst = c("error", "post")) {
+      if (length(roll_dst) == 1L) {
+        roll_dst <- c(roll_dst, roll_dst)
+      } else if (length(roll_dst) != 2L) {
+        arrow_not_supported("`roll_dst` length != 1 or 2")
+      }
+
+      nonexistent <- switch(
+        roll_dst[1],
+        "error" = 0L,
+        "boundary" = 2L,
+        arrow_not_supported("`roll_dst` != 'error' or 'boundary' for 
nonexistent times")
+      )
+
+      ambiguous <- switch(
+        roll_dst[2],
+        "error" = 0L,
+        "pre" = 1L,
+        "post" = 2L,
+        arrow_not_supported("`roll_dst` != 'error', 'pre', or 'post' for 
ambiguous times")
+      )
+
+      if (identical(tzone, "")) {
+        tzone <- Sys.timezone()
+      }
+
+      if (!inherits(time, "Expression")) {
+        time <- Expression$scalar(time)
+      }
+
+      # Non-UTC timezones don't work here and getting them to do so was too
+      # hard to do in the initial PR because there is no way in Arrow to
+      # "unapply" a UTC offset (i.e., the reverse of assume_timezone).
+      if (!time$type()$timezone() %in% c("", "UTC")) {
+        arrow_not_supported(
+          paste0("force_tz() from timezone `", time$type()$timezone(), "`")
+        )

Review Comment:
   Please can we add something mentioning the fact that UTC timezones *are* 
supported to this error message, so it's clearer to users what they can and 
can't do?



-- 
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]

Reply via email to