The getWeekInfo()
method of Intl.Locale instances returns a weekInfo
object with the properties firstDay
, weekend
and minimalDays
for this locale.
Note: In some versions of some browsers, this method was implemented as an accessor property called
weekInfo
. However, because it returns a new object on each access, it is now implemented as a method to prevent the situation oflocale.weekInfo === locale.weekInfo
returningfalse
. Check the browser compatibility table for details.
Syntax
getWeekInfo()
Parameters
None.
Return value
An object representing week information associated with the Locale data specified in UTS 35's Week Elements. It has the following properties:
firstDay
- : An integer indicating the first day of the week for the locale. Can be either
1
(Monday) or7
(Sunday).
- : An integer indicating the first day of the week for the locale. Can be either
weekend
- : An array of integers indicating the weekend days for the locale, where
1
is Monday and7
is Sunday.
- : An array of integers indicating the weekend days for the locale, where
minimalDays
- : An integer between 1 and 7 indicating the minimal days required in the first week of a month or year, for calendar purposes.
Examples
Obtaining the Week Information
Return the week information for a given Locale
.
const he = new Intl.Locale("he");
console.log(he.getWeekInfo()); // { firstDay: 7, weekend: [5, 6], minimalDays: 1 }
const af = new Intl.Locale("af");
console.log(af.getWeekInfo()); // { firstDay: 7, weekend: [6, 7], minimalDays: 1 }
const enGB = new Intl.Locale("en-GB");
console.log(enGB.getWeekInfo()); // { firstDay: 1, weekend: [6, 7], minimalDays: 4 }
const msBN = new Intl.Locale("ms-BN");
console.log(msBN.getWeekInfo()); // { firstDay: 7, weekend: [5, 7], minimalDays: 1 }
// Brunei weekend is Friday and Sunday but not Saturday