Skip to content

Commit

Permalink
added toString for cronTime
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Condon committed Sep 8, 2011
1 parent 8c158dc commit 48d815c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
56 changes: 56 additions & 0 deletions lib/cron.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,61 @@ CronTime.prototype = {
return Math.max(0, this.sendAt().getTime() - Date.now());
},

/**
* writes out a cron string
*/

toString: function()
{
return [ this._wcOrAll('second'),
this._wcOrAll('minute'),
this._wcOrAll('hour'),
this._wcOrAll('dayOfMonth'),
this._wcOrAll('month'),
this._wcOrAll('dayOfWeek') ].join(' ');
},

/**
*/

toJSON: function()
{
return this.toString();
},

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

'_wcOrAll': function(type)
{
if(this._hasAll(type)) return '*';

var all = [];
for(var time in this[type])
{
all.push(time);
}

return all.join(',');
},

/**
*/

'_hasAll': function(type)
{
var constrain = CronTime.constraints[CronTime.map.indexOf(type)];

for(var i = constrain[0], n = constrain[1]; i < n; i++)
{
if(!(i in this[type])) return false;
}

return true;

},


/**
*/
Expand Down Expand Up @@ -267,6 +322,7 @@ exports.timeout = function(cronTime)
return new CronTime(cronTime).timeout();
}


exports.CronJob = CronJob;
exports.CronTime = CronTime;

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cron2",
"description": "CronJob's for your node",
"version": "0.1.5",
"version": "0.1.6",
"author": "James Padolsey (http://github.com/jamespadolsey)",
"bugs" : {
"web" : "http://github.com/ncb000gt/node-cron/issues"
Expand Down

0 comments on commit 48d815c

Please sign in to comment.