Giter Club home page Giter Club logo

later's Introduction

This project is no longer being maintained. It should be treated as sample code on one technique to calculate future instances of complex schedules. If you are looking to fire a task every 1 minute, use a cron scheduler instead.

Later is a library for describing recurring schedules and calculating their future occurrences. It supports a very flexible schedule definition including support for composite schedules and schedule exceptions. Create new schedules manually, via Cron expression, via text expressions, or using a fully chainable API.

Types of schedules supported by Later:

  • Run a report on the last day of every month at 12 AM except in December
  • Install patches on the 2nd Tuesday of every month at 4 AM
  • Gather CPU metrics every 10 mins Mon - Fri and every 30 mins Sat - Sun
  • Send out a scary e-mail at 13:13:13 every Friday the 13th

For complete documentation visit http://bunkat.github.io/later/.

Installation

Using npm:

$ npm install later

Using bower:

$ bower install later

Building

To build the minified javascript files for later, run npm install to install dependencies and then:

$ make all

Running tests

To run the tests for later, run npm install to install dependencies and then:

$ make test

Versioning

Releases will be numbered with the following format:

<major>.<minor>.<patch>

And constructed with the following guidelines:

  • Breaking backward compatibility bumps the major (and resets the minor and patch)
  • New additions without breaking backward compatibility bumps the minor (and resets the patch)
  • Bug fixes and misc changes bumps the patch

For more information on SemVer, please visit http://semver.org/.

Bug tracker

Have a bug or a feature request? Please open a new issue.

Change Log

Later v1.2.0

  • Implemented predefined scheduling definitions for cron
    • @yearly, @annually, @monthly, @weekly, @daily, and @hourly are now parsed correctly
    • Submitted by pekeler (thanks!)

Later v1.1.8, v1.1.9

  • Fixed npm and bower entry points

Later v1.1.7

  • Various bug fixes

Later v1.1.3

  • Merge consecutive ranges when using composite schedules (fixes issues #27)

Later v1.1.1 and v1.1.2

  • Fixed handling of ranged schedules which never go invalid. End date is undefined for these types of schedules.

Later v1.1.0

  • Implemented fullDate (fd) constraint to specify a specific occurrence (or exception)
    • later.parse.recur().on(new Date(2013,3,21,10,30,0)).fullDate()

Later v1.0.0

  • Refactored core engine so that it could be better tested
    • Added over 41,500 tests and fixed hundreds of edge cases that were unfortunately broken in v0.0.20
  • Core engine is now extensible via custom time periods and custom modifiers
    • Full examples included in the documentation
  • Added support for finding valid ranges as well as valid instances of schedules
    • Later can now be used to schedule activities and meetings as well as point in time occurrences
  • Improved support for finding past ranges and instances
    • Searching forward or backward now produces the same valid occurrences
  • No more need to specify a resolution!
    • Later now automatically handles this internally, you no longer need to specify your desired resolution. 'Every 5 minutes' now does exactly what you would expect it to :)
  • Changing between UTC and local time has changed.
    • Use later.date.UTC() and later.date.localTime() to switch between the two.
  • API for parsers has changed.
    • Recur is now at later.parse.recur()
    • Cron is now at later.parse.cron(expr)
    • Text is now at later.parse.text(expr)
  • API for calculating occurrences has changed.
    • Schedules are now compiled using later.schedule(schedule)
    • getNext is now later.schedule(schedule).next(count, start, end)
    • getPrev is now later.schedule(schedule).prev(count, start, end)
  • After meaning 'don't start until after this amount of time' has been deprecated.
    • This was a hack since people had a hard time with resolutions. With resolutions gone, this is no longer needed and is deprecated since it produced non-deterministic schedules.

Note: Schedule definitions did not change (unless you were using after constraints which have been deprecated). If you stored any schedule definitions from v0.0.20, they should continue to work unchanged in v1.0.0.

later's People

Contributors

billscheidel avatar bunkat avatar gautaz avatar ilanbiala avatar pekeler avatar peterdavehello avatar xorgy 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  avatar  avatar  avatar

Watchers

 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

later's Issues

schedule interprets every 5s as 1s

For some reason when i retreive schedules that have been stringified and stored in the database its interpreting nextRange(1) to be 1 second apart instead of 5 seconds.

/** This comes from db row.. initially created from parse.text of:
 *  'every 5 seconds
**/
var s = '{"schedules":[{"s":[0,5,10,15,20,25,30,35,40,45,50,55]}],"exceptions":[],"error":-1}';
var schedule = JSON.parse(s);
var nextRunTime = later.schedule(schedule).nextRange(1);

when you console.log(nextRunTime); you get:

[ Thu Aug 01 2013 15:52:10 GMT-0700 (MST),
  Thu Aug 01 2013 15:52:11 GMT-0700 (MST) ]

on() and dayOfYear() not working properly with later()

The following code works:

var rSched = recur().on(68).dayOfYear().at('11:00:00');
var results = later(60, true).get(rSched, 1, new Date());

Result:

array(1) {
    [0] => Date(Sun Mar 09 2014 11:00:00 GMT-0500 (Central Daylight Time))
}

However, on(69) it'll fail:

var rSched = recur().on(69).dayOfYear().at('11:00:00');
var results = later(60, true).get(rSched, 1, new Date());

Result:

array(1) {
}

Remove true as the second parameter to later() and it works again:

var rSched = recur().on(69).dayOfYear().at('11:00:00');
var results = later(60).get(rSched, 1, new Date());

Result:

array(1) {
    [0] => Date(Sun Mar 09 2014 11:00:00 GMT-0500 (Central Daylight Time))
}

double execution in google chrome and opera but not firefox

Hi,

I am doing a POC using later and discovered trying to execute a function on time
gives double execution, one on time and second time a few seconds later. I tested in Google Crome, Opera and Firefox. In firefox it looks good but in Google Chrome i get these double executions which feels quite unstable to me. The code is straigforward too. My PC is WIN7 PRO with intel i7 quad core, Please advice how to fix.

<script type="text/javascript" src="js/later.js"></script> <script type="text/javascript" src="js/jquery-1.9.2.min.js"></script> <script type="text/javascript"> var textSched = later.parse.text('every 15 sec'); // var textSched = later.parse.recur().every(1).minute(); var timer2 = later.setInterval(changeFrameSrc, textSched); function changeFrameSrc() { alert(new Date()); //timer2.clear(); // $("#showSrc").attr('src', 'http://www.w3schools.com'); } </script>

Every 1 hour runs every minute

In my testing, I've found that running every 1 hour appears to run each minute instead. This is in node.js, but it appears I'm getting the same results in the browser as well.

var l = later(60),
        schedule = enParser().parse("ever 1 hour");
l.exec(schedule, new Date(), execute_job, job);
2012-10-25 16:39:21.047230
2012-10-25 16:40:21.047031
2012-10-25 16:41:21.048893
2012-10-25 16:42:21.044633
2012-10-25 16:43:21.048364
2012-10-25 16:44:21.047145
2012-10-25 16:45:21.047585
2012-10-25 16:46:21.043886

I'm not sure if this is something I'm doing incorrectly (likely!), or a bug in the library...still investigating.
Thanks!

Later Persistance

Say my Node.js server crashes, will all Later jobs still be good to go (i.e. don't disappear) when the server is started again?

Edit: Silly question, my bad.

every X days

i have found that i can some what ask for like every 10 days. but its not what i really want

as an ex
later.parse.recur().every(10).dayOfMonth()
if i set the start date for next() as the 24th Jan 2014, the first date returned is the 31st Jan..
technically the 31st isn't 10 days from the start date.
i see that the schedule builds an array like 1,3,5,7..... when i specify every(2).dayOfMonth()
but if i set the start dates as 2nd Jan, i would have expected every two days to be 2,4,6,8...
i know i am doing it wrong because if it was every 3 days i would not get results like 31 jan,1 feb, as these are not 2 days apart

i need to be able to build a recurrence every X days from a given date?
any help please

oz

"every second" cron pattern support.

later.schedule(later.parse.cron('* * * * * *',true))

throws error. While * * * * * * is valid cron pattern.
It looks like to support this later has to support millisecond periods.
Or just replace * * * * * * or similar with 0/1 * * * * * in cron parser, which is the same.

Handle long sleep times

When handling a monthly schedule, the required sleep time (as passed to setTimeout in exec) might exceed 2^31-1 ms (about 24.9 days). When this happens, the callback is called immediately instead of when it's supposed to. A simple fix is to make a callback loop in exec that sleeps at most 2^31-1 ms at a time and then checks if the final time has been reached or not. I'd make a patch & pull request, but for some reason a lot of the tests fail out of the box on my installation so I don't want to mess with it. :/

Set TimeZone

Is there a way to set timezone in this module? My server is on UTC but I have to use Europe/Stockholm timezone but I am unable to set it.

shift date when falls on exception

Hi

I'm trying to work out something that might not be possible..
i am trying to build a dates array in a schedule, that includes exceptions, where if the date expected falls on an exception to move to the next possible date

as am example to make better sense here..
var sched = later.parse.recur().every(2).dayOfMonth().except().every().dayOfMonth().between(4,5).on(3).month().on(2014).year();

i get a list of dates:
Sat Mar 01 2014 00:00:00 GMT+1000 (EST)
Mon Mar 03 2014 00:00:00 GMT+1000 (EST)
Fri Mar 07 2014 00:00:00 GMT+1000 (EST) <--
Sun Mar 09 2014 00:00:00 GMT+1000 (EST) <--

since the schedule "without" the exception would fall on the 5th March, I'm looking to shift over to the next day.. to get a response like
Sat Mar 01 2014 00:00:00 GMT+1000 (EST)
Mon Mar 03 2014 00:00:00 GMT+1000 (EST)
Thu Mar 06 2014 00:00:00 GMT+1000 (EST) <--
Sat Mar 08 2014 00:00:00 GMT+1000 (EST) <--

so it would pick the next date that would be allowed (since every day is it would be the next day thats not excluded) and continue using this new date

thanks
oz

Persistence?

There is any persistence support for node? e.g. i define a recurring schedule, the app restarts and i want the same schedule to be there.

Tests failing.

Cloning, then running make test, I get over 3000 assertions failing, and make exiting with code 27.

cron day/weekday issue

if we have both day and weekday values, there is an incorrect calculation. See
sample: http://jsfiddle.net/SmYqS/

man 5 crontab:
Note: The day of a command's execution can be specified by two fields โ€” day of month, and day of week. If both fields are restricted (i.e., aren't *), the command will be run when either field matches the current time.

Odd behavior from next

I set up the following simple schedule:

sched = later.parse.recur().every(1).minute()
compSched = later.schedule sched
console.log compSched.next(10)
later.setInterval (-> update()), sched

update = ->
  # there is an async delay here of approx 7-8 seconds
  console.log compSched.next(2)

I get the following output from next(10):

[Fri Aug 09 2013 12:53:55 GMT-0700 (Pacific Daylight Time), Fri Aug 09 2013 12:54:00 GMT-0700 (Pacific Daylight Time), Fri Aug 09 2013 12:55:00 GMT-0700 (Pacific Daylight Time), Fri Aug 09 2013 12:56:00 GMT-0700 (Pacific Daylight Time), Fri Aug 09 2013 12:57:00 GMT-0700 (Pacific Daylight Time), Fri Aug 09 2013 12:58:00 GMT-0700 (Pacific Daylight Time), Fri Aug 09 2013 12:59:00 GMT-0700 (Pacific Daylight Time), Fri Aug 09 2013 13:00:00 GMT-0700 (Pacific Daylight Time), Fri Aug 09 2013 13:01:00 GMT-0700 (Pacific Daylight Time), Fri Aug 09 2013 13:02:00 GMT-0700 (Pacific Daylight Time)]

I don't understand why the the initial entry is there, which corresponds to the time the code was first run. Shouldn't the initial next value be the next "round" minute, i.e. the second entry?

Now, despite this, the update fires at exactly 12:54:00. But when l get the log output from the update method, the first value returned from next is not the true next value but rather the time the next(2) was executed, i.e. the same issue as above:

[Fri Aug 09 2013 12:54:07 GMT-0700 (Pacific Daylight Time), Fri Aug 09 2013 12:55:00 GMT-0700 (Pacific Daylight Time)]

The seven seconds corresponds to the async delay but why is it showing up at all as the "next" scheduled occurrence? I was expecting that the first element in any call to next would be the next scheduled execution time but it seems I have to get the second array element instead. Is this expected behavior? I think this is a bug because it doesn't match the documented behavior of next.

day() in month()

I'm trying to create a schedule like every Feb 2nd every year

i have tried things like
var sched = later.parse.recur().every(2).day().on(2)month();
var sched = later.parse.recur().on(2).day().on(2)month() ;
etc..etc..

it just does not seem to like day() so I'm very sure I'm doing it wrong..
any idea on how to get it done?

(i worked out using text its later.parse.text('on the 2 day of Feb'); but really trying to get recur working)

thanks
oz

Cron parser first next date is the start date

Hi and thanks a lot for your great module !

I have a strange behavior on this simple expression :

later.date.localTime();
var sched = later.parse.cron('5 2 * * *'),
      start = new Date('2013-10-12 02:05:00'),
      occurrences = later.schedule(sched).next(2, start);
console.log(start.getTime() == occurrences[0].getTime()); // ----> true

The first element in occurrences is the start date itself.

Thanks

cron minutes/hours on ie issues

Hi,

I've a problem on IE

On firefox : later.schedule(later.parse.cron('6 8 * * * *')).next(1) => Date {Tue Dec 03 2013 08:06:00 GMT+0100}
On IE 8,9,10,11 : later.schedule(later.parse.cron('6 8 * * * *')).next(1) => Date {Tue Dec 03 2013 08:00:00 GMT+0100}

What I'm doing wrong ?

Thanks for help :)

using hours with between produces some strange results.

I have the following two schedules, one with hours and one with days using between. It appears that if I do the days, in the examples below between works, but when I do hours and I'm in the current time or the future, I get a 'bad result'

Am I doing something wrong, or is this a bug?

> s = l.parse.text('every 2 hours between 7 and 19') ; l.schedule(s).isValid(new Date())
true
> s = l.parse.text('every 2 hours between 1 and 15') ; l.schedule(s).isValid(new Date())
false
> s = l.parse.text('every 2 days between 7 and 19') ; l.schedule(s).isValid(new Date())
true
> s = l.parse.text('every 2 days between 1 and 15') ; l.schedule(s).isValid(new Date())
false
> s = l.parse.text('every 2 hours between 1 and 15') ; l.schedule(s).isValid(new Date())
false
> s = l.parse.text('every 2 hours between 1 and 17') ; l.schedule(s).isValid(new Date())
true
> s = l.parse.text('every 2 hours between 1 and 18') ; l.schedule(s).isValid(new Date())
true
> s = l.parse.text('every 2 hours between 1 and 16') ; l.schedule(s).isValid(new Date())

enParser

'every 1 hour' successfully parses:

later.enParser().parse('every 1 hour')
{ schedules: [ { h: [Object] } ],
exceptions: [],
error: -1 }

however fails to increment hourly, seems to increment by minute:

later.later(60).get(later.enParser().parse('every 1 hour'), 3, now)
[ Mon May 27 2013 12:41:22 GMT+1000 (EST),
Mon May 27 2013 12:42:22 GMT+1000 (EST),
Mon May 27 2013 12:43:22 GMT+1000 (EST) ]

Either this should fail to parse, or should work?

setInterval execute only the first schedule

Hi, with the following example, logTime is only fired at 2:02am:

later.date.localTime()
var sched = later.parse.text('at 2:02 am also at 10:02 am also at 16:02 pm')
var timer = later.setInterval(logTime, sched)
function logTime() {
  console.log(new Date())
}

(using later.min.js v1.1.6)

Am I missing something?
Is there a better way to achieve the same thing?

Not a single example showing how to actually use it

Trying to work with later it's completely unclear how to use it.

Why not include actual function to be fired on each interval, and show how to use later to fire that function.

i.e.

var funcName = function () { console.log("I'm fired!", +new Date); }
var timer = later.schedule('every 5 seconds').setInterval(funcName)

wrapping months doesn't appear to work correctly

It's now may. If i use this cron:

var s = later.parse.cron('15 10 * nov-feb mon-tue');
later.schedule(s).next(10);

it returns me this

[ Mon Dec 01 2014 02:15:00 GMT-0800 (PST),
Tue Dec 02 2014 02:15:00 GMT-0800 (PST),
Mon Dec 08 2014 02:15:00 GMT-0800 (PST),
Tue Dec 09 2014 02:15:00 GMT-0800 (PST),
Mon Dec 15 2014 02:15:00 GMT-0800 (PST),
Tue Dec 16 2014 02:15:00 GMT-0800 (PST),
Mon Dec 22 2014 02:15:00 GMT-0800 (PST),
Tue Dec 23 2014 02:15:00 GMT-0800 (PST),
Mon Dec 29 2014 02:15:00 GMT-0800 (PST),
Tue Dec 30 2014 02:15:00 GMT-0800 (PST) ]

I would expect it to start in nov and wrap to feb of next year.

next() return the wrong value

I'm using later.js to calculate the next occurrence of a cron, and it returns wrong result.

Here's my code:

var laterCron = later.parse.cron("5 11,15,19,23,3,7 * * *");
console.log(later.schedule(laterCron).next());

The response is

Fri Dec 06 2013 13:05:00 GMT+0200 (EET)

(Now is Thu Dec 05 2013 14:36:38 GMT+0200 (EET)) But the next run should be at 15:05 GMT (or 17:05 GMT+02)

(I use the newest version, 1.1.6)

Test cronjob

Hi,

Is there a way to check a cron format before parse it ?

Thanks for help !

Support node-cron like CronJob support

Currently we are using node-cron for our scheduling needs because of their flexible CronJob class ( https://github.com/ncb000gt/node-cron ) but Later supports way more formats and has a more complete cron parser implementation.

Could support be added for these kind of CronJobs, that would be really useful and would greatly improve the usefulness of Later.

0.0.5 does not run in nodejs

my package.json
....
"dependencies" : {
"later": "0.0.5",
}

in core try to
var cronParser = require("later").cronParser;

cause

Error: Cannot find module './later'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object. (/Users/farin/Sites/cc-console/node_modules/later/app.js:1:79)

later.js is in 'lib' directory

later.schedule({schedules: [{dw: [2]}]}).next(3) returns an array including Monday instead of only Sundays

Hello!

As in the topic.

sched = {schedules: [{dw: [1]}]};
later.schedule(sched3).next(3)

Gives me back expected:

[Date {Sat Jul 27 2013 19:00:00 GMT-0500 (CDT)}, 
Date {Sat Aug 03 2013 19:00:00 GMT-0500 (CDT)}, 
Date {Sat Aug 10 2013 19:00:00 GMT-0500 (CDT)}]

But when I try with

sched3 = {schedules: [{dw: [2]}]}
later.schedule(sched3).next(3)

Gives me back an array that starts with the current date and time:

[Date {Mon Jul 22 2013 13:52:52 GMT-0500 (CDT)}, 
Date {Sun Jul 28 2013 19:00:00 GMT-0500 (CDT)}, 
Date {Sun Aug 04 2013 19:00:00 GMT-0500 (CDT)}]

Is that a bug or a feature?

Next is returning a value a day late

I'm attempting to use a recurrence rule that specifies running a task at 9:30am every day:

let scheduleDefinition = later.parse.recur().on('09:30:00').time();
let schedule = later.schedule(scheduleDefinition);
console.log(schedule.next());

When I run this at 9:26am today, next returns 9:30am tomorrow.

Am I doing something wrong? Is it not taking into account my time zone? It seems if I set this to 1:30pm it gives me the correct value, which is 4 hours later (my timezone is EST). Do I need to schedule using UTC time?

Documentation inconsistency re: successful text parse

Successful text parsing appears to return -1 in the error property.

However, the documentation states:

"Tip If there is an error parsing the text expression, the character position that the error occurred in will be returned in the error property. If the expression was parsed correctly, error will be undefined."

Great Library!

Not really an issue.

This library is GREAT! bunkat should get an Oscar for Javascript!

j.

Every x weeks

Hi,

Is it possible to create something like:

Every 3 weeks on monday

And is it possible to set a start date?

Thanks

and() operand do not merge ranges seamlessly

This is my schedule:

var sched = later.parse.recur()
.every().hour().between(0,8).onWeekday()
.and()
.onWeekend();

later.schedule(sched).nextRange(2, new Date("Sat Sep 28 2013 11:00:00 GMT+0600 (YEKT)"));

and this is result:

[["2013-09-28T05:00:00.000Z","2013-09-30T00:00:00.000Z"],
["2013-09-30T00:00:00.000Z","2013-09-30T09:00:00.000Z"]]

As you can see: first period ends at 2013-09-30T00:00:00.000Z and the second one begins at the same date. Whole rule is valid at that time. First valid moment is 2013-09-28T05:00:00.000Z and first invalid moment is 2013-09-30T09:00:00.000Z. So by definition, nextRange() should return first range as: ["2013-09-28T05:00:00.000Z", "2013-09-30T09:00:00.000Z"].

RRule support

It would be useful to get RRules as input and output for supporting more complex recurring schedules.

prev() behaving strangely?

Input:

later.date.localTime();
var schedule = later.parse.cron("0 0 * * 1-5");
var next = later.schedule(schedule).next();
console.log(next);
var prev = later.schedule(schedule).prev();
console.log(prev);

Output:

Tue Dec 03 2013 00:00:00 GMT-0800 (Pacific Standard Time)
{ Mon, 02 Dec 2013 08:00:00 GMT dw: 2, h: 0, m: 0, s: 0 }

Why is the format of the two logs different? And why aren't they at the same time? Am I just using prev() incorrectly?

This is later 1.1.6 under node 0.10.22.

1st working day of the month

How can i enumerate the first working day of the month.
For ex.
3rd feb 2014 (1st day of the month falls on a weekend so it would return 3rd)

when i try
later.parse.recur().every(1).month().first().dayOfMonth().onWeekday();
it eats up March, June etc. whichever month has the 1st day occurring on a weekend.

thanks.

after() doesn't work properly

Test 1

Minutes are correctly recurring every 5 minutes. Seconds should remain at 34 but it is being incremented (35, 36,...) when it shouldn't.
Test code:

var now = new Date();
var rSched = recur().after(5).minute();
var results = later(0).get(rSched, 5, now);

Output

now = Date(Fri Mar 15 2013 09:39:34 GMT-0500 (Central Daylight Time))
results = array(5) {
    [0] => Date(Fri Mar 15 2013 09:44:34 GMT-0500 (Central Daylight Time))
    [1] => Date(Fri Mar 15 2013 09:49:35 GMT-0500 (Central Daylight Time))
    [2] => Date(Fri Mar 15 2013 09:54:36 GMT-0500 (Central Daylight Time))
    [3] => Date(Fri Mar 15 2013 09:59:37 GMT-0500 (Central Daylight Time))
    [4] => Date(Fri Mar 15 2013 10:04:38 GMT-0500 (Central Daylight Time))
}

Test 2

Minutes recur the fist time correctly. Thereafter, it recur's every 6 minutes instead of 5 minutes. Seconds remained at 34 correctly.
Test code:

var now = new Date();
var rSched = recur().after(5).minute();
var results = later(60).get(rSched, 5, now);

Output

now = Date(Fri Mar 15 2013 09:45:34 GMT-0500 (Central Daylight Time))
array(5) {
    [0] => Date(Fri Mar 15 2013 09:50:34 GMT-0500 (Central Daylight Time))
    [1] => Date(Fri Mar 15 2013 09:56:34 GMT-0500 (Central Daylight Time))
    [2] => Date(Fri Mar 15 2013 10:02:34 GMT-0500 (Central Daylight Time))
    [3] => Date(Fri Mar 15 2013 10:08:34 GMT-0500 (Central Daylight Time))
    [4] => Date(Fri Mar 15 2013 10:14:34 GMT-0500 (Central Daylight Time))
}

cron issue: won't parse 0 4/10 * * * ?

I am having an issue where the script will not parse this sort of syntax.

works: 0 0/10 * * * ?
doesn't work: 0 4/10 * * * ?

I am using this as a frontend web app controller for a scheduler using quartz.net scheduler. I need to decode the crontab syntax so I can display the next occurrences on a calender. The non-working syntax works fine in the scheduler but not with 'later'.

code used:

var cronSch = cronParser().parse(dataJobs[i].time, true); // dataJobs[i].time = the cron string
var results = later(60, true).get(cronSch, 5, calDate);

for the non working example, results[0] == undefined.

Example of how to handle dynamic schedules based on user input..

I am writing an app that runs on the raspberry pi and controls a sprinkler system via a shift register..

One of the requirements of this application is runtime. which is the length of time a sprinkler zone should run for.

currently all my scheduling is done via mongodb and a setTimeout which pulls any task which is status: inactive and startDate >= now() from db. It does this every 1 minute and also queries for tasks which are supposed to end..

I'd like to use laterjs to abstract this out and make things a bit better and add more features!

I have two questions:

  • will/does laterjs have a method for calculating runtimes? Such as, run this "job" for 15 minutes every 12 hours.
  • Your site mentions usage of databases with laterjs .. could you provide some sample code for this? How could i add schedules via a web interface which a user can select the scheduling and then laterjs receives this schedule.

FYI
my repository is at http://github.com/RelativeMedia/nodesprinkler

Calculate previous occurrences?

Hi, I'm developing a project where would be useful to know the last occurence before actualtime. Something like

getPrevious(recur, [endDate])

is ther a way to do it? or if not, is there plans to implement in future versions?

The unique way possible I know is to get all occurrences from (year one) to actual date and extract last from response :(

thanks in advance and congrats for your very good work.

Alberto.

next(1) should have increased resolution or be aware that the sched has fired

I'm currently running into a problem where I'm calling next(1) after I fire off a method from setInterval because I want to log when the next update will occur. However, because things happen so quickly in my update routine, next reports what is really the current scheduled time. This appears to be because the resolution is is at a higher level that the amount of time passed. But in any case, I think that the schedule should be aware that a scheduled time was triggered by setInterval and immediately start reporting the true next schedule time, rather than relying on enough passing.

LICENSE?

add license field to package.json

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.