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.
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.
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.
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
}