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

Option request: add parameter to set week start (Sunday vs Monday) #257

Closed
IamGianluca opened this Issue Sep 2, 2014 · 16 comments

Comments

Projects
None yet
10 participants
@IamGianluca

IamGianluca commented Sep 2, 2014

It would be useful to have a parameter in the week() function to set the initial day for the week. On the USA is common to consider as a starting day for a week Sunday, whereas in Europe we start the week on Monday.

@dougmitarotonda

This comment has been minimized.

Contributor

dougmitarotonda commented Sep 4, 2014

I would also like to see this feature and suggest it be made for all relevant functions. I just came across this myself when using wday. Are there others? I thought it came back as a character string, but it comes back as a factor starting on Sunday (I changed the documentation to reflect it is a factor not a string). But I would prefer the factoring to start on Monday.

It is probably easiest if you make it general to take a first_day_of_week argument that defaults to "Sunday".

@datalove

This comment has been minimized.

Contributor

datalove commented Dec 31, 2014

In addition to being useful with week, an argument to wday to set the start of the week to Monday makes sense in the context of the isoxxx functions (isoweek and now isoyear). People often want day number of the wday of the iso week, which always starts on a monday. (for example 2013-53-1 to 2015-53-7.

Happy to work on this if it sounds like a good idea.

@vspinu

This comment has been minimized.

Member

vspinu commented Dec 31, 2014

Happy to work on this if it sounds like a good idea.

I think it would be very useful. We just have to check that all lubridate code doesn't explicitly rely on the first day being Sunday. If it were after me I would even change the default to Monday as that's how iso defines it.

@ibiris

This comment has been minimized.

ibiris commented Apr 22, 2016

This would be a very useful feature. Just to emphasise the point: I would especially like to have this enabled floor_date when executed with unit="week". Maybe introduce a unit "isoweek" or an option for global application to all releant lubridate functions in a session.

@wdenton

This comment has been minimized.

wdenton commented Aug 30, 2016

Just to chime in, I'd like this too. When needed one can rearrange wday levels with something like this

s$day_name <- factor(s$day_name, levels = c("Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun"))

but a general option would be nice.

@Dmitrii-I

This comment has been minimized.

Dmitrii-I commented Aug 31, 2016

Also, would it make sense to take week start based on the locale LC_TIME value of the machine (Sys.getlocale()). I am not sure if this is cross platform compatible though.

Also this has been a feature request for two years now... no takers?

@vspinu

This comment has been minimized.

Member

vspinu commented Sep 1, 2016

I am not a big fan of locale-dependent settings as the same code will produce different results for different people. But given that in this regard to core R and some parts in lubridate (locale dependent parsing) are already locale dependent it might make sense to have week start locale dependent as well. But I am afraid this would break backward compatibility quite badly.

@dougmitarotonda

This comment has been minimized.

Contributor

dougmitarotonda commented Sep 1, 2016

One problem I have with locale-dependent settings is that I do work for customers in multiple locales. So sometimes I deliver output that has the first day Sunday, other times Monday. And that does not depend on my locale, but my customers'. Instead maybe something that could be in options that you could have in your .Rprofile would be better.

@GrayAlex49

This comment has been minimized.

GrayAlex49 commented Sep 13, 2016

I'm currently using floor_date() extensively for a project and happen to need it to collapse on Saturday which is obviously not typical but would be nice to have the option to do. Something like floor_date(data$date, weekstart = 'Saturday')

@vspinu

This comment has been minimized.

Member

vspinu commented Sep 13, 2016

You can do this with floor_date(x, "week") - days(1).

@GrayAlex49

This comment has been minimized.

GrayAlex49 commented Sep 14, 2016

That doesn't change the actual week, just how its labeled. To actually shift the window I use
floor_date( x + days(1), "week") - days(1)

@randomgambit

This comment has been minimized.

randomgambit commented Nov 11, 2016

Hello everybody, I am also interested in this feature. In many asset pricing studies, one can use different week-cycles (say Monday to Monday, or Friday to Friday, or even Wed to Wed). It would be nice to have that directly in lubridate. What do you think?

@randomgambit

This comment has been minimized.

@randomgambit

This comment has been minimized.

randomgambit commented Nov 11, 2016

One can always code it manually, but I think lubridate should probably handle that out-of-the-box to be the must-have package in date-management 💯

@vspinu vspinu closed this in deb0984 Nov 20, 2016

@RoyalTS

This comment has been minimized.

RoyalTS commented May 24, 2017

Given that the round-functions are gaining a week_start argument, should the argument to determine the start of the week not also be week_start instead of start for wday()?

@vspinu

This comment has been minimized.

Member

vspinu commented May 26, 2017

This is a good point. Thanks for pointing it out. I made this change. Hesitated a bit because start was introduced already 6 months ago, but given that back then it was the same development version I went with the consistency on this one.

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