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

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

* apply review suggestion

(cherry picked from commit 99c8ce5ab9)

Co-authored-by: Agnès Toulet <35176601+AgnesToulet@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2022-06-14 15:26:54 +02:00
committed by GitHub
co-authored by Agnès Toulet
parent 88188d63c8
commit b4f9f19ed1
@@ -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,