paleolimbot commented on code in PR #14093:
URL: https://github.com/apache/arrow/pull/14093#discussion_r1064699067
##########
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:
Good call! How is this?
``` r
library(arrow, warn.conflicts = FALSE)
#> Some features are not enabled in this build of Arrow. Run `arrow_info()`
for more information.
tibble::tibble(timestamps = Sys.time()) |>
arrow_table() |>
dplyr::mutate(timestamps = lubridate::force_tz(timestamps, "UTC")) |>
dplyr::collect()
#> Warning: In lubridate::force_tz(timestamps, "UTC"), `time` with a non-UTC
#> timezone not supported in Arrow; pulling data into R
#> # A tibble: 1 × 1
#> timestamps
#> <dttm>
#> 1 2023-01-09 10:26:23
```
<sup>Created on 2023-01-09 with [reprex
v2.0.2](https://reprex.tidyverse.org)</sup>
--
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]