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
getDay doesn't let you set weekStartsOn #1287
Comments
@lsenta hi. The behaviour of 0 always means Sunday, and 6 always means Saturday regardless of
|
@leshakoss can you explain the reasoning behind that design?
|
@hernansartorio "please" would be helpful. First of all, day (just like a month) is an index number, so it should be static and always point on the same entity. Week, year, and quarter, unlike day and month, are relative to the used calendar system. For example, 2005-01-01 might give you 2004 year if you ISO week numbering calendar but 0 always points to Sunday or January (at least in JavaScript). Secondly, it doesn't make sense from the API point of view: const date = new Date(2019, 11, 19)
startOfWeek(date, { weekStartsOn: 1 })
//=> 2019-12-16
getDay(date, { weekStartsOn: 5 })
//=> what do you expect to get? I think you might confuse the day of the week with the day number relative to the start of the week. It's not the same, and we don't use the latter anywhere. It's also not common in the real world. You say, "let's meet on Tuesday," but never "let's meet on the third day of the week." At first, it's not intuitive but also could lead to confusion when people from different parts of the world try to arrange a meeting. |
@kossnocorp sorry, I was definitely missing a “please” there. I didn’t mean to sound demanding at all. Thanks for the explanation, that makes sense. Like you say, I was confusing getting the day of the week with getting the day number relative to the start of the week (which I ended up solving with Anyways, thank you for creating and maintaining this library. It's incredibly well-done and a life-saver when working with dates. |
@hernansartorio no worries, no grudge at all. I'm glad that it was helpful, and thank you so much for the kind words. |
Hi there, thanks for maintaining this super useful library,
I have a remark / request / issue regarding
getDay
:getWeekOfMonth
accept options such aslocale, weekStartsOn
.https://date-fns.org/v2.0.0-beta.4/docs/getWeekOfMonth
This means that:
(supposedly, there's a known bug with Sundays: #1040)
I expect the
getDay
function to let me setlocale, weeksStartsOn
too, so that:The text was updated successfully, but these errors were encountered: