Permalink
Browse files

add CronWTF.entry() for parsing a single cron line

  • Loading branch information...
technoweenie committed Mar 15, 2009
0 parents commit 2475c416eb6757976ed74cc51590ceb469620211
Showing with 1,772 additions and 0 deletions.
  1. +58 −0 javascripts/cronwtf.js
  2. +1 −0 javascripts/diff_match_patch.js
  3. +1,379 −0 javascripts/jsspec.js
  4. +214 −0 stylesheets/jsspec.css
  5. +120 −0 test.html
@@ -0,0 +1,58 @@
+var CronWTF = {
+ entry: function(line) {
+ pieces = line.split(/\s/)
+ e = {
+ minutes: this.parseAttribute(pieces[0], 60),
+ hours: this.parseAttribute(pieces[1], 24),
+ days: this.parseAttribute(pieces[2], 31),
+ months: this.parseAttribute(pieces[3], 12),
+ week_days: this.parseAttribute(pieces[4], 8),
+ command: pieces.slice(5, pieces.length).join(" ")
+ }
+ e.message = this.generateMessage(e);
+ return e;
+ },
+
+ // parses an individual time attribute into an array of numbers.
+ // * - every increment (returns 0)
+ // \d+ - that value
+ // 1,2,3 - those values
+ // 1-3 - range of values
+ // */3 - steps
+ parseAttribute: function(value, upperBound) {
+ if(value == '*') return 0;
+
+ if(value.match(/^\*\/\d+$/)) {
+ step = parseInt(value.match(/^\*\/(\d+)$/)[1])
+ range = []
+ for(i = 0; i < upperBound; i++) {
+ if(i % step == 0) range.push(i)
+ }
+ return range
+ }
+
+ if(value.match(/^\d+\-\d+$/)) {
+ matches = value.match(/^(\d+)\-(\d+)$/)
+ lower = parseInt(matches[1])
+ upper = parseInt(matches[2])
+ range = []
+ for(var i = lower; i <= upper; i++) {
+ range.push(i);
+ }
+ return range
+ }
+
+ return value.split(",")
+ },
+
+ generateMessage: function(entry) {
+ var timeMsg;
+ if(entry.minutes == 0) {
+ timeMsg = 'every minute'
+ } else {
+ //alert(entry.minutes)
+ timeMsg = 'every hour'
+ }
+ return "Runs `" + entry.command + "`" + timeMsg + "."
+ }
+}

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 2475c41

Please sign in to comment.