1.0.1 • Published 5 years ago
cron-dates v1.0.1
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"
}
...
]
*/