Skip to content
Merged
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Added support for `lubridate::date()` (@atsyplenkov, #181).

* Added support for `lubridate::today()` and `lubridate::now()` (#183).

# tidypolars 0.13.0

## New features
Expand Down
9 changes: 9 additions & 0 deletions R/funs-date.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@
pl$date(year = year, month = month, day = day)
}

pl_today_lubridate <- function(tzone = "") {
pl$lit(lubridate::today(tzone = tzone))
}

pl_now_lubridate <- function(tzone = "") {
pl$lit(lubridate::now(tzone = tzone))

Check warning on line 95 in R/funs-date.R

View check run for this annotation

Codecov / codecov/patch

R/funs-date.R#L95

Added line #L95 was not covered by tests
}


# Durations --------------------------------------

# TODO: annoying to parse `...` because of partial matching of args, e.g
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-funs_date-lazy.R
Original file line number Diff line number Diff line change
Expand Up @@ -804,4 +804,17 @@ test_that("check_timezone() throws expected errors", {
)
})

test_that("today() works", {
test_df <- data.frame(
id = 1:6,
date = lubridate::now(tzone = "") + lubridate::days(-5:0)
)
test <- as_polars_lf(test_df)

expect_equal_lazy(
filter(test, date >= lubridate::today()),
filter(test_df, date >= lubridate::today())
)
})

Sys.setenv('TIDYPOLARS_TEST' = FALSE)
13 changes: 13 additions & 0 deletions tests/testthat/test-funs_date.R
Original file line number Diff line number Diff line change
Expand Up @@ -799,3 +799,16 @@ test_that("check_timezone() throws expected errors", {
"`tidypolars` cannot pass a variable of the data as timezone."
)
})

test_that("today() works", {
test_df <- data.frame(
id = 1:6,
date = lubridate::now(tzone = "") + lubridate::days(-5:0)
)
test <- as_polars_df(test_df)

expect_equal(
filter(test, date >= lubridate::today()),
filter(test_df, date >= lubridate::today())
)
})