Overview
Unless otherwise specified, all parameters are named parameters (i.e., functions take an object as an argument, and extract parameters from the object).
Month
getCalendarMonth
Convenience method Returns a set of weeks for a predefined month range. By default, this returns a calendar month - i.e., 5 weeks/35 days. A calendar month includes days preceding and following the actual days of the month.
Create a simple Month set:
import {getCalendarMonth} from 'calendar-model/lib/month';
export default getCalendarMonth({date});
This returns a one-dimensional array.
Parameters
startDate
The Start Date for result set compilation.getEvents
The event binder method. Calendar Model provides a default implementation; however, you can also write your own. For details see Writing an Event Binder.formatDate
A function that formats a JSDate
object. The default formatter formats dates in International format (dd/mm/yyyy).weeksInMonth
The number of weeks in a month. The default value is 5.
getNestedCalendarMonth
Convenience method Returns a set of weeks for a predefined month range. By default, this returns a calendar month - i.e., 5 weeks/35 days. A calendar month includes days preceding and following the actual days of the month. This method returns a nested set (two-dimensional array).
A nested set is useful when you need to loop through rows and columns, for example when displaying tabular data.
Create a nested Month set:
import {getNestedCalendarMonth} from 'calendar-model/lib/month';
export default getNestedCalendarMonth({date});
This returns a two-dimensional array.
Parameters
startDate
The Start Date for result set compilation.getEvents
The event binder method. Calendar Model provides a default implementation; however, you can also write your own. For details see Writing an Event Binder.formatDate
A function that formats a JSDate
object. The default formatter formats dates in International format (dd/mm/yyyy).weeksInMonth
The number of weeks in a month. The default value is 5.
monthNameFinder
Given a month number, return the name coresponding to it. A default name finder is provided, using English Month names. You can provide your own set of month names to override this. See below for details.
Find a month name:
import {monthNameFinder} from 'calendar-model/lib/month';
const getMonthName = monthNameFinder();
/**
* @param {number} month
* @param {number} year
* @returns {string}
*/
function getCalendarTitle(month, year) {
return `${getMonthName(month)}: ${year}`;
}
To provide your own set of months names:
import {monthNameFinder} from 'calendar-model/lib/month';
const MONATE = ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
const getMonthName = monthNameFinder(MONATE);
Week
getNWeeks
Returns a set of weeks.
Create a Week set:
import {getNWeeks} from 'calendar-model/lib/week';
export default getNWeeks({date, numOfWeeks: 2});
The code above returns a flat set of two weeks.
Parameters
date
The start date seed. A valid date value (mm/dd/yyyy). Calendar Model always returns full weeks, calculated from the beginning of the week (i.e., Sunday). Therefore, Calendar Model will take whatever date is passed to it, and obtain the start of the week for that date. For example, if the date was03/15/2017
, a Wednesday, Calendar Model would set the start date seed at03/12/2017
, the Sunday of that week. NOTE: If you need to create a set of weeks starting at a mid-point in the week, usegetNDays
.numOfWeeks
The number of weeks to return.getEvents
The event binder method. Calendar Model provides a default implementation; however, you can also write your own. For details see Writing an Event Binder.formatDate
A function that formats a JSDate
object. The default formatter formats dates in International format (dd/mm/yyyy).
getNWeeksNested
Returns a set of weeks.
Create a nested Week set:
import {getNWeeksNested} from 'calendar-model/lib/week';
export default getNWeeksNested({date, numOfWeeks: 2});
The code above returns a nested set of two weeks.
Parameters
date
The start date seed. A valid date value (mm/dd/yyyy). Calendar Model always returns full weeks, calculated from the beginning of the week (i.e., Sunday). Therefore, Calendar Model will take whatever date is passed to it, and obtain the start of the week for that date. For example, if the date was03/15/2017
, a Wednesday, Calendar Model would set the start date seed at03/12/2017
, the Sunday of that week. NOTE: If you need to create a set of weeks starting at a mid-point in the week, usegetNDays
.numOfWeeks
The number of weeks to return.getEvents
The event binder method. Calendar Model provides a default implementation; however, you can also write your own. For details see Writing an Event Binder.formatDate
A function that formats a JSDate
object. The default formatter formats dates in International format (dd/mm/yyyy).
Day
getNDays
Returns a set of days.
Create a Day set:
import {getNDays} from 'calendar-model/lib/day';
export default getNWeeksNested({startDate, numOfDays: 2});
The code above returns a set of two days. Queries for days always return flat sets.
Parameters
startDate
The start date.numOfDays
The number of weeks to return.getEvents
The event binder method. Calendar Model provides a default implementation; however, you can also write your own. For details see Writing an Event Binder.formatDate
A function that formats a JSDate
object. The default formatter formats dates in International format (dd/mm/yyyy).
getDay
Returns a day.
Create a Day:
import {getDay} from 'calendar-model/lib/day';
export default getDay({date, getEvents, formatDate, toISOString});
The code above returns a set of two days. Queries for days always return flat sets.
Parameters
date
The date.getEvents
The event binder method. Calendar Model provides a default implementation; however, you can also write your own. For details see Writing an Event Binder.formatDate
A function that formats a JSDate
object. The default formatter formats dates in International format (dd/mm/yyyy).toISOString
A function that formats the date into ISO format. The default formatter uses the built-in JS DatetoISOString
function.