1.2.1 • Published 3 years ago

class-scheduler v1.2.1

Weekly downloads
33
License
MIT
Repository
github
Last release
3 years ago

Installation

  • Using npm
npm install class-scheduler
  • Using yarn
yarn add class-scheduler

Quick Start

Importing

  • TypeScript / JavaScript ES6+

    import { Schedule } from 'class-scheduler';
  • Common JS

    const { Schedule } = require('class-scheduler');

Usage

The calendar array

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.

Initialize the Schedule object

const sch = new Schedule(calendar);

Get current class

const currentClass = sch.getCurrentClass();

Get upcoming classes

const nextClass = sch.getNextClass();
const laterClass = sch.getLaterClass();

Schema of the Calendar

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.


Custom messages

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:

1. Pass it using the constructor options parameter

constructor(calendar: Calendar, options?: object)

The options object contains the following properties:

PropertyTypeDefaultDescription
noScheduleMessagestring'No Schedule'No schedule for the time being, default when other messages are not provided
breakMessagestring'Break'Break in-between two classes
classesOverMessagestring'Classes are over'Classes are over for today
yetToBeginMessagestring'Yet to begin'Today's classes are yet to begin

2. Use methods to set specific messages

Method nameParameter typeDescription
setNoScheduleMessagestringNo schedule for the time being, default when other messages are not provided
setBreakMessagestringBreak in-between two classes
setClassesOverMessagestringClasses are over for today
setYetToStartMessagestringToday's classes are yet to begin

Methods

getClassTable

Arguments: None

Returns

All the classes of the week as array of array.

Type: Array<Array<string>>


getPeriodNumber

Get Period number corresponding to a given time.

Arguments

NameTypeisMandatoryDefault
timeDatefalsecurrent time

Returns

The period number corresponding to the given time. 0 corresponds to 1st period of the day.

Type: number

Special values
ValueMeaning
-4Break
-3No classes today
-2Classes have ended
-1Classes are yet to start

getClasses

Get Classes of a given Date/ Day number. Day number 0 corresponds to Sunday.

Arguments

NameTypeisMandatoryDefault
dateDate / numberfalsecurrent date

Returns

An array of all the classes in the given day.

Type: Array<string>


getClass

Get the Class corresponding to a given period and day.

Arguments

NameTypeisMandatoryDefault
periodnumberfalsecurrent period
dateDate / numberfalsecurrent date

Returns

The Class corresponding to a given period and day.

Type: string

Quick hint

() -> currentPeriod

(n) -> today's nth period

(n, d) -> Day d's nth period


getClassByDay

Get the Class schedule corresponding to given days.

Arguments

NameTypeisMandatoryDefault
date... stringtruenot set

Returns

An array of all the classes that matches the given days.

Type: Array<string>

Quick hint

For single day

getClassByDay('Monday')

For multiple days

getClassByDay('Monday' , 'Friday')


getCurrentClass

Get the class for current time.

Arguments Options

NameTypeisMandatoryDefaultDescription
{useMeaningfulMessage}booleanfalsefalseToggle usage of custom No schedule message

Returns

The current class.

Type: string


getNextClass

Get the next upcoming class.

Arguments Options

NameTypeisMandatoryDefaultDescription
{allowNextDay}booleanfalsefalseToggle next day look up

Returns

The next upcoming class.

Type: string


getLaterClass

Get the class coming after the next class.

Arguments Options

NameTypeisMandatoryDefaultDescription
{allowNextDay}booleanfalsefalseToggle next day look up

Returns

The class coming after the next class.

Type: string


Authors

Contributing

Refer the contributing guide here.

License

MIT License


1.2.0

3 years ago

1.2.1

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago