Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make round_date() really use week_start= #1

Merged
merged 1 commit into from
Nov 27, 2018
Merged

Conversation

xvrdm
Copy link
Owner

@xvrdm xvrdm commented Nov 27, 2018

After reading the documentation and many SO questions, I still couldn't really explain the difference between round_date() and ceiling/floor_date when using unit="week" and week_start=1.

I thought it might just be that round_date() ignore week_start=, a bit like floor/ceiling_date back in the tidyverse#509 days.

Without week_start=, everything looks as expected.

> date <- parse_date_time("November 27 2018 23:45", orders="bdyHM")
> date
[1] "2018-11-27 23:45:00 UTC"
> lubridate::round_date(date, "week")
[1] "2018-11-25 UTC"
> lubridate::floor_date(date, "week")
[1] "2018-11-25 UTC"
> lubridate::ceiling_date(date, "week")
[1] "2018-12-02 UTC"

But if you ask for weeks starting on Mondays (or any other day). Only floor/ceiling_date seem affected:

> lubridate::round_date(date, "week", week_start = 1)
[1] "2018-11-25 UTC"
> lubridate::floor_date(date, "week", week_start = 1)
[1] "2018-11-26 UTC"
> lubridate::ceiling_date(date, "week", week_start = 1)
[1] "2018-12-03 UTC"

Apart from this tiny glitch, thanks for the awesome library: I don't want to use anything else when it comes to dates 👍 !

After reading the documentation and many SO questions, I still couldn't really explain the difference between `round_date()` and `ceiling/floor_date` when using `unit="week"` and `week_start=1`.

I thought it might just be that `round_date()` ignore `week_start=`, a bit like `floor/ceiling_date` back in the tidyverse#509 days.

Without `week_start=`, everything looks as expected. 

```
> date <- parse_date_time("November 27 2018 23:45", orders="bdyHM")
> date
[1] "2018-11-27 23:45:00 UTC"
> lubridate::round_date(date, "week")
[1] "2018-11-25 UTC"
> lubridate::floor_date(date, "week")
[1] "2018-11-25 UTC"
> lubridate::ceiling_date(date, "week")
[1] "2018-12-02 UTC"
```

But if you ask for weeks starting on Mondays (or any other day). Only `floor/ceiling_date` seem affected:

```
> lubridate::round_date(date, "week", week_start = 1)
[1] "2018-11-25 UTC"
> lubridate::floor_date(date, "week", week_start = 1)
[1] "2018-11-26 UTC"
> lubridate::ceiling_date(date, "week", week_start = 1)
[1] "2018-12-03 UTC"
```

Apart from this tiny glitch, thanks for the awesome library: I don't want to use anything else when it comes to dates 👍 !
@xvrdm xvrdm merged commit 14cd27a into master Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant