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
Add first weekday option in profile #13991
Conversation
src/fake_data/provide_hass.ts
Outdated
@@ -224,6 +224,7 @@ export const provideHass = ( | |||
language: localLanguage, | |||
number_format: NumberFormat.language, | |||
time_format: TimeFormat.language, | |||
first_weekday: Weekday.monday, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first_weekday: Weekday.monday, | |
first_weekday: Weekday.language, |
if default, use:
"weekInfo" in Intl.Locale.prototype ? getLocaleFirstWeekDay(language) : Weekday.monday
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can do this. If user select "language", it will have the right day on compatible browsers and Monday on others (firefox).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can fallback to this package if needed https://github.com/gamtiq/weekstart (or defined our own mapping locale => first day). But I think the best solution is to define Monday for everyone and let the user choose in profile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weekstart is pretty small, I think we can use that as fallback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I just tested it and it don't impact the app size.
Most country/country use Monday as country, it just need to add the custom cases.
// @ts-ignore | ||
if ("weekInfo" in Intl.Locale.prototype) { | ||
// @ts-ignore | ||
return new Intl.Locale(locale.language).weekInfo.firstDay % 7; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just added ts-ignore until typescript version is bump de 4.5+
monday = "monday", | ||
tuesday = "tuesday", | ||
wednesday = "wednesday", | ||
thursday = "thursday", | ||
friday = "friday", | ||
saturday = "saturday", | ||
sunday = "sunday", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make these numeric values, so we can use them as index directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is language
option. So I preferred to keep all in string for consistency.
Is this still in scope? Would be great to have Monday a as first dat of week. Most of the counties have Monday is start of the week. The United States, Canada, most of South America, China, Japan and the Philippines officially consider Sunday to start the week ahead. |
This feature was added in 2022.11 release. |
Didn't catch that one. Maybe I saw it but didn't linked to it as issue... thank you! |
Proposed change
This PR allow user to select the first day of the week manually or use language option.
The language option uses
Int.Locale.weekInfo
but it's not always possible to determine the first day of week because it's not supported in all browsers and no polyfills exist. https://caniuse.com/mdn-javascript_builtins_intl_locale_weekinfoSo, a fallback has been added to https://github.com/gamtiq/weekstart for browsers that don't support
Int.Locale.weekInfo
.Fixed time components:
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: