cron
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -1,8 +0,6 @@ | ||
var timeModuleFound = false; | ||
var CronDate = Date; | ||
try { | ||
var time = require("time"); | ||
Date = time.Date; | ||
timeModuleFound = true; | ||
CronDate = require("time").Date; | ||
} catch(e) { | ||
//no time module...leave Date alone. :) | ||
//no time module...leave CronDate alone. :) | ||
} | ||
@@ -22,4 +20,4 @@ | ||
if (this.source instanceof Date) { | ||
this.source = new Date(this.source); | ||
if ((this.source instanceof Date) || (this.source instanceof CronDate)) { | ||
this.source = new CronDate(this.source); | ||
this.realDate = true; | ||
@@ -44,3 +42,3 @@ } else { | ||
sendAt: function() { | ||
var date = (this.source instanceof Date) ? this.source : new Date(); | ||
var date = (this.source instanceof CronDate) ? this.source : new CronDate(); | ||
if (this.zone && date.setTimezone) | ||
@@ -62,3 +60,3 @@ date.setTimezone(this.zone); | ||
getTimeout: function() { | ||
return Math.max(-1, this.sendAt().getTime() - Date.now()); | ||
return Math.max(-1, this.sendAt().getTime() - CronDate.now()); | ||
}, | ||
@@ -91,3 +89,3 @@ | ||
_getNextDateFrom: function(start) { | ||
var date = new Date(start); | ||
var date = new CronDate(start); | ||
if (this.zone && date.setTimezone) | ||
@@ -244,5 +242,6 @@ date.setTimezone(start.getTimezone()); | ||
timeZone = cronTime.timeZone; | ||
if (timeZone && !(Date.setTimezone)) console.log('You specified a Timezone but have not included the `time` module. Timezone functionality is disabled. Please install the `time` module to use Timezones in your application.'); | ||
} | ||
if (timeZone && !(CronDate.prototype.setTimezone)) console.log('You specified a Timezone but have not included the `time` module. Timezone functionality is disabled. Please install the `time` module to use Timezones in your application.'); | ||
this._callbacks = []; | ||
@@ -249,0 +248,0 @@ this.onComplete = onComplete; |
{ | ||
"name": "cron", | ||
"description": "CronJob's for your node", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"author": "Nick Campbell <nicholas.j.campbell@gmail.com> (http://github.com/ncb000gt)", | ||
@@ -6,0 +6,0 @@ "bugs" : { |
@@ -214,8 +214,7 @@ var testCase = require('nodeunit').testCase, | ||
// New Orleans time | ||
var d = new time.Date(); | ||
d.setTimezone(zone); | ||
var t = new time.Date(); | ||
t.setTimezone(zone); | ||
// Current time | ||
t = new time.Date(); | ||
t.setTimezone("America/New_York"); | ||
d = new Date(); | ||
@@ -225,9 +224,15 @@ // If current time is New Orleans time, switch to Los Angeles.. | ||
zone = "America/Los_Angeles"; | ||
d.setTimezone(zone); | ||
t.setTimezone(zone); | ||
} | ||
assert.notEqual(d.getHours(), t.getHours()); | ||
assert.notEqual(d.getTimezone(), t.getTimezone()); | ||
assert.ok(!(Date instanceof time.Date)); | ||
var seconds = d.getSeconds() + 1; | ||
var c = new cron.CronJob(seconds + ' ' + d.getMinutes() + ' ' + d.getHours() + ' * * *', function(){ | ||
// If t = 59s12m then t.setSeconds(60) | ||
// becones 00s13m so we're fine just doing | ||
// this and no testRun callback. | ||
t.setSeconds(t.getSeconds()+1); | ||
// Run a job designed to be executed at a given | ||
// time in `zone`, making sure that it is a different | ||
// hour than local time. | ||
var c = new cron.CronJob(t.getSeconds() + ' ' + t.getMinutes() + ' ' + t.getHours() + ' * * *', function(){ | ||
assert.ok(true); | ||
@@ -242,3 +247,3 @@ }, undefined, true, zone); | ||
'test a job with a date and a given time zone': function (assert) { | ||
assert.expect(2); | ||
assert.expect(3); | ||
@@ -249,8 +254,7 @@ var time = require("time"); | ||
// New Orleans time | ||
var d = new time.Date(); | ||
d.setTimezone(zone); | ||
var t = new time.Date(); | ||
t.setTimezone(zone); | ||
// Current time | ||
t = new time.Date(); | ||
t.setTimezone("America/New_York"); | ||
d = new Date(); | ||
@@ -260,5 +264,6 @@ // If current time is New Orleans time, switch to Los Angeles.. | ||
zone = "America/Los_Angeles"; | ||
d.setTimezone(zone); | ||
t.setTimezone(zone); | ||
} | ||
assert.notEqual(d.getHours(), t.getHours()); | ||
assert.ok(!(Date instanceof time.Date)); | ||
@@ -265,0 +270,0 @@ if ((58 - t.getSeconds()) <= 0) { |
Sorry, the diff of this file is not supported yet
26591
677