A date & schedule library to use for advanced calendars in TypeScript and JS.
bower install dayspan
or npm install dayspan
// A monthly calendar around today (string=event data type, any=schedule metadata type)
let cal = Calendar.months<string, any>();
// Every Monday 9:00 - 9:30
cal.addEvent({
data: 'Weekly Meeting',
schedule: {
dayOfWeek: Weekday.MONDAY,
times: 9,
duration: 30,
durationUnit: 'minutes'
}
});
// Dr. Appointment on 01/04/2018
cal.addEvent({
data: 'Dr. Appointment',
visible: false,
schedule: {
on: Day.build(2018, Month.APRIL, 1)
}
});
// Mother's Day
cal.addEvent({
id: 'someUserProvidedId',
data: "Mother's Day",
schedule: new Schedule({
weekspanOfMonth: 1, // 2nd
dayOfWeek: Weekday.SUNDAY, // Sunday
month: Month.MAY // of May
})
});
// The array of days in the month, each day has a list of the days events.
cal.days;
// Go to the next month
cal.next();
// Select this day and update the selection flags in the calendar days
cal.select(Day.build(2018, Month.APRIL, 12));
// Remove the schedule
cal.removeEvent('Weekly Meeting');
// A weekly calendar with custom MyEvent class
Calendar.weeks<MyEvent, any>();
// A daily calendar covering 3 days centered on today
Calendar.days<string, any>(3);
// A daily calendar covering 3 days starting with given date
Calendar.days<string, any>(3, Day.build(2018, Month.JUNE, 15), 0);
You just need to append ds
to the beginning of the classes:
// A monthly calendar around today
var cal = ds.Calendar.months();
// Every Monday 9:00 - 9:30
cal.addEvent({
data: 'Weekly Meeting',
schedule: {
dayOfWeek: [ds.Weekday.MONDAY],
times: 9,
duration: 30,
durationUnit: 'minutes'
}
});
// Dr. Appointment on 01/04/2018
cal.addEvent({
data: 'Dr. Appointment',
schedule: new ds.Schedule({
on: ds.Day.build(2018, ds.Month.APRIL, 1)
})
});
A map of CalendarTypeDefinition keyed by the Units.
All valid types which may be converted to a Day instance.
number
: A UNIX timestamp.string
: A string representation of a date.Day
: An existing Day instance.number[]
: An array of numbers specifying any of: [year, month, dayOfMonth, hour, minute, second, millisecond].object
: An object with any of the following properties: year, month, dayOfMonth, hour, minute, second, millisecond.true
: This will be interpreted as Day.todayOne of the properties on the Day object.
A frequency that occurs at a constant rate or only on specific values.
A frequency that occurs once.
A frequency that occurs only on specific values.
The type for identifiers. Most of the time an identifier can be stored as a number because the 4 digit year is first. However when the year is below 1000 a string will be used with zero padding. Storing identifiers as numbers enable very quick comparisons and using strings or numbers allows the identifier to be used as a key to a map.
A rule helps parse ScheduleInput and determines whether it matches the given pattern.
A tuple which identifies an event on the schedule. The tuple contains the total span of the event occurrence, the day of the event (could be the start day, end day, or any days in between for multi-day events) as well as the identifier for the event.
A function which takes two CalendarEvents and returns a number which instructs a sort which event goes before the other in a list.
A value that can possibly be parsed into a Time instance.
The map of patterns keyed by their name.
The list of patterns that can be searched through for matches to schedule input.
Formats time into a string. The following list describes the available formatting patterns:
Performs the requested operation on the given number, optionally taking the absolute value of the number before the operation.
The number to operate on.
The operation to perform.
If the number should be positive before the operation.
The operated result, or the original value if its not a valid number.
The number of milliseconds for various duration units. These are worse case scenario and do not include DST changes.
Generated using TypeDoc
A function which moves a given day by some amount and some unit. This is used to shift a calendar's frame via Calendar.next and Calendar.prev.
The day to move.
The amount to move the day by.
A new day instance moved by the given amount.