Skip to content

<FEATURE REQ>[as_date()] Would it be possible for as_date to only produce future dates? #1226

Description

@JoeMarino2021

I was wondering if as_date() could have a future argument that would cause only future dates to be created? Consider the dates of the upcoming NFL season, as an example. Here are the last few dates of the season, which are 2026 and 2027 dates.

[1] "December 27" "December 28" "December 31" "January 3" "January 4" "January 10"

If I perform as_date(format = "%B %d") on these dates, it creates the following results.

[1] "2026-12-27" "2026-12-28" "2026-12-31" "2026-01-03" "2026-01-04" "2026-01-10"

With the future argument, we could have as_date(format = "%B %d", future = TRUE) and produce this output.

[1] "2026-12-27" "2026-12-28" "2026-12-31" "2027-01-03" "2027-01-04" "2027-01-10"

Maybe even as_date() could be smart enough to detect any future rollover points from December to January in a list that was longer and multiyear and add more than just one year to the output dates when needed. My example only spans the crossover from 2026 to 2027, but a longer list may, perhaps, also contain a crossover from 2027 to 2028 at some point.

It is not too much trouble to correct this now, with

mutate(Date = case_when(Date < today() ~ Date %m+% years(1), .default = Date))

but code could be so much cleaner, and possibly faster, if as_date() had a future argument.

Thanks for creating and maintaining such wonderful tools, and considering this request. Have a great day!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions