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


##########
r/R/dplyr-funcs-datetime.R:
##########
@@ -429,6 +430,48 @@ register_bindings_datetime_conversion <- function() {
   })
 }
 
+register_bindings_datetime_timezone <- function() {
+  register_binding(
+    "lubridate::force_tz",
+    function(time, tzone = "", roll = FALSE) {
+      if (tzone == "") {
+        tzone <- Sys.timezone()
+      }
+      if (roll) {
+        .nonexistent <- 2L
+      } else {
+        # ToDo: Should return NA if falls into the DST-break without error
+        .nonexistent <- 0L
+      }
+      # ToDo: Work with non-UTC timezones
+      if (!time$type()$timezone() %in% c("", "UTC")) {
+        abort(
+          paste0(
+            "force_tz() from timezone `",
+            time$type()$timezone(),
+            "` not supported in Arrow"
+          )
+        )
+      }
+
+      # Remove timezone
+      time <- cast(time, timestamp(unit = time$type()$unit()))
+      # Add timezone
+      Expression$create("assume_timezone", time, options = list(timezone = 
tzone, nonexistent = .nonexistent))
+    },
+    notes = c(
+      "Timezone conversion from non-UTC timezone not supported;",
+      "When `roll = FALSE` and hit a non-existent time, raise an error"
+    )
+  )
+  register_binding("lubridate::with_tz", function(time, tzone = "") {
+    if (tzone == "") {
+      tzone <- Sys.timezone()
+    }
+    cast(time, timestamp(unit = time$type()$unit(), timezone = tzone))

Review Comment:
   Maybe I should change here as follows? (I haven't tried it, but would 
entering an R vector cause an error?)
   
   
https://github.com/apache/arrow/blob/793e5f6251255cfe812f4f187f2924224fefad8b/r/R/dplyr-funcs-datetime.R#L342-L343



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