diff --git a/cron/jquery-cron.js b/cron/jquery-cron.js index 0d35756..3a69516 100644 --- a/cron/jquery-cron.js +++ b/cron/jquery-cron.js @@ -5,9 +5,9 @@ * Copyright (c) 2010-2013 Shawn Chin. * Dual licensed under the MIT or GPL Version 2 licenses. * - * Modified By Felix Ruponen to use Quartz Cron Format + * Modified By Scott Thornton * - * GitHub: https://github.com/felixruponen/jquery-cron + * GitHub: https://github.com/sthornton/jquery-cron * * More at: http://www.quartz-scheduler.org * @@ -51,7 +51,7 @@ (function($) { var defaults = { - initial : "0 0/1 * * * ?", + initial : "0 0 1 ? * 1", minuteOpts : { minWidth : 100, // only applies if columns and itemWidth not set itemWidth : 30, @@ -142,6 +142,7 @@ str_opt_month += "\n"; } + // options for day of week var str_opt_dow = ""; var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", @@ -152,30 +153,34 @@ // options for period var str_opt_period = ""; - var periods = ["minute", "hour", "day", "week", "month", "year"]; + var periods = ["minute", "hour", "day", "week", "month", "quarter", "semi-annual", "year"]; for (var i = 0; i < periods.length; i++) { str_opt_period += "\n"; } // display matrix var toDisplay = { - "minute" : [], - "hour" : ["mins"], - "day" : ["time"], - "week" : ["dow", "time"], - "month" : ["dom", "time"], - "year" : ["dom", "month", "time"] + "minute" : [], + "hour" : ["mins"], + "day" : ["time"], + "week" : ["dow", "time"], + "month" : ["dom", "time"], + "quarter" : ["dom", "time"], + "semi-annual" : ["dom","time"], + "year" : ["dom", "month", "time"] }; var combinations = { // Quartz Regex Expressions below // "-" indicates digit of one or two numbers that should be replaced with the desired time - "minute" : /^0\s(0\/1)\s(\*\s){3}\?$/, // "0 0/1 * * * ?" - "hour" : /^0\s\d{1,2}\s(0\/1)\s(\*\s){2}\?$/, // "0 - 0/1 * * ?" - "day" : /^0\s(\d{1,2}\s){2}(\*\s){2}\?$/, // "0 - - * * ?" - "week" : /^0\s(\d{1,2}\s){2}\?\s(\*\s)\d{1,2}$/, // "0 - - ? * -" - "month" : /^0\s(\d{1,2}\s){3}\*\s\?$/, // "0 - - - * ?" - "year" : /^0\s(\d{1,2}\s){4}\?\s\*$/ // "0 - - - - ? *" + "minute" : /^0\s(0\/1)\s(\*\s){3}\?$/, // "0 0/1 * * * ?" + "hour" : /^0\s\d{1,2}\s(0\/1)\s(\*\s){2}\?$/, // "0 - 0/1 * * ?" + "day" : /^0\s(\d{1,2}\s){2}(\*\s){2}\?$/, // "0 - - * * ?" + "week" : /^0\s(\d{1,2}\s){2}\?\s(\*\s)\d{1,2}$/, // "0 - - ? * -" + "month" : /^0\s(\d{1,2}\s){3}\*\s\?$/, // "0 - - - * ?" + "quarter" : /^0\s(\d{1,2}\s){3}?\bJAN,APR,JUL,OCT\b\s\?/, // "0 - - - * ?" + "semi-annual" : /^0\s(\d{1,2}\s){3}?\bJAN,JUL\b\s\?/, // "0 - - - * ?" + "year" : /^0\s(\d{1,2}\s){4}\?\s\*$/ // "0 - - - - ? *" }; // ------------------ internal functions --------------- @@ -197,10 +202,19 @@ } // check format of initial cron value - var valid_cron = /^0\s(0\/1|\d{1,2})\s(0\/1|\d{1,2}|\*)\s(\d{1,2}|\*|\?)\s(\d{1,2}|\*)\s(\d{1,2}|\?)(\s\*)?$/ + var valid_cron = /^0\s(0\/1|\d{1,2})\s(0\/1|\d{1,2}|\*)\s(\d{1,2}|\*|\?)\s(\d{1,2}|\*|\bJAN,JUL\b|\bJAN,APR,JUL,OCT)\s(\d{1,2}|\?)(\s\*)?$/ if (typeof cron_str != "string" || !valid_cron.test(cron_str)) { - $.error("cron: invalid initial value"); - return undefined; + if (cron_str.indexOf("JAN,APR") > 0) { + // this is probably valid since this app generated it + } + else if (cron_str.indexOf("JAN,JUL") > 0) { + // this is probably valid semi-anual cron string + } + else { + $.error("cron: invalid initial value"); + return undefined; + } + } // check actual cron values @@ -209,19 +223,19 @@ d = d.splice(1, d.length - 1); // remove first 0 // mm, hh, DD, MM, DOW - var minval = [ 0, 0, 1, 1, 1]; - var maxval = [59, 23, 31, 12, 7]; - for (var i = 0; i < d.length; i++) { - if (d[i] == "*") continue; - if (/^0\/1$/.test(d[i])) continue; - if (d[i] == "?") continue; - - var v = parseInt(d[i]); - if (defined(v) && v <= maxval[i] && v >= minval[i]) continue; - - $.error("cron: invalid value found (col "+(i+1)+") in " + o.initial); - return undefined; - } + //var minval = [ 0, 0, 1, 1, 1]; + //var maxval = [59, 23, 31, 12, 7]; + //for (var i = 0; i < d.length; i++) { + // if (d[i] == "*") continue; + // if (/^0\/1$/.test(d[i])) continue; + // if (d[i] == "?") continue; + + // var v = parseInt(d[i]); + // if (defined(v) && v <= maxval[i] && v >= minval[i]) continue; + + // $.error("cron: invalid value found (col "+(i+1)+") in " + o.initial); + // return undefined; + //} // determine combination for (var t in combinations) { @@ -287,6 +301,20 @@ return ["0", min, hour, day, "*", "?"].join(" "); break; + case "quarter": + min = b["time"].find("select.cron-time-min").val(); + hour = b["time"].find("select.cron-time-hour").val(); + day = b["dom"].find("select").val(); + return ["0", min, hour, day, "JAN,APR,JUL,OCT", "?"].join(" "); + break; + + case "semi-annual": + min = b["time"].find("select.cron-time-min").val(); + hour = b["time"].find("select.cron-time-hour").val(); + day = b["dom"].find("select").val(); + return ["0", min, hour, day, "JAN,JUL", "?"].join(" "); + break; + case "year": min = b["time"].find("select.cron-time-min").val(); hour = b["time"].find("select.cron-time-hour").val(); @@ -315,6 +343,8 @@ minuteOpts : $.extend({}, defaults.minuteOpts, eo, options.minuteOpts), domOpts : $.extend({}, defaults.domOpts, eo, options.domOpts), monthOpts : $.extend({}, defaults.monthOpts, eo, options.monthOpts), + quarterOpts: $.extend({}, defaults.quarterOpts, eo, options.quarterOpts), + semiAnnualOpts: $.extend({}, defaults.semiAnnualOpts, eo, options.semiAnnualOpts), dowOpts : $.extend({}, defaults.dowOpts, eo, options.dowOpts), timeHourOpts : $.extend({}, defaults.timeHourOpts, eo, options.timeHourOpts), timeMinuteOpts : $.extend({}, defaults.timeMinuteOpts, eo, options.timeMinuteOpts) @@ -361,6 +391,24 @@ select = block["month"].find("select").data("root", this); if (o.useGentleSelect) select.gentleSelect(o.monthOpts); + block["quarter"] = $("" + + " of ") + .appendTo(this) + .data("root", this); + + select = block["quarter"].find("select").data("root", this); + if (o.useGentleSelect) select.gentleSelect(o.quarterOpts); + + block["semi-annual"] = $("" + + " of ") + .appendTo(this) + .data("root", this); + + select = block["semi-annual"].find("select").data("root", this); + if (o.useGentleSelect) select.gentleSelect(o.semiAnnualOpts); + block["mins"] = $("" + " at minutes past the hour ") diff --git a/index.html b/index.html index 7180030..51f21ef 100644 --- a/index.html +++ b/index.html @@ -1,4 +1,4 @@ - +
@@ -30,20 +30,20 @@ $(document).ready(function() { $('#example1').cron({ - initial: "42 3 * * 5", + initial: "0 0 1 ? * 1", onChange: function() { $('#example1-val').text($(this).cron("value")); } }); $('#example1b').cron({ - initial: "42 3 * * 5", + initial: "0 0 1 ? * 1", onChange: function() { $('#example1b-val').text($(this).cron("value")); }, useGentleSelect: true }); $('#example2').cron({ - initial: "42 3 * * 5", + initial: "0 0 1 ? * 1", effectOpts: { openEffect: "fade", openSpeed: "slow" @@ -51,7 +51,7 @@ useGentleSelect: true }); $('#example3').cron({ - initial: "*/5 * * * *", + initial: "0 0 1 ? * 1", onChange: function() { $('#example3-val').text($(this).cron("value")); }, @@ -62,7 +62,7 @@ useGentleSelect: true }); $('#example4').cron({ - initial: "42 3 * * 5", + initial: "0 0 1 ? * 1", onChange: function() { $('#example4-val').text($(this).cron("value")); }, @@ -91,9 +91,9 @@Generated cron entry:
- + Or, with useGentleSelect enabled: - +Generated cron entry: