dragosmg commented on a change in pull request #12433:
URL: https://github.com/apache/arrow/pull/12433#discussion_r814632260



##########
File path: r/R/dplyr-funcs-type.R
##########
@@ -76,6 +76,13 @@ register_bindings_type_cast <- function() {
   register_binding("as.numeric", function(x) {
     Expression$create("cast", x, options = cast_options(to_type = float64()))
   })
+  register_binding("as.Date", function(x) {
+    # base::as.Date() first converts to UTC and then extracts the date, which 
is
+    # why we need to go through timestamp() first - see unit tests for the real
+    # life impact of the difference between lubridate::date() and 
base::as.Date()
+    y <- build_expr("cast", x, options = cast_options(to_type = timestamp()))

Review comment:
       You are right, that was done to match the default behaviour of 
`as.Date()`, but we actually need to support a `tz` argument.  
   
   I think this needs a bit more work to support _all of_ (?) the following:
   ``` r
   a <- as.POSIXct("2022-02-25 00:00:01", tz = "Europe/London")
   b <- "2022-02-25 00:00:01"
   c <- "2022/25/02 00:00:01"
   d <- 1234
   as.Date(a)
   #> [1] "2022-02-25"
   as.Date(a, tz = "Pacific/Marquesas")
   #> [1] "2022-02-24"
   as.Date(b)
   #> [1] "2022-02-25"
   as.Date(c, format = "%Y/%d/%m %H:%M:%S")
   #> [1] "2022-02-25"
   as.Date(d, origin = "1981-01-01")
   #> [1] "1984-05-19"
   ```
   
   <sup>Created on 2022-02-25 by the [reprex 
package](https://reprex.tidyverse.org) (v2.0.1)</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: github-unsubscr...@arrow.apache.org

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


Reply via email to