dragosmg commented on a change in pull request #12707:
URL: https://github.com/apache/arrow/pull/12707#discussion_r838326323
##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -300,6 +314,34 @@ register_bindings_duration <- function() {
build_expr("cast", x, options = cast_options(to_type = duration(unit =
"s")))
})
+ register_binding("decimal_date", function(date) {
+ y <- build_expr("year", date)
+ start <- call_binding("make_datetime", year = y, tz = "UTC")
+ sofar <- call_binding("difftime", date, start, units = "secs")
+ total <- call_binding(
+ "if_else",
+ build_expr("is_leap_year", date),
+ call_binding("as.integer64", 31622400L), # number of seconds in a leap
year (366 days)
+ call_binding("as.integer64", 31536000L) # number of seconds in a
regular year (365 days)
Review comment:
```r
summary(test1, relative = TRUE)
#> A tibble: 2 × 13
#> expression min median `itr/sec` mem_alloc `gc/sec` n_itr
n_gc total_time result memory time gc
#> <bch:expr> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
<dbl> <bch:tm> <list> <list> <list> <list>
#> 1 new_implementation 1 1 1.40 1 1.03 94
6 1.32s <tibble> <Rprofmem> <bench_tm> <tibble>
#> 2 old_implementation 1.46 1.46 1 1.27 1 92
8 1.81s <tibble> <Rprofmem> <bench_tm> <tibble>
test1
#> A tibble: 2 × 13
#> expression min median `itr/sec` mem_alloc `gc/sec` n_itr
n_gc total_time result memory time gc
#> <bch:expr> <bch:tm> <bch:t> <dbl> <bch:byt> <dbl> <int>
<dbl> <bch:tm> <list> <list> <list> <list>
#> 1 new_implementation 12.7ms 13.3ms 71.1 76.1KB 4.54 94
6 1.32s <tibble> <Rprofmem> <bench_tm> <tibble>
#> 2 old_implementation 18.5ms 19.4ms 50.8 96.9KB 4.42 92
8 1.81s <tibble> <Rprofmem> <bench_tm> <tibble>
--
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]