@yct/schedule
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Build Status Coverage Status MIT license

Installation

npm i -S @yct/schedule

or

yarn add @yct/schedule

Usage

import { 
  IEvent,
  IRules,
  Schedule 
} from '@yct/schedule';

const rules: IRules = ... // rules
const events: IEvent[] = ... // events
const schedule = new Schedule(rules, events);

Rules

There are 3 different types of rules.

  • daily rule
  • weekly rule
  • date rule

Priority: daily < weekly < date

Daily rule example available from 9am to 5pm

  const dailyRule: IDailyRule = Array(24).fill(0)
  .map((x, y) => x + y)
  .map(x: IRuleItem => {
    return {
      available: x >= 9 && x < 17,
    };
  });
  const rules: IRules = {
    daily: dailyRule,
  };

Weekly rule example weekdays available

  const nonAvailableDay = Array(24).fill({
    available: false
  });
  const weekdaysRule: IWeeklyRule = Array(5).fill(dailyRule);
  const weeklyRules: IWeeklyRule = [].concat(nonAvailableDay, weekdaysRule, nonAvailableDay)
  const rules: IRules = {
    weekly: weeklyRule,
  };

Date rule example bank holiday

import * as moment from 'moment';

const r: IRules = {
  date: [
    {
      date: moment('...'), // date of a bank holiday
      rule: Array(24).fill({
        available: false
      })
    }
  ]
};

Events

import * as moment from 'moment';

const events: IEvent[] = [
  {
    date: moment().hour(0).minute(0).second(0).millisecond(0),
    name: 'test event',
    detail: 'just a test',
  },
  {
    date: moment().hour(1).minute(0).second(0).millisecond(0),
    name: 'another test event',
    detail: 'just a test',
  },
];

Schedule methods and properties

public rules: IRules;
public events: IEvent[];

public presentCurrentMonth(): Calendar;
public presentMonth(date: Date | moment.Moment | string): Calendar;
public presentCurrentDate(): CalendarDate;
public presentDate(date: Date | moment.Moment | string): CalendarDate;

Calendar methods and properties

public items: ICalendarItem[];
public selected: ICalendarItem;

public select(item: ICalendarItem): void;

CalendarDate methods and properties

public hours: ICalendarHour[];
public selected: ICalendarHour;

public select(hour: ICalendarHour): void;

Readme

Keywords

none

Package Sidebar

Install

npm i @yct/schedule

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • kuyoonjo