jonkeane commented on a change in pull request #12319:
URL: https://github.com/apache/arrow/pull/12319#discussion_r814342940



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -140,3 +140,25 @@ register_bindings_datetime <- function() {
     (year %% 4 == 0) & ((year %% 100 != 0) | (year %% 400 == 0))
   })
 }
+
+binding_format_datetime <- function(x, format = "", tz = "", usetz = FALSE) {
+  if (usetz) {
+    format <- paste(format, "%Z")
+  }
+
+  if (call_binding("is.POSIXct", x)) {
+    # the casting part might not be required once
+    # https://issues.apache.org/jira/browse/ARROW-14442 is solved
+    # TODO revisit the steps below once the PR for that issue is merged
+    if (tz == "" && x$type()$timezone() != "") {
+      tz <- x$type()$timezone()
+    } else if (tz == "") {
+      tz <- Sys.timezone()
+    }
+    ts <- Expression$create("cast", x, options = list(to_type = 
timestamp(x$type()$unit(), tz)))
+  } else {
+    ts <- x
+  }
+
+  Expression$create("strftime", ts, options = list(format = format, locale = 
Sys.getlocale("LC_TIME")))

Review comment:
       Sorry I didn't catch these earlier — should we try using `build_expr()` 
here? 

##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -140,3 +140,25 @@ register_bindings_datetime <- function() {
     (year %% 4 == 0) & ((year %% 100 != 0) | (year %% 400 == 0))
   })
 }
+
+binding_format_datetime <- function(x, format = "", tz = "", usetz = FALSE) {
+  if (usetz) {
+    format <- paste(format, "%Z")
+  }
+
+  if (call_binding("is.POSIXct", x)) {
+    # the casting part might not be required once
+    # https://issues.apache.org/jira/browse/ARROW-14442 is solved
+    # TODO revisit the steps below once the PR for that issue is merged
+    if (tz == "" && x$type()$timezone() != "") {
+      tz <- x$type()$timezone()
+    } else if (tz == "") {
+      tz <- Sys.timezone()
+    }
+    ts <- Expression$create("cast", x, options = list(to_type = 
timestamp(x$type()$unit(), tz)))
+  } else {
+    ts <- x
+  }

Review comment:
       ```suggestion
       if (tz == "" && x$type()$timezone() != "") {
         tz <- x$type()$timezone()
       } else if (tz == "") {
         tz <- Sys.timezone()
       }
       x <- build_expr("cast", x, options = list(to_type = 
timestamp(x$type()$unit(), tz)))
     }
   ```
   
   I think this is a little bit less code but does the same thing — what do you 
think?




-- 
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-unsubscr...@arrow.apache.org

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


Reply via email to