1.0.1 • Published 5 years ago

cron-dates v1.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

Description

A simple and succinct way to generate recurring events from a single object.

Installation

$ npm install cron-dates --save

Usage

  const cronDates = require('./index');
  const moment = require('moment');

  // Some list of objects received from a DB
  const data = [
    {
      title: 'Restaurant',
      cron: '0 0 * * 1-5',
    }
  ];

  const now = moment().format();
  const nextWeek = moment().add(14, 'days');

  //
  const events = cronDates.generate(cronEvents, now, nextWeek);

  console.log(JSON.stringify(events, null, 2));
  /*
    Prints something like:
[
  {
    "title": "Restaurant",
    "date": "2019-10-15T13:00:00.000Z"
  },
  {
    "title": "Restaurant",
    "date": "2019-10-16T13:00:00.000Z"
  },
  {
    "title": "Restaurant",
    "date": "2019-10-17T13:00:00.000Z"
  },
  {
    "title": "Restaurant",
    "date": "2019-10-20T13:00:00.000Z"
  }
  ...
]
  */

Help with crontab syntax

https://crontab.guru/

1.0.1

5 years ago

1.0.0

5 years ago