lubridate
lubridate copied to clipboard
Possible improvements to 'wday.numeric'
Re: #1025
wday.numeric
gains an optional argument week_start_x
indicating the coding of argument x
. The default value is 7, meaning 1=Sunday, for backwards compatibility. Hence anyone doing wday(<numeric>)
without specifying week_start_x
should see the same behaviour as before.
Some tests, which could easily go into test-accessors.R
...
library("lubridate")
wday(1:7, week_start_x = 7, week_start = 7) # from 1=Sunday to 1=Sunday (no-op)
## [1] 1 2 3 4 5 6 7
wday(1:7, week_start_x = 1, week_start = 7) # from 1=Monday to 1=Sunday
## [1] 2 3 4 5 6 7 1
wday(1:7, week_start_x = 7, week_start = 1) # from 1=Sunday to 1=Monday
## [1] 7 1 2 3 4 5 6
An even nicer (and still backwards compatible) interface might be:
library("lubridate")
wday(1:7, from_sunday = 1, to_sunday = 1)
## [1] 1 2 3 4 5 6 7
wday(1:7, from_sunday = 7, to_sunday = 1)
## [1] 2 3 4 5 6 7 1
wday(1:7, from_sunday = 1, to_sunday = 7)
## [1] 7 1 2 3 4 5 6
The default value of from_sunday
is 1 and the default value of to_sunday
is 8 - week_start
, so again anyone doing wday(<numeric>)
without specifying any of the new, optional arguments should see the same behaviour as before.
The same tests with label = TRUE
:
wday(1:7, from_sunday = 1, to_sunday = 1, label = TRUE)
## [1] Sun Mon Tue Wed Thu Fri Sat
## Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
wday(1:7, from_sunday = 7, to_sunday = 1, label = TRUE)
## [1] Mon Tue Wed Thu Fri Sat Sun
## Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
wday(1:7, from_sunday = 1, to_sunday = 7, label = TRUE)
## [1] Sun Mon Tue Wed Thu Fri Sat
## Levels: Mon < Tue < Wed < Thu < Fri < Sat < Sun