All Projects → harrisiirak → Cron Parser

harrisiirak / Cron Parser

Licence: mit
Node.js library for parsing crontab instructions

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Cron Parser

Wecron
✔️ 微信上的定时提醒 - Cron on WeChat
Stars: ✭ 537 (-33.04%)
Mutual labels:  cron, crontab
Agendash
Agenda Dashboard
Stars: ✭ 620 (-22.69%)
Mutual labels:  cron, crontab
asparagus
An easy to use task scheduler for distributed systems
Stars: ✭ 14 (-98.25%)
Mutual labels:  cron, crontab
crontab
cron expression parser and executor for dotnet core.
Stars: ✭ 13 (-98.38%)
Mutual labels:  cron, crontab
crony
Manage remote crontabs from your terminal
Stars: ✭ 12 (-98.5%)
Mutual labels:  cron, crontab
croncal
Utility to convert a crontab file to a list of actual events within a date range.
Stars: ✭ 37 (-95.39%)
Mutual labels:  cron, crontab
lambda-cron
LambdaCron - serverless cron tool
Stars: ✭ 22 (-97.26%)
Mutual labels:  cron, crontab
croner
Trigger functions and/or evaluate cron expressions in JavaScript. No dependencies. Most features. All environments.
Stars: ✭ 169 (-78.93%)
Mutual labels:  cron, crontab
Chronos
Fault tolerant job scheduler for Mesos which handles dependencies and ISO8601 based schedules
Stars: ✭ 4,303 (+436.53%)
Mutual labels:  cron, crontab
php-cron-expr
Ultra lightweight, Dependency free and Super Fast Cron Expression parser for PHP
Stars: ✭ 42 (-94.76%)
Mutual labels:  cron, crontab
Automation-using-Shell-Scripts
Development Automation using Shell Scripting.
Stars: ✭ 41 (-94.89%)
Mutual labels:  cron, crontab
Dynamic Wallpaper
A simple bash script to set wallpapers according to current time, using cron job scheduler.
Stars: ✭ 762 (-4.99%)
Mutual labels:  cron, crontab
watchman
📆 更夫(watchman)是一款可视化的定时任务配置 Web 工具,麻麻不用担心我漏掉任何更新啦!
Stars: ✭ 40 (-95.01%)
Mutual labels:  cron, crontab
LexikCronFileGeneratorBundle
This symfony bundle provides service for generate cron file
Stars: ✭ 20 (-97.51%)
Mutual labels:  cron, crontab
node-cron-expression
Declarative functional cron expression builder
Stars: ✭ 17 (-97.88%)
Mutual labels:  cron, crontab
mi-cron
📆 A microscopic parser for standard cron expressions.
Stars: ✭ 16 (-98%)
Mutual labels:  cron, crontab
Cronsun
A Distributed, Fault-Tolerant Cron-Style Job System.
Stars: ✭ 2,493 (+210.85%)
Mutual labels:  cron, crontab
delay-timer
Time-manager of delayed tasks. Like crontab, but synchronous asynchronous tasks are possible scheduling, and dynamic add/cancel/remove is supported.
Stars: ✭ 257 (-67.96%)
Mutual labels:  cron, crontab
cronitor-cli
Command line tools for Cronitor.io
Stars: ✭ 31 (-96.13%)
Mutual labels:  cron, crontab
Gocron
定时任务管理系统
Stars: ✭ 4,198 (+423.44%)
Mutual labels:  cron, crontab

cron-parser

Build Status NPM version

Node.js library for parsing and manipulating crontab instructions. It includes support for timezones and DST transitions.

Compatibility
Node >= 0.8
Typescript <= 4.2

Setup

npm install cron-parser

Supported format

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

Supports mixed use of ranges and range increments (L and W characters are not supported currently). See tests for examples.

Usage

Simple expression.

var parser = require('cron-parser');

try {
  var interval = parser.parseExpression('*/2 * * * *');

  console.log('Date: ', interval.next().toString()); // Sat Dec 29 2012 00:42:00 GMT+0200 (EET)
  console.log('Date: ', interval.next().toString()); // Sat Dec 29 2012 00:44:00 GMT+0200 (EET)

  console.log('Date: ', interval.prev().toString()); // Sat Dec 29 2012 00:42:00 GMT+0200 (EET)
  console.log('Date: ', interval.prev().toString()); // Sat Dec 29 2012 00:40:00 GMT+0200 (EET)
} catch (err) {
  console.log('Error: ' + err.message);
}

Iteration with limited timespan. Also returns ES6 compatible iterator (when iterator flag is set to true).

var parser = require('cron-parser');

var options = {
  currentDate: new Date('Wed, 26 Dec 2012 12:38:53 UTC'),
  endDate: new Date('Wed, 26 Dec 2012 14:40:00 UTC'),
  iterator: true
};

try {
  var interval = parser.parseExpression('*/22 * * * *', options);

  while (true) {
    try {
      var obj = interval.next();
      console.log('value:', obj.value.toString(), 'done:', obj.done);
    } catch (e) {
      break;
    }
  }

  // value: Wed Dec 26 2012 14:44:00 GMT+0200 (EET) done: false
  // value: Wed Dec 26 2012 15:00:00 GMT+0200 (EET) done: false
  // value: Wed Dec 26 2012 15:22:00 GMT+0200 (EET) done: false
  // value: Wed Dec 26 2012 15:44:00 GMT+0200 (EET) done: false
  // value: Wed Dec 26 2012 16:00:00 GMT+0200 (EET) done: false
  // value: Wed Dec 26 2012 16:22:00 GMT+0200 (EET) done: true
} catch (err) {
  console.log('Error: ' + err.message);
}

Timezone support

var parser = require('cron-parser');

var options = {
  currentDate: '2016-03-27 00:00:01',
  tz: 'Europe/Athens'
};

try {
  var interval = parser.parseExpression('0 * * * *', options);

  console.log('Date: ', interval.next().toString()); // Date:  Sun Mar 27 2016 01:00:00 GMT+0200
  console.log('Date: ', interval.next().toString()); // Date:  Sun Mar 27 2016 02:00:00 GMT+0200
  console.log('Date: ', interval.next().toString()); // Date:  Sun Mar 27 2016 04:00:00 GMT+0300 (Notice DST transition)
} catch (err) {
  console.log('Error: ' + err.message);
}

Manipulation

var parser = require('cron-parser');

var interval = parser.parseExpression('0 7 * * 0-4');
var fields = JSON.parse(JSON.stringify(interval.fields)); // Fields is immutable
fields.hour = [8];
fields.minute = [29];
fields.dayOfWeek = [1,3,4,5,6,7];
var modifiedInterval = parser.fieldsToExpression(fields);
var cronString = modifiedInterval.stringify();
console.log(cronString); // "29 8 * * 1,3-7"

Options

  • currentDate - Start date of the iteration
  • endDate - End date of the iteration

currentDate and endDate accept string, integer and Date as input.

In case of using string as input, not every string format accepted by the Date constructor will work correctly. The supported formats are: ISO8601 and the older ASP.NET JSON Date format. The reason being that those are the formats accepted by the moment library which is being used to handle dates.

Using Date as an input can be problematic specially when using the tz option. The issue being that, when creating a new Date object without any timezone information, it will be created in the timezone of the system that is running the code. This (most of times) won't be what the user will be expecting. Using one of the supported string formats will solve the issue(see timezone example).

  • iterator - Return ES6 compatible iterator object
  • utc - Enable UTC
  • tz - Timezone string. It won't be used in case utc is enabled
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].