You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2023/01/09 10:26:48 UTC

[GitHub] [arrow] thisisnic commented on a diff in pull request #14093: ARROW-17416: [R] Implement lubridate::with_tz and lubridate::force_tz

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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org