A zero dependency class schedule manager.
- Using npm
npm install class-scheduler
- Using yarn
yarn add class-scheduler
-
TypeScript / JavaScript ES6+
import { Schedule } from 'class-scheduler';
-
Common JS
const { Schedule } = require('class-scheduler');
Create the calendar array in the following structure for each day in a week:
const calendar = [
{
day: 'Sunday',
timeRange: [],
classes: []
},
{
day: 'Monday',
timeRange: [
{ start: { hour: 12, minute: 30 }, end: { hour: 13, minute: 30 } },
...
],
classes: ['Class 1', ...]
}
...
];
The array must have a length of 7.
const sch = new Schedule(calendar);
const currentClass = sch.getCurrentClass();
const nextClass = sch.getNextClass();
const laterClass = sch.getLaterClass();
Array<{
day: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
timeRange: Array<{
start: {
hour: number;
minute: number;
};
end: {
hour: number;
minute: number;
};
}>;
classes: Array<string>
}>;
See Quick Start Usage guide to get a grasp of the schema.
NOTE
The package is not mature enough to check if the length of the timeRange[]
comply with the length of classes[]
or to check if the given time limit is valid or even the size of the entire array. Please make sure that you don't do anything wrong such things before reporting a bug.
Scheduler offers several options to customize the messages shown during break times, when there are no classes, when the classes are yet to start or when the all classes have ended already.
You can do that in one of the following ways:
constructor(calendar: Calendar, options?: object)
The options object contains the following properties:
Property | Type | Default | Description |
---|---|---|---|
noScheduleMessage | string | 'No Schedule' | No schedule for the time being, default when other messages are not provided |
breakMessage | string | 'Break' | Break in-between two classes |
classesOverMessage | string | 'Classes are over' | Classes are over for today |
yetToBeginMessage | string | 'Yet to begin' | Today's classes are yet to begin |
Method name | Parameter type | Description |
---|---|---|
setNoScheduleMessage | string | No schedule for the time being, default when other messages are not provided |
setBreakMessage | string | Break in-between two classes |
setClassesOverMessage | string | Classes are over for today |
setYetToStartMessage | string | Today's classes are yet to begin |
Arguments: None
All the classes of the week as array of array.
Type: Array<Array<string>>
Get Period number corresponding to a given time.
Name | Type | isMandatory | Default |
---|---|---|---|
time | Date | false | current time |
The period number corresponding to the given time. 0 corresponds to 1st period of the day.
Type: number
Value | Meaning |
---|---|
-4 | Break |
-3 | No classes today |
-2 | Classes have ended |
-1 | Classes are yet to start |
Get Classes of a given Date/ Day number. Day number 0 corresponds to Sunday.
Name | Type | isMandatory | Default |
---|---|---|---|
date | Date / number | false | current date |
An array of all the classes in the given day.
Type: Array<string>
Get the Class corresponding to a given period and day.
Name | Type | isMandatory | Default |
---|---|---|---|
period | number | false | current period |
date | Date / number | false | current date |
The Class corresponding to a given period and day.
Type: string
()
-> currentPeriod
(n)
-> today's nth period
(n, d)
-> Day d's nth period
Get the Class schedule corresponding to given days.
Name | Type | isMandatory | Default |
---|---|---|---|
date | ... string | true | not set |
An array of all the classes that matches the given days.
Type: Array<string>
For single day
getClassByDay('Monday')
For multiple days
getClassByDay('Monday' , 'Friday')
Get the class for current time.
Name | Type | isMandatory | Default | Description |
---|---|---|---|---|
{useMeaningfulMessage} | boolean | false | false | Toggle usage of custom No schedule message |
The current class.
Type: string
Get the next upcoming class.
Name | Type | isMandatory | Default | Description |
---|---|---|---|---|
{allowNextDay} | boolean | false | false | Toggle next day look up |
The next upcoming class.
Type: string
Get the class coming after the next class.
Name | Type | isMandatory | Default | Description |
---|---|---|---|---|
{allowNextDay} | boolean | false | false | Toggle next day look up |
The class coming after the next class.
Type: string
Krishna Moorthy |
Santhosh |
Pranav |
Refer the contributing guide here.
Maintained by