jonkeane commented on code in PR #13190:
URL: https://github.com/apache/arrow/pull/13190#discussion_r887364317


##########
r/tests/testthat/test-dplyr-funcs-datetime.R:
##########
@@ -50,49 +50,72 @@ test_df <- tibble::tibble(
 test_that("strptime", {
   t_string <- tibble(x = c("2018-10-07 19:04:05", NA))
   t_stamp <- tibble(x = c(lubridate::ymd_hms("2018-10-07 19:04:05"), NA))
+  t_stamp_with_pm_tz <- tibble(
+    x = c(lubridate::ymd_hms("2018-10-07 19:04:05", tz = "Pacific/Marquesas"), 
NA)
+  )
+
+  # base::strptime returns a POSIXlt (a list) => we cannot use 
compare_dplyr_binding
+  # => we use expect_equal
+  withr::with_timezone("Pacific/Marquesas", {
+    expect_equal(
+      t_string %>%
+        record_batch() %>%
+        mutate(
+          x = strptime(x, format = "%Y-%m-%d %H:%M:%S")
+        ) %>%
+        collect(),
+      t_stamp_with_pm_tz
+    )
+  })
+
+  expect_equal(
+    t_string %>%
+      arrow_table() %>%
+      mutate(
+        x = strptime(x, format = "%Y-%m-%d %H:%M:%S", tz = "Pacific/Marquesas")
+      ) %>%
+      collect(),
+    t_stamp_with_pm_tz
+  )
 
   expect_equal(
     t_string %>%
       Table$create() %>%
       mutate(
-        x = strptime(x)
+        x = strptime(x, tz = "UTC")
       ) %>%
       collect(),
-    t_stamp,
-    ignore_attr = "tzone"
+    t_stamp
   )
 
   expect_equal(
     t_string %>%
       Table$create() %>%
       mutate(
-        x = strptime(x, format = "%Y-%m-%d %H:%M:%S")
+        x = strptime(x, format = "%Y-%m-%d %H:%M:%S", tz = "UTC")
       ) %>%
       collect(),
-    t_stamp,
-    ignore_attr = "tzone"
+    t_stamp
   )
 
   expect_equal(
     t_string %>%
       Table$create() %>%
       mutate(
-        x = strptime(x, format = "%Y-%m-%d %H:%M:%S", unit = "ns")
+        x = strptime(x, format = "%Y-%m-%d %H:%M:%S", unit = "ns", tz = "UTC")
       ) %>%
       collect(),
-    t_stamp,
-    ignore_attr = "tzone"
+    t_stamp
   )
 
   expect_equal(
     t_string %>%
       Table$create() %>%
       mutate(
-        x = strptime(x, format = "%Y-%m-%d %H:%M:%S", unit = "s")
+        x = strptime(x, format = "%Y-%m-%d %H:%M:%S", unit = "s", tz = "UTC")

Review Comment:
   It might be good to test a non-UTC, non-current timezone here too, just to 
make sure we're dealing with timezones the way we think we should.



##########
r/R/dplyr-funcs-datetime.R:
##########
@@ -28,25 +28,52 @@ register_bindings_datetime <- function() {
 }
 
 register_bindings_datetime_utility <- function() {
-  register_binding("strptime", function(x, format = "%Y-%m-%d %H:%M:%S", tz = 
NULL,
+  register_binding("strptime", function(x,
+                                        format = "%Y-%m-%d %H:%M:%S",
+                                        tz = "",
                                         unit = "ms") {
     # Arrow uses unit for time parsing, strptime() does not.
     # Arrow has no default option for strptime (format, unit),
     # we suggest following format = "%Y-%m-%d %H:%M:%S", unit = MILLI/1L/"ms",
     # (ARROW-12809)
 
-    # ParseTimestampStrptime currently ignores the timezone information 
(ARROW-12820).
-    # Stop if tz is provided.
-    if (is.character(tz)) {
-      arrow_not_supported("Time zone argument")
-    }
+    unit <- make_valid_time_unit(
+      unit,
+      c(valid_time64_units, valid_time32_units)
+    )
+
+    output <- build_expr(
+      "strptime",
+      x,
+      options =
+        list(
+          format = format,
+          unit = unit,
+          error_is_null = TRUE
+        )
+    )
 
-    unit <- make_valid_time_unit(unit, c(valid_time64_units, 
valid_time32_units))
+    if (tz == "") {
+      tz <- Sys.timezone()
+    }
 
-    build_expr("strptime", x, options = list(format = format, unit = unit, 
error_is_null = TRUE))
+    if (!is.null(tz)) {
+      output <- build_expr(
+        "assume_timezone",
+        output,
+        options =
+          list(
+            timezone = tz
+          )
+      )
+    }
+    output

Review Comment:
   It might be helpful to add in a comment explaining why `assume_timezone` 
here is used instead of `cast`



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