Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions r/R/dplyr-funcs-datetime.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ register_bindings_datetime <- function() {
Expression$create("day_of_week", x, options = list(count_from_zero = FALSE, week_start = week_start))
})

register_binding("week", function(x) {
(call_binding("yday", x) - 1) %/% 7 + 1
})

register_binding("month", function(x, label = FALSE, abbr = TRUE, locale = Sys.getlocale("LC_TIME")) {
if (label) {
if (abbr) {
Expand Down
18 changes: 18 additions & 0 deletions r/tests/testthat/test-dplyr-funcs-datetime.R
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@ test_that("extract epiweek from timestamp", {
)
})

test_that("extract week from timestamp", {
compare_dplyr_binding(
.input %>%
mutate(x = week(datetime)) %>%
collect(),
test_df
)
})

test_that("extract day from timestamp", {
compare_dplyr_binding(
.input %>%
Expand Down Expand Up @@ -529,6 +538,15 @@ test_that("extract epiweek from date", {
)
})

test_that("extract week from date", {
compare_dplyr_binding(
.input %>%
mutate(x = week(date)) %>%
collect(),
test_df
)
})

test_that("extract month from date", {
compare_dplyr_binding(
.input %>%
Expand Down