lubridate icon indicating copy to clipboard operation
lubridate copied to clipboard

FR: week_start= to accept "commonly recognized" weekday names for readability

Open MichaelChirico opened this issue 4 years ago • 2 comments

When reading code,

floor_date(x, "week", week_start = 1)

is a bit hard to read. Is this week 0-or 1-based? Is it based on Sunday or Monday?

This is easily answered by consulting ?floor_date, but when reading code / doing code reviews, it may not be trivial to do so (e.g. I don't have R open).

Therefore I think it makes sense for the following to "just work":

floor_date(x, "week", week_start = "Monday")

The only issue is this doesn't align perfectly with format(x, "%A") due to locale dependency. We could also do something like compare the input to format(x, "%A") at run-time (possibly with caching)... not sure it's worth it.

Happy to file a PR to this end.

MichaelChirico avatar Feb 14 '22 17:02 MichaelChirico

Very good idea. Would be happy to accept a PR in this regard.

vspinu avatar Feb 14 '22 19:02 vspinu

Regarding the format. I think english names should be there regardless of the locale and for the current locale the internal .get_locale_regs should be helpfull:


> lubridate:::.get_locale_regs()$wday_names
$abr
[1] "Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"

$full
[1] "Sunday"    "Monday"    "Tuesday"   "Wednesday" "Thursday"  "Friday"    "Saturday" 

vspinu avatar Feb 14 '22 19:02 vspinu