10

Is there a way to get the first day of the week (Sunday or Monday for most countries) from the HTML5 internationalization API?

The spec can be found here. I would be surprised if it's not somehow disclosed, but I can't seem to find where.

TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87
David Mulder
  • 26,123
  • 9
  • 51
  • 114
  • It looks like `Intl` has been designed to follow ISO 8601, which only allows Monday as first day of week :( – gpbl May 28 '15 at 17:32
  • I'm fan of `Intl` as implemented in PHP: a wrapper for ICU. My expectation was that browsers would also just use the ICU library from the Unicode Consortium to implement their own `Intl` extention. But it seems everybody implements their own? A workaround is to output [`getFirstDayOfWeek()`](http://icu-project.org/apiref/icu4c/classicu_1_1Calendar.html#aa95d4e17ea169d0388a3a18489e67da0) in JSON to your own HTML5 app. – Code4R7 Jul 10 '17 at 14:07

2 Answers2

6

Intl doesn't have an API to access this sort of calendar information yet. It's possible it may add support for doing so in the future, but right now you're out of luck.

Jeff Walden
  • 7,008
  • 2
  • 38
  • 55
5

The official vanilla API for retrieving this is:

new Intl.Locale('en-US').weekInfo

which will return an object like:

{
    firstDay: 7,      // First day of the week is Sunday
    minimalDays: 1,   // First calendar week of the year must have at least 1 weekday
    weekend: [6, 7]   // Weekend is Saturday and Sunday
}

Examples for other cultures: (new Intl.Locale('<locale>').weekInfo)

Germany de-DE:

{
    firstDay: 1,      // First day of the week is Monday
    minimalDays: 4,   // First calendar week of the year has at least 4 weekdays
    weekend: [6, 7]   // Weekend is Saturday and Sunday
}

Egypt ar-EG:

{
    firstDay: 6,      // First day of the week is Saturday
    minimalDays: 1,   // First calendar week of the year has at least 1 weekday
    weekend: [5, 6]   // Weekend is Friday and Saturday
}

Uganda sw-UG:

{
    firstDay: 1,      // First day of the week is Monday
    minimalDays: 1,   // First calendar week of the year has at least 1 weekday
    weekend: [7]      // Weekend is Sunday only
}

Brunei ms-BN:

{
    firstDay: 7,      // First day of the week is Sunday
    minimalDays: 1,   // First calendar week of the year has at least 1 weekday
    weekend: [5, 7]   // Weekend is Friday and Sunday
}
Leon Adler
  • 2,993
  • 1
  • 29
  • 42
  • 1
    Some info I found on `weekInfo`: it is going be wonderful when it exists, but the TC39 proposal for [intl-locale-info](https://github.com/tc39/proposal-intl-locale-info) is currently at stage 3 and [not available yet](https://caniuse.com/mdn-javascript_builtins_intl_locale_weekinfo) in firefox and some active safari versions. I wasn't able to find a polyfill. – jrjohnson Sep 22 '22 at 22:26
  • yes I found this very usefull too , but why no one polyfilled it yet ? – mh-alahdadian Oct 15 '22 at 14:55