pcron
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

pcron

NPM version NPM downloads Build status

pcron is a periodical scheduler expression tool inspired by fcron

Example

PT1h 2020 * 21-22 * * *

Like the example above, it means "from 21 through 22 of every month in 2020, the scheduler will be executed every 1 hour".

For more example, see test

Installation

yarn add pcron

or

npm i pcron

Usage

import { parseExpression } from "pcron";
import dayjs from "dayjs";
 
const timestamp = dayjs("2020-09-23T00:00:00").unix();
// timestamp is a unix timestamp, a current timestamp will be used by default if you omit this parameter
const exp = parseExpression("PT1s 2020 9 23 0 0-1 0-1", timestamp);
const nextDate = exp.next(); // you will get a dayjs object represent 2020-09-23T00:00:01
const nextDate = exp.next(); // you will get a dayjs object represent 2020-09-23T00:01:00
const nextDate = exp.next(); // you will get a dayjs object represent 2020-09-23T00:01:01
const nextDate = exp.next(); // you will get null

Changelog

change log

License

MIT

Keywords

none

Install

DownloadsWeekly Downloads

0

Version

0.0.6

License

MIT

Unpacked Size

181 kB

Total Files

18

Last publish

Collaborators

  • 297951292