Giter Club home page Giter Club logo

scheduler's Introduction

Scheduley

Build Status

Statement Coverage Function Coverage Line Coverage
Statements Functions Lines

Installation

NPM:

npm i scheduley --save

Yarn:

yarn add scheduley

Usage

Methods

Add

The scheduley().add(pattern) method takes a Pattern as a parameter and adds it to the schedule. A pattern describes the frequency at which an event occurs and how long its occurs for.

Examples:

An event which occurs ever day indefinitely:

scheduley().add({
    startDate: new Date(),
    frequency: {
        measure: 1,
        unit: 'day'
    },
    event: {
        title: 'An event',
        description: 'My daily event.'
    }
})

An event which occurs every 2 weeks indefinitely:

scheduley().add({
    startDate: new Date(),
    frequency: {
        measure: 2,
        unit: 'week'
    },
    event: {
        title: 'An event',
        description: 'My bi-weekly event.'
    }
})

An event which occurs every 6 months between two dates:

scheduley().add({
    startDate: new Date('2023-01-01 12:00:00'),
    endDate: new Date('2025-01-01 12:00:00'),
    frequency: {
        measure: 6,
        unit: 'month'
    },
    event: {
        title: 'An event',
        description: 'My bi-annual event.'
    }
})

Calendar

The scheduley().calendar(startDate, endDate) method takes two Date parameters and generates an Array of Occurrences which describes all occurrences of events in the date range.

Example:

const event1 = {
    startDate: new Date('2023-01-01 12:00:00'),
    endDate: new Date('2023-01-05 12:00:00'),
    frequency: {
        measure: 1,
        unit: 'day'
    },
    event: {
        title: 'My first event.',
        description: 'This happens daily.'
    }
}
const event2 = {
    startDate: new Date('2023-01-01 12:00:00'),
    endDate: new Date('2023-01-05 12:00:00'),
    frequency: {
        measure: 2,
        unit: 'day'
    },
    event: {
        title: 'My second event.',
        description: 'This happens every 2 days.'
    }
}

const schedule = scheduley()
    .add(event1)
    .add(event2)

console.log(schedule.calendar());

Would output:

[
    {
        "event": {
            "title": "My first event.",
            "description": "This happens daily."
        },
        "date": "2023-01-01T12:00:00.000Z"
    },
    {
        "event": {
            "title": "My second event.",
            "description": "This happens every 2 days."
        },
        "date": "2023-01-01T12:00:00.000Z"
    },
    {
        "event": {
            "title": "My first event.",
            "description": "This happens daily."
        },
        "date": "2023-01-02T12:00:00.000Z"
    },
    {
        "event": {
            "title": "My first event.",
            "description": "This happens daily."
        },
        "date": "2023-01-03T12:00:00.000Z"
    },
        {
        "event": {
            "title": "My second event.",
            "description": "This happens every 2 days."
        },
        "date": "2023-01-03T12:00:00.000Z"
    },
    {
        "event": {
            "title": "My first event.",
            "description": "This happens daily."
        },
        "date": "2023-01-04T12:00:00.000Z"
    },
    {
        "event": {
            "title": "My first event.",
            "description": "This happens daily."
        },
        "date": "2023-01-05T12:00:00.000Z"
    },
    {
        "event": {
            "title": "My second event.",
            "description": "This happens every 2 days."
        },
        "date": "2023-01-05T12:00:00.000Z"
    }
]

Types

Pattern

A pattern is the duration and frequency in which an event occurs on a schedule.

Property Type Description
event any An event which occurs within this pattern.
startDate Date The date which the pattern starts from.
endDate Date | undefined The date which the pattern ends on.
frequency Frequency The frequency which the event occurs within the date period for this pattern.

Frequency

A frequency is the date interval at which an event should occur.

Property Type Description
unit Unit The unit of frequency: daily, weekly, monthly or yearly.
measure number The number of units.

Unit

The measure of time used to describe the frequency of an event.

Property Type Description
day string A day.
week string A week.
month string A month.
year string A year.

Occurrence

An concrete of an event on a specific date generated from a pattern on the schedule.

Property Type Description
event any An event which occurs on a date.
date Date The date on which the event occurs.

scheduler's People

Contributors

scottdrinkwater avatar

Stargazers

 avatar Peter Smith avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.