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


##########
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:
   I have a few more updates that I haven't pushed yet...I should have written 
a note! I'm sorry we took so long to review this...I was going to try to finish 
it off for you and ask you to review (although if you feel you can get it done 
before the release at the end of next week feel free!). Note that lubridate was 
also updated to add some more `roll` options.



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