Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 47 additions & 21 deletions later.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,13 +923,13 @@ later = function() {
OCT: 10,
NOV: 11,
DEC: 12,
SUN: 1,
MON: 2,
TUE: 3,
WED: 4,
THU: 5,
FRI: 6,
SAT: 7
SUN: 0,
MON: 1,
TUE: 2,
WED: 3,
THU: 4,
FRI: 5,
SAT: 6
};
var REPLACEMENTS = {
"* * * * * *": "0/1 * * * * *",
Expand All @@ -947,10 +947,11 @@ later = function() {
D: [ 3, 1, 31 ],
M: [ 4, 1, 12 ],
Y: [ 6, 1970, 2099 ],
d: [ 5, 1, 7, 1 ]
d: [ 5, 0, 7 ]
};
function getValue(value, offset, max) {
return isNaN(value) ? NAMES[value] || null : Math.min(+value + (offset || 0), max || 9999);
function getValue(value, max) {
var result = isNaN(value) ? NAMES[value] : Math.min(+value, max || 9999);
return result === undefined ? null : result;
}
function cloneSchedule(sched) {
var clone = {}, field;
Expand Down Expand Up @@ -1004,31 +1005,31 @@ later = function() {
s.exceptions.push(except1);
s.exceptions.push(except2);
}
function addRange(item, curSched, name, min, max, offset) {
function addRange(item, curSched, name, min, max) {
var incSplit = item.split("/"), inc = +incSplit[1], range = incSplit[0];
if (range !== "*" && range !== "0") {
var rangeSplit = range.split("-");
min = getValue(rangeSplit[0], offset, max);
max = getValue(rangeSplit[1], offset, max) || max;
min = getValue(rangeSplit[0], max);
max = getValue(rangeSplit[1], max) || max;
}
add(curSched, name, min, max, inc);
}
function parse(item, s, name, min, max, offset) {
function parse(item, s, name, min, max) {
var value, split, schedules = s.schedules, curSched = schedules[schedules.length - 1];
if (item === "L") {
item = min - 1;
}
if ((value = getValue(item, offset, max)) !== null) {
if ((value = getValue(item, max)) !== null) {
add(curSched, name, value, value);
} else if ((value = getValue(item.replace("W", ""), offset, max)) !== null) {
} else if ((value = getValue(item.replace("W", ""), max)) !== null) {
addWeekday(s, curSched, value);
} else if ((value = getValue(item.replace("L", ""), offset, max)) !== null) {
addHash(schedules, curSched, value, min - 1);
} else if ((value = getValue(item.replace("L", ""), max)) !== null) {
addHash(schedules, curSched, value, min);
} else if ((split = item.split("#")).length === 2) {
value = getValue(split[0], offset, max);
value = getValue(split[0], max);
addHash(schedules, curSched, value, getValue(split[1]));
} else {
addRange(item, curSched, name, min, max, offset);
addRange(item, curSched, name, min, max);
}
}
function isHash(item) {
Expand Down Expand Up @@ -1059,8 +1060,33 @@ later = function() {
var prepared = expr.toUpperCase();
return REPLACEMENTS[prepared] || prepared;
}
function postProcessSchedule(sched) {
function process(collection) {
var s, i, length, di, dlength;
length = collection.length;
for (i = 0; i < length; i++) {
s = collection[i];
if (s.d) {
dlength = s.d.length;
for (di = 0; di < dlength; di++) {
s.d[di] += 1;
}
if (s.d[dlength - 1] === 8) {
s.d.pop();
if (s.d[0] !== 1) {
s.d.unshift(1);
}
}
}
}
}
process(sched.schedules);
process(sched.exceptions);
}
var e = prepareExpr(expr);
return parseExpr(hasSeconds ? e : "0 " + e);
var s = parseExpr(hasSeconds ? e : "0 " + e);
postProcessSchedule(s);
return s;
};
later.parse.recur = function() {
var schedules = [], exceptions = [], cur, curArr = schedules, curName, values, every, modifier, applyMin, applyMax, i, last;
Expand Down
Loading