The MonthCalendar object provides support for generating month calendars.
Fetch arrays of weeks containing Date objects for the current month of the year:
var currentDate = new Date;
var monthCalendar = new MonthCalendar(currentDate.getFullYear(), currentDate.getMonth(), 1);
var weekRow;
while (weekRow = monthCalendar.fetchRow()) {
console.log(weekRow);
}
Will output:
[Log] [
Mon Jan 01 2018 00:00:00 GMT+0300 (+03),
Tue Jan 02 2018 00:00:00 GMT+0300 (+03),
Wed Jan 03 2018 00:00:00 GMT+0300 (+03),
Thu Jan 04 2018 00:00:00 GMT+0300 (+03),
Fri Jan 05 2018 00:00:00 GMT+0300 (+03),
Sat Jan 06 2018 00:00:00 GMT+0300 (+03),
Sun Jan 07 2018 00:00:00 GMT+0300 (+03)
] (7)
[Log] [
Mon Jan 08 2018 00:00:00 GMT+0300 (+03),
Tue Jan 09 2018 00:00:00 GMT+0300 (+03),
Wed Jan 10 2018 00:00:00 GMT+0300 (+03),
Thu Jan 11 2018 00:00:00 GMT+0300 (+03),
Fri Jan 12 2018 00:00:00 GMT+0300 (+03),
Sat Jan 13 2018 00:00:00 GMT+0300 (+03),
Sun Jan 14 2018 00:00:00 GMT+0300 (+03)
] (7)
[Log] [
Mon Jan 15 2018 00:00:00 GMT+0300 (+03),
Tue Jan 16 2018 00:00:00 GMT+0300 (+03),
Wed Jan 17 2018 00:00:00 GMT+0300 (+03),
Thu Jan 18 2018 00:00:00 GMT+0300 (+03),
Fri Jan 19 2018 00:00:00 GMT+0300 (+03),
Sat Jan 20 2018 00:00:00 GMT+0300 (+03),
Sun Jan 21 2018 00:00:00 GMT+0300 (+03)
] (7)
new MonthCalendar(); new MonthCalendar(date); new MonthCalendar(year, month[, firstDayOfWeek]);
- date
-
A
Date
object. - year
-
Integer value representing the year. Values from 0 to 99 map to the years 1900 to 1999.
- month
-
Integer value representing the month, beginning with 0 for January to 11 for December.
- firstDayOfWeek
-
Optional. Integer value representing the first day of the week, beginning with 0 for Sunday to 6 for Saturday.
A new MonthCalendar
object.
- TypeError
-
Thrown if the
year
ormonth
orfirstDayOfWeek
parameters are not a number type. - RangeError
-
Thrown if the
year
andmonth
parameters results in an invalid combination.Thrown if the
firstDayOfWeek
parameter is out of range of valid values (0–6).
- Chrome
- Opera 5+
- Firefox
- Safari
- Internet Explorer 5.5+
Licensed under the BSD 3-Clause License.