chenc-cron-parser
TypeScript icon, indicating that this package has built-in type declarations

4.9.0 • Public • Published

拓展 cron-parser 框架,支持年份

Node >= 12.0.0 TypeScript >= 4.2

步骤

npm install @ky/cron-parser
npm install dayjs

支持的格式

*    *    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    |    └ year (2000 - 2200)
│    │    │    │    │    └ day of week (0 - 7, 1L - 7L) (0 or 7 is Sun)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31, L)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, optional)

使用方式

必须按照这样写才能正常运行

import cronParse from '@ky/cron-parser'
import dayjs from 'dayjs'

const interval = cronParse.parseExpression('0 0 0 1,2,3 3,4,5 ? 2024')
const arr = []
for (let i = 0; i < 20; i++) {
  // 必须判断是否存在,否则会报错
  if (interval.hasNext()) {
    const datetime = dayjs(interval.next().toDate()).format('YYYY-MM-DD HH:mm:ss')
    arr.push(datetime)
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i chenc-cron-parser

Weekly Downloads

4

Version

4.9.0

License

MIT

Unpacked Size

49.5 kB

Total Files

11

Last publish

Collaborators

  • zhangyf_wansui