Skip to content

Commit

Permalink
consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Condon committed Sep 23, 2011
1 parent a0fff9b commit 3a33296
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions lib/cron.js
Expand Up @@ -51,32 +51,36 @@ CronTime.prototype = {


//sanity check
while(--i)
{
while(--i) {

if (!(date.getMonth() in this.month)) {
date.setMonth(date.getMonth()+1);
date.setDate(1);
date.setHours(0);
date.setMinutes(0);
continue;
}

if (!(date.getDate() in this.dayOfMonth)) {
date.setDate(date.getDate()+1);
date.setHours(0);
date.setMinutes(0);
continue;
}

if (!(date.getDay()+1 in this.dayOfWeek)) {
date.setDate(date.getDate()+1);
date.setHours(0);
date.setMinutes(0);
continue;
}

if (!(date.getHours() in this.hour)) {
date.setHours(date.getHours()+1);
date.setMinutes(0);
continue;
}

if (!(date.getMinutes() in this.minute)) {
date.setMinutes(date.getMinutes()+1);
date.setSeconds(0);
Expand All @@ -101,17 +105,17 @@ CronTime.prototype = {
*/


timeout: function()
{
timeout: function() {

return Math.max(0, this.sendAt().getTime() - Date.now());
},

/**
* writes out a cron string
*/

toString: function()
{
toString: function() {

return [ this._wcOrAll('second'),
this._wcOrAll('minute'),
this._wcOrAll('hour'),
Expand All @@ -123,17 +127,17 @@ CronTime.prototype = {
/**
*/

toJSON: function()
{
toJSON: function() {

return this.toString();
},

/**
* wildcard, or all params in array (for to string)
*/

'_wcOrAll': function(type)
{
_wcOrAll: function(type) {

if(this._hasAll(type)) return '*';

var all = [];
Expand All @@ -148,8 +152,8 @@ CronTime.prototype = {
/**
*/

'_hasAll': function(type)
{
_hasAll: function(type) {

var constrain = CronTime.constraints[CronTime.map.indexOf(type)];

for(var i = constrain[0], n = constrain[1]; i < n; i++)
Expand Down Expand Up @@ -307,23 +311,23 @@ CronJob.prototype = {
};


exports.job = function(cronTime, onComplete)
{
exports.job = function(cronTime, onComplete) {

return new CronJob(cronTime, onComplete);
}

exports.time = function(cronTime)
{
exports.time = function(cronTime) {

return new CronTime(cronTime);
}

exports.sendAt = function(cronTime)
{
exports.sendAt = function(cronTime) {

return exports.time(cronTime).sendAt();
}

exports.timeout = function(cronTime)
{
exports.timeout = function(cronTime) {

return exports.time(cronTime).timeout();
}

Expand Down

0 comments on commit 3a33296

Please sign in to comment.