GrafanaData: Fix week start for non-English browsers (#50582)

* grafana-data: Fix start week for non-English browsers

* apply review suggestion
This commit is contained in:
Agnès Toulet 2022-06-14 15:12:52 +02:00 committed by GitHub
parent b184280cb3
commit 99c8ce5ab9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,10 +126,15 @@ export const getWeekdayIndex = (day: string) => {
return moment.weekdays().findIndex((wd) => wd.toLowerCase() === day.toLowerCase());
};
export const getWeekdayIndexByEnglishName = (day: string) =>
['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'].findIndex(
(wd) => wd.toLowerCase() === day.toLowerCase()
);
export const setWeekStart = (weekStart?: string) => {
const suffix = '-weekStart';
const language = getLocale().replace(suffix, '');
const dow = weekStart ? getWeekdayIndex(weekStart) : -1;
const dow = weekStart ? getWeekdayIndexByEnglishName(weekStart) : -1;
if (dow !== -1) {
moment.locale(language + suffix, {
parentLocale: language,