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


##########
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:
   Aaah so maybe it would be helpful to call that argument something else? Like 
maybe `use_tz`? That way the intent of it is a bit clearer on first read? (And 
of course comments if they are helpful...)



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