dragosmg commented on code in PR #12738:
URL: https://github.com/apache/arrow/pull/12738#discussion_r853972265


##########
r/R/dplyr-funcs-datetime.R:
##########
@@ -372,3 +372,50 @@ binding_format_datetime <- function(x, format = "", tz = 
"", usetz = FALSE) {
 
   build_expr("strftime", x, options = list(format = format, locale = 
Sys.getlocale("LC_TIME")))
 }
+
+binding_as_date <- function(x,
+                            format = NULL,
+                            tryFormats = "%Y-%m-%d",
+                            origin = "1970-01-01",
+                            tz = "UTC",
+                            base = TRUE) {
+
+  if (is.null(format) && length(tryFormats) > 1) {
+    abort("`as.Date()` with multiple `tryFormats` is not supported in Arrow")
+  }
+
+  if (call_binding("is.Date", x)) {
+    return(x)
+
+    # cast from POSIXct
+  } else if (call_binding("is.POSIXct", x)) {
+    # base::as.Date() first converts to the desired timezone and then extracts
+    # the date, which is why we need to go through timestamp() first
+    if (base || !is.null(tz)) {
+      x <- build_expr("cast", x, options = cast_options(to_type = 
timestamp(timezone = tz)))
+    }

Review Comment:
   We run row 395 in 2 cases: either when we call `as.Date()` or when we call 
`as_date()` and the user passes a value for `tz`. So the row is run both by the 
`as.Date()` and `as_date()` bindings. It encapsulates the main difference 
between the 2 functions when it comes to the treatment of `tz` (either passed 
as argument or attribute of the `POSIXct` object)    



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