Git Product home page Git Product logo

cron-time's Introduction

Cron-Time

Cron Time Expression Generator/Builder written in Typescript.

Tested on CronTab.Guru

Install

npm install cron-time-generator

OR

yarn add cron-time-generator

Setup

// Javascript
const {CronTime} = require('cron-time-generator');
// OR 
const {default: CronTime} = require('cron-time-generator');

// Typescript
import {CronTime} from "cron-time-generator";
// OR
import CronTime from "cron-time-generator";

The CronTime class is the main class that contains all the methods for generating cron expressions. it is the default export of the package and also has a named export called CronTime

Setup

CronTime.everyMinute();
// * * * * *

CronTime.everyHour();
// 0 * * * *

CronTime.everyDay();
// 0 0 * * *

CronTime.everyDayAt(6);
// 0 6 * * *

CronTime.everyDayAt(6, 15);
// 15 6 * * *

CronTime.everySunday();
// 0 0 * * SUN

CronTime.everySundayAt(4, 30);
// 30 4 * * SUN

CronTime.everyWeekDay();
// 0 0 * * 1-5
// from Monday to Friday

CronTime.everyWeekDayAt(1, 30);
// 30 1 * * 1-5
// 1:30 AM from Monday to Friday

CronTime.everyWeekend();
// 0 0 * * 6,0
// on Saturday and Sunday

CronTime.everyWeekendAt(1, 30);
// 30 1 * * 6,0
// 1:30 AM on Saturday and Sunday

// E.T.C

For everyWeekDay and everyWeekend there is also an option to change the starting day.

By default, week days is from Monday to Friday while weekend days are Saturdays and Sundays

This can be changed like so:

CronTime.everyWeekDay("sunday", "thursday");
// 0 0 * * 0-4
// from Sunday to Thursday

CronTime.everyWeekDayAt(1, 30, "sunday", "thursday");
// 30 1 * * 0-4
// 1:30 AM from Sunday to Thursday

CronTime.everyWeekend("friday", "saturday");
// 0 0 * * 5,6
// on Friday and Saturday

CronTime.everyWeekendAt(1, 30, "friday", "saturday");
// 30 1 * * 5,6
// 1:30 AM on Friday and Saturday

Note: if a startDay is specified then an endDay must be specified also, else it will use the default values which may not tally with your new $startDay

Every method of CronTime returns exactly what its name says.

onSpecificDays and onSpecificDaysAt

To target specific days

CronTime.onSpecificDays(['sunday', 'tuesday', 'thursday']); // 0 0 * * 0,2,4

// With time 
CronTime.onSpecificDaysAt(['sunday', 'tuesday', 'thursday'], 3, 30); // 0 0 * * 0,2,4

Every Nth Time

const CronTime = require('cron-time-generator');

CronTime.every(5).minutes();
// Every Five Minutes

CronTime.every(2).hours();
// Every 2 Hours

CronTime.every(7).days();
// Every 7 Days

CronTime.every(7).days(9, 5);
// Every 7 days at 9:05

CronTime.every('even').hours();
// Every Even Hours
// * */2 * * *

CronTime.every('uneven').hours();
// Every Uneven Hours
// * 1-23/2 * * *

Between

const {CronTime} = require('cron-time-generator');

CronTime.between(1, 4).days();
// Between  1 - 4 th day of the month 

All Functions

every

between

everyMinute

everyHour

everyHourAt(minuteOfTheHour)

everyDay

everyDayAt(hoursOfTheDay)

everySunday

everySundayAt(hours, minutes?)

everyMonday

everyMondayAt(hours, minutes?)

everyTuesday

everyTuesdayAt(hours, minutes?)

everyWednesday

everyWednesdayAt(hours, minutes?)

everyThursday

everyThursdayAt(hours, minutes?)

everyFriday

everyFridayAt(hours, minutes?)

everySaturday

everySaturdayAt(hours, minutes?)

everyWeek

everyWeekAt(days, hours?, minutes?)

everyWeekDay

everyWeekDayAt(hours, minutes?, startDay?, endDay?)

everyWeekend

everyWeekendAt(hours, minutes?, startDay?, endDay?)

everyMonth

everyMonthOn(days, hours?, minutes?)

everyYear

everyYearIn(months, days?, hours?, minutes?)

onSpecificDays(days)

onSpecificDaysAt(days, hour, minutes?)

cron-time's People

Contributors

davidamunga avatar dkirchhof avatar evilprogrammerng avatar localpcguy avatar onra avatar trapcodeio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cron-time's Issues

no option for minutes

For example if I use everyDayAt('hourOfTheDay') but I need to set every day at 7:15
I'm not able to set minutes.

Module 'cron-time-generator/dist/EveryTime"' can only be default-imported using the 'allowSyntheticDefaultImports' flag

When using the latest version of the package, I get this error:

Module '"<my-path>/node_modules/cron-time-generator/dist/EveryTime"' can only be default-imported using the 'allowSyntheticDefaultImports' flag

1 import EveryTime from "./EveryTime";
         ~~~~~~~~~

  node_modules/cron-time-generator/dist/EveryTime.d.ts:32:1
    32 export = EveryTime;
       ~~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.

Adding the "allowSyntheticDefaultImports": true in my project doesn't fix this. Are you ok with me creating a PR in order to change from export = EveryTime; to export default class EveryTime ?

support for everyweekendAt with more than 2 days

I saw that I can do:

cronTime.everyWeekendAt(3, 30, 0, 4));

to generate:

30 3 * * 0,4
// At 03:30 on Sunday and Thursday

but I was wondering if there is an option for more than 2 days, so I can generate:

30 3 * * 0,2,4
// At 03:30 on Sunday, Tuesday, and Thursday

This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag

error TS1259: Module '"/Users/rdjurasaj/code/ngtoc-devops/data-transfer-factory/node_modules/cron-time-generator/dist/index"' can only be default-imported using the 'esModuleInterop' flag

4 import cronTime from "cron-time-generator";
         ~~~~~~~~

  node_modules/cron-time-generator/dist/index.d.ts:203:1
    203 export = CronTime;
        ~~~~~~~~~~~~~~~~~~
    This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

It works with esModuleInterop flag in tsconfig.json but it's a workaround.

Esm Version

โฐ Reminder to convert to ESM with CJS support.

Single execution

Is there a way to do a single execution, for example December 22 2022 at 3:30pm?

issue with once in every x hours

every method isn't working as intended?
for example: cronTime.every(4).hours() outputs * */4 * * * which is Every minute, every 4 hours as opposed to once in every 4 hours.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.