Skip to content

Have calendar - locale aware #1696

@Emacdyz

Description

@Emacdyz

Improvement description

Atm the calendar always starts the week on a Monday but for some countries, the week starts on a Sunday. It would be nice to have a calendar that updates the first day of the week depending on the local

Expected behavior

Something like this would work, but not yet supported on firefox

const getWeekdays = (locale: string) => {
  const weekdays = []
  const localeWeek = new Intl.Locale(locale)
  const firstDayOfTheWeek = localeWeek.weekInfo.firstDay

  for (let i = 0; i < 7; i++) {
    const weekday = new Date(2021, 5, i).toLocaleString(locale, {
      weekday: 'short',
    })

    weekdays.push(weekday)
  }

  if (firstDayOfTheWeek === 7) {
    return weekdays
      .slice(firstDayOfTheWeek - 1)
      .concat(weekdays.slice(0, firstDayOfTheWeek - 1))
  }

  return weekdays
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions