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

useCalendar: Add support for overriding first day of week #3986

Open
selbekk opened this issue Jan 31, 2023 · 34 comments · May be fixed by #7363
Open

useCalendar: Add support for overriding first day of week #3986

selbekk opened this issue Jan 31, 2023 · 34 comments · May be fixed by #7363
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@selbekk
Copy link

selbekk commented Jan 31, 2023

🙋 Feature Request

Specifying the first day of the week (monday or sunday, typically) should be supported.

💁 Possible Solution

Add a firstDayOfWeek override to the useDatepickerState hook, for instance.

@reidbarber
Copy link
Member

reidbarber commented Jan 31, 2023

From #3553 (comment):

You can just reorder the returned days like:

  let [first, ...rest] = weekDays;
  weekDays = [...rest, first];

Example: https://codesandbox.io/s/calendar-starting-on-monday-q6kr3c?file=/src/CalendarGrid.js

@selbekk
Copy link
Author

selbekk commented Jan 31, 2023

I could, but I would have to add custom logic for the locales that have this by default.

@LFDanLu LFDanLu added the enhancement New feature or request label Feb 8, 2023
@github-project-automation github-project-automation bot moved this to ✏️ To Groom in RSP Component Milestones Feb 8, 2023
@LFDanLu LFDanLu moved this from ✏️ To Groom to 🛑 Blocked / Needs More Info in RSP Component Milestones Apr 5, 2023
@LFDanLu
Copy link
Member

LFDanLu commented Apr 5, 2023

@selbekk We were discussing this in our grooming session today and were wondering what your use case was for this. Is there a particular locale that you wanted to override?

@selbekk
Copy link
Author

selbekk commented Apr 5, 2023

@selbekk We were discussing this in our grooming session today and were wondering what your use case was for this. Is there a particular locale that you wanted to override?

Well, mostly for overriding the US default. Lots of European sites used the US English as their alternative locale, but have never seen Sunday as the first day in any calendar whatsoever. So presenting them with that choice may seem odd.

@devongovett
Copy link
Member

So you want English language but for a different region? Would setting the locale to something like "en-DE" (eg for Germany) work? We use the region code to determine the first day of the week, not the language.

@selbekk
Copy link
Author

selbekk commented Apr 6, 2023

I could (this is my workaround today), but if the language of the site is "en-US", the locale should reflect that as well.

Using the en-US locale also introduces am/pm, but at least there you can specify a 24 hour clock

@kristian-puccio
Copy link

Just a comment, the work around doesn't work, it's re-orders the days of the week correctly but then the dates don't adjust accordingly.

So 1st of May 2023 is a Monday but it will show as a Tuesday (In my locale) using the above work around.

I would like an option to change it as well, my locale for some reason starts the week on Monday but it's much more common here to consider the start of the week Sunday.

@devongovett
Copy link
Member

What's your locale?

@kristian-puccio
Copy link

Australia/Melbourne

But I don't think my locale would affect the re-ordering of the days to be wrong. The issue is that the snippet above re-orders the day labels but not the dates in the calendar below.

One thing is that Apple provides a switch in their preferences to determine the start of the week, so sorta seems like a nice best practice to offer it.

Screenshot 2023-05-28 at 10 52 59 am

@devongovett
Copy link
Member

devongovett commented May 28, 2023

I think that was a bug (#4585) that was just fixed (#4598). Should be released soon (or try the nightly).

@kristian-puccio
Copy link

Awesome thanks!

@Capsicum42
Copy link

Hi,
in my company our planning per week is from Saturday to Friday and I would like to display all calendars accordingly.

If the dates are not included in the month, the calendar should fill it with the dates from the previous month.

image

Is there an example, how to implement this with react-aria ?
(This is using react-datepicker)
Regards
Holger

@LFDanLu
Copy link
Member

LFDanLu commented Jun 14, 2023

Talked about this with the team today, we think this is a reasonable request but was wondering if anyone had any ideas about the possible API for this override, specifically with considerations to make it locale agnostic.

@Capsicum42
Copy link

The other libraries have a property, where you just can set set the "start day" of week. As default it uses the value from the locale.

e.g. https://www.npmjs.com/package/react-datepicker uses a property called:
calendarStartDay={6}. // Start on Saturday

@ArtemFedorchuk
Copy link

ArtemFedorchuk commented Jun 29, 2023

I'm blocked by this issue🙁😢
I need to have a Monday as the first day of the week;
Like this:
Screenshot 2023-06-29 at 18 23 59

Currently, I have this:
Screenshot 2023-06-28 at 15 48 30

@devongovett
Copy link
Member

Could you explain why this is important for you? Overriding the locale may be unexpected for users.

@Capsicum42
Copy link

Capsicum42 commented Jun 29, 2023

In my company we perform planning of our business activities from Saturday to Friday. To display a complete "Work / Planning" week, the calendar week should start on Saturday. In this case, one of "our" weeks is one row in the calendar.

Most of the calendar / date-picker for react can override the "start of week day"

@ArtemFedorchuk
Copy link

ArtemFedorchuk commented Jun 30, 2023

Could you explain why this is important for you? Overriding the locale may be unexpected for users.

In my project, it's important to have such a calendar which will start with Monday as the first day of the week. Because our product uses the people from Europe and most of them from Germany. They want to use and see such variants.

I don't want to install an additional library for a such case.

@devongovett
Copy link
Member

Calendar already adjusts the first day of the week based on the user's locale though, so you shouldn't need to override it in that case.

@hosmelq
Copy link
Contributor

hosmelq commented Sep 24, 2023

In my case, I am in Nicaragua, and if I set the calendar to Spanish (Latin America), the first day is still on Sunday. Usually, in Latin America, Monday is the first day of the week.

@snowystinger
Copy link
Member

That looks like a bug for CLDR. I see

new Intl.Locale('en-US').weekInfo
// {firstDay: 7, weekend: Array(2), minimalDays: 1}
new Intl.Locale('es-NI').weekInfo
// {firstDay: 7, weekend: Array(2), minimalDays: 1}

Both say that the first day of the week is Sunday

@hunganhAtWhill
Copy link

I dont think it is a bug, since officially start of week in US is Sunday. With that said, sometimes we want to show the calendar starting from a specific day of the week and not always based on the Intl.Locale. This feature is needed I think.

@snowystinger
Copy link
Member

I dont think it is a bug, since officially start of week in US is Sunday.

I don't follow, both of them show Sunday, which @hosmelq is saying is wrong for Nicaragua. I included the US in that sample to show that they both give the same day, Sunday.

You can change the locale of the calendar by changing what is in the Intl Provider. IE you could wrap the calendar in question specifically with its own Intl Provider which differs from the App level one.

I know we have some other tickets to support some various business/financial calendars. Would this ticket better match your needs? #3270

@joshuajaco
Copy link
Contributor

joshuajaco commented Jan 23, 2024

Could you explain why this is important for you? Overriding the locale may be unexpected for users.

Some users might speak a different language from the country they live in. In that case you would likely want the locale to be different from the start of the week. Google Calendar for example lets you select the language, country and the start of the week separately.

@joshuajaco
Copy link
Contributor

Our users expect to be able to select a start of the week that is different from their locale/language.
We are now using our own implementation of getWeeksInMonth and state.getDatesInWeek to allow this.

@hunganhAtWhill
Copy link

Also, imagine a management portal scenario, where you can manage remote facilities. In that case all that is shown on the UI must be in local format of the facility you are currently viewing including when does the week start, no matter where the browser of the manager is

@hunganhAtWhill
Copy link

I don't follow, both of them show Sunday, which @hosmelq is saying is wrong for Nicaragua

@snowystinger maybe it is indeed wrong, but at least according to Intl.Locale it starts from Sunday. In any case the need to specify first day of week is plently apparent to me. Intl.Locale being wrong / outdated in some cases is even more reason to support this feature.

@snowystinger snowystinger added the help wanted Extra attention is needed label Feb 6, 2024
@hsuanyi-chou
Copy link

hsuanyi-chou commented Mar 1, 2024

In Taiwan, some people are accustomed to considering Sunday as the first day of the week, while others consider Monday as the first day.
As for the government calendar, Sunday is considered the first day.

It would be beneficial to have a parameter that allows users to set their preferred first day of the week. Both of these practices are common in Taiwan.

I've tried to create the feature, but I have no idea how to offset the date to meet th(a.k.a weekDay).

@anclark686
Copy link

Just wanted to post a workaround, since the codeSandbox example doesn't work. I wrapped my calendar component (only) in a I18nProvider and changed the locale to en-DE for Monday start, but kept en-US for Sunday start. Not the most programmatic way, but it gets the job done.

@AmelloAster
Copy link

Are there any viable options at this point?

@dmtrek14
Copy link

I agree that having such a feature would be nice. A use case: creating an application for a multinational company, but the company wants to choose a standard calendar for the company. This might mean that even though Sunday is technically the first day of the week in the US, the company may want to use Monday as a starting day because most of the company is not US-based or this is simply how the company wants to standardize discussion of work periods across the company.

date-fns handles this by allowing you pass in various options, such as a locale or the starting day: https://date-fns.org/v3.6.0/docs/startOfWeek#. The code for that is here: https://github.com/date-fns/date-fns/blob/ddb34e083/src/startOfWeek/index.ts

Something like that here would be very nice. I think the change could go in https://github.com/adobe/react-spectrum/blob/main/packages/%40internationalized/date/src/queries.ts to allow an optional param of weekStartsOn to the startOfWeek function. But there are probably other places in the stack where such a thing could be added.

@joshuajaco
Copy link
Contributor

Our customers expect to see date pickers with their "business week" with a configurable start of the week.
This is still blocking us from moving our date picker to use react-aria-components.
I haven't found a way to implement this without dropping down to the hook API.
Not sure if this is part of this issue or rather #3270.

@lxcid
Copy link

lxcid commented Aug 28, 2024

I do agree with ability to change start of the week, sometimes locale don't capture it accurately due to political/racial/religions reasons, especially, in a multi racial countries, not everyone might follow what politically is the start of the week and locale only capture till the political level.

@lxcid
Copy link

lxcid commented Aug 28, 2024

another good reason is in a remote working world people might follow the start of week of the employer but do not want to adjust their locale.

also, it would be useful to find out the weekday of the calendar date https://en.m.wikipedia.org/wiki/ISO_week_date

@matthewdeutsch matthewdeutsch moved this to 📋 Waiting for Sprint in RSP Component Milestones Nov 5, 2024
@reidbarber reidbarber moved this from 📋 Waiting for Sprint to 🏗 In Progress in RSP Component Milestones Nov 11, 2024
@reidbarber reidbarber linked a pull request Nov 13, 2024 that will close this issue
5 tasks
@reidbarber reidbarber moved this from 🏗 In Progress to 👀 In Review in RSP Component Milestones Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Status: 👀 In Review
Development

Successfully merging a pull request may close this issue.