From 14515f571f7a5f6f63368178066ea0bb23a24db2 Mon Sep 17 00:00:00 2001 From: Ilan Biala Date: Wed, 4 Feb 2015 23:02:12 -0500 Subject: [PATCH 1/9] Update recur.js Start laying out code to cancel and exception --- src/parse/recur.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/parse/recur.js b/src/parse/recur.js index 0c1b01d..065efe6 100644 --- a/src/parse/recur.js +++ b/src/parse/recur.js @@ -502,12 +502,16 @@ later.parse.recur = function () { * recur().at('08:00:00').on(2).dayOfWeek().except() * .dayOfWeekCount(1); * + * @param {String} tag: An optional tag used to cancel an exception * @api public */ - except: function () { + except: function (tag) { + if (tag) { + // TODO add to some object to store the tag and related array + } curArr = exceptions; cur = null; return this; } }; -}; \ No newline at end of file +}; From bfc05a5f11e5bdf41d800145c7fa3092f456aa33 Mon Sep 17 00:00:00 2001 From: Ilan Biala Date: Thu, 5 Feb 2015 23:26:38 -0500 Subject: [PATCH 2/9] Update recur.js Add variables to track when an exception is being created. --- src/parse/recur.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/parse/recur.js b/src/parse/recur.js index 065efe6..c4ad1a0 100644 --- a/src/parse/recur.js +++ b/src/parse/recur.js @@ -14,6 +14,8 @@ later.parse.recur = function () { var schedules = [], exceptions = [], + exceptionTags = {}, + settingException = false, cur, curArr = schedules, curName, @@ -507,7 +509,8 @@ later.parse.recur = function () { */ except: function (tag) { if (tag) { - // TODO add to some object to store the tag and related array + settingException = true; + exceptionTags[tag] = tag; } curArr = exceptions; cur = null; From 8ba1027e6a7bd2466939c2910107eeb904a28f70 Mon Sep 17 00:00:00 2001 From: Ilan Biala Date: Tue, 10 Feb 2015 13:00:45 -0500 Subject: [PATCH 3/9] Update recur.js Add in exception tagging functionality --- src/parse/recur.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/parse/recur.js b/src/parse/recur.js index c4ad1a0..3f5cb56 100644 --- a/src/parse/recur.js +++ b/src/parse/recur.js @@ -14,7 +14,7 @@ later.parse.recur = function () { var schedules = [], exceptions = [], - exceptionTags = {}, + newException = {}, settingException = false, cur, curArr = schedules, @@ -31,10 +31,12 @@ later.parse.recur = function () { function add(name, min, max) { name = modifier ? name + '_' + modifier : name; - if (!cur) { + if (settingException && !cur) { + currArr.push(newException); + } else if (!cur) { curArr.push({}); - cur = curArr[0]; } + cur = curArr[0]; if (!cur[name]) { cur[name] = []; @@ -489,6 +491,8 @@ later.parse.recur = function () { * @api public */ and: function () { + newException = {}; + settingException = false; cur = curArr[curArr.push({}) - 1]; return this; }, @@ -509,9 +513,9 @@ later.parse.recur = function () { */ except: function (tag) { if (tag) { - settingException = true; - exceptionTags[tag] = tag; + newException[tag] = tag; } + settingException = true; curArr = exceptions; cur = null; return this; From e91e6b4365578f97496a05380f1f6fb33a359e19 Mon Sep 17 00:00:00 2001 From: Ilan Biala Date: Tue, 10 Feb 2015 13:08:10 -0500 Subject: [PATCH 4/9] Update recur-test.js Add basic tests for exceptions --- test/parse/recur-test.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/parse/recur-test.js b/test/parse/recur-test.js index 3c8c258..ccb4219 100644 --- a/test/parse/recur-test.js +++ b/test/parse/recur-test.js @@ -218,7 +218,21 @@ describe('Parse Recur', function() { r.exceptions[0].m.should.eql([5]); r.exceptions[1].M.should.eql([0]); }); + + it('should tag exception schedules', function() { + var r = recur().except('Sunday').on(0).dayOfWeek(); + r.exceptions[0].should.eql({d: [0]}); + r.exceptions[0].tag.should.eql('Sunday'); + }); + + it('should tag both exception schedules when using .and()', function() { + var r = recur().except('Start time').on(5).minute().and('Skip month').on(0).month(); + r.exceptions[0].m.should.eql([5]); + r.exceptions[1].M.should.eql([0]); + r.exceptions[0].tag.should.eql('Start time'); + r.exceptions[1].tag.should.eql('Skip month'); + }); }); -}); \ No newline at end of file +}); From ff6a608855e4a379e04ddec4a00498ed4e974677 Mon Sep 17 00:00:00 2001 From: Ilan Biala Date: Tue, 10 Feb 2015 13:09:53 -0500 Subject: [PATCH 5/9] Update recur.js Add some functionality to .and() to accept an exception tag for a composite schedule --- src/parse/recur.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/parse/recur.js b/src/parse/recur.js index 3f5cb56..549c1ca 100644 --- a/src/parse/recur.js +++ b/src/parse/recur.js @@ -490,10 +490,21 @@ later.parse.recur = function () { * * @api public */ - and: function () { + and: function (exceptionTag) { + if (settingException) { + if (exceptionTag) { + + } else { + + } + cur = curArr[curArr.push({}) - 1]; + } else { + cur = curArr[curArr.push({}) - 1]; + } + newException = {}; settingException = false; - cur = curArr[curArr.push({}) - 1]; + return this; }, From 6d33adf65e385897c21d1058bb71d584b197d06e Mon Sep 17 00:00:00 2001 From: Ilan Biala Date: Tue, 10 Feb 2015 21:48:48 -0500 Subject: [PATCH 6/9] Update recur.js Add tagging functionality into .and() to enable tagging subsequent exceptions in a composite exception schedule. --- src/parse/recur.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/parse/recur.js b/src/parse/recur.js index 549c1ca..d7399e4 100644 --- a/src/parse/recur.js +++ b/src/parse/recur.js @@ -488,23 +488,20 @@ later.parse.recur = function () { * recur().every(5).minutes().on(1).dayOfWeek().and().every(10) * .minutes().on(2).dayOfWeek(); * + * @param {String} exceptionTag: An optional tag used to cancel an exception in a composite exception schedule * @api public */ and: function (exceptionTag) { - if (settingException) { - if (exceptionTag) { - - } else { - - } - cur = curArr[curArr.push({}) - 1]; + if (exceptionTag && settingException) { + cur = curArr[curArr.push({tag: tag}) - 1]; } else { cur = curArr[curArr.push({}) - 1]; } - newException = {}; - settingException = false; - + if (currArr !== exceptions) { + newException = {}; + settingException = false; + } return this; }, From 1551a2c8576c7c2bf3e3d17eaa060150f828c638 Mon Sep 17 00:00:00 2001 From: Ilan Biala Date: Tue, 10 Feb 2015 21:55:24 -0500 Subject: [PATCH 7/9] Update recur.js Add remove exception functionality --- src/parse/recur.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/parse/recur.js b/src/parse/recur.js index d7399e4..f626c36 100644 --- a/src/parse/recur.js +++ b/src/parse/recur.js @@ -528,5 +528,28 @@ later.parse.recur = function () { cur = null; return this; } + + /** + * Removes exceptions from a schedule. The given tag will be checked + * against the exceptions' tags in the array and will be removed + * based on a matching String tag. To remove an + * exception: + * + * var schedule = recur().at('08:00:00').on(2).dayOfWeek().except('Monday') + * .dayOfWeekCount(1); + * schedule.removeException('Monday'); + * + * @param {String} tag: An optional tag used to cancel an exception + * @api public + */ + removeException: function (tag) { + for (var i = 0; i < exceptions.length; i++) { + if (exceptions[i].tag === tag) { + exceptions.splice(i, 1); + break; + } + } + return this; + } }; }; From c9e0ce711830772428cd0b4c602c4cb0fe850926 Mon Sep 17 00:00:00 2001 From: Ilan Biala Date: Tue, 10 Feb 2015 21:57:37 -0500 Subject: [PATCH 8/9] Update recur-test.js Add tests for removing exceptions --- test/parse/recur-test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/parse/recur-test.js b/test/parse/recur-test.js index ccb4219..e0d6d76 100644 --- a/test/parse/recur-test.js +++ b/test/parse/recur-test.js @@ -232,6 +232,26 @@ describe('Parse Recur', function() { r.exceptions[0].tag.should.eql('Start time'); r.exceptions[1].tag.should.eql('Skip month'); }); + + it('should remove an exception from the exception schedule', function() { + var r = recur().except('Sunday').on(0).dayOfWeek(); + r.exceptions[0].should.eql({d: [0]}); + r.exceptions[0].tag.should.eql('Sunday'); + r.removeException('Monday'); + r.exceptions.should.eql([]); + }); + + it('should remove an exception from a composite exception schedule', function() { + var r = recur().except('Start time').on(5).minute().and('Skip month').on(0).month(); + r.exceptions[0].m.should.eql([5]); + r.exceptions[1].M.should.eql([0]); + r.exceptions[0].tag.should.eql('Start time'); + r.exceptions[1].tag.should.eql('Skip month'); + r.removeException('Start time'); + r.exceptions[0].tag.should.eql('Skip month'); + r.removeException('Skip month'); + r.exceptions.should.eql([]); + }); }); From 233c8f412c07e7e1b29be96f666ce05536b6459e Mon Sep 17 00:00:00 2001 From: Ilan Biala Date: Tue, 10 Feb 2015 22:33:24 -0500 Subject: [PATCH 9/9] Tests passing and all exception removal functionality working --- later.js | 35 ++++++++++++++++++++++++++++++----- src/parse/recur.js | 15 +++++++-------- test/parse/recur-test.js | 20 ++++++++------------ 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/later.js b/later.js index 2cdbb58..20fb4f8 100644 --- a/later.js +++ b/later.js @@ -1023,10 +1023,12 @@ later = function() { return parseExpr(hasSeconds ? e : "0 " + e); }; later.parse.recur = function() { - var schedules = [], exceptions = [], cur, curArr = schedules, curName, values, every, modifier, applyMin, applyMax, i, last; + var schedules = [], exceptions = [], newException = {}, settingException = false, cur, curArr = schedules, curName, values, every, modifier, applyMin, applyMax, i, last; function add(name, min, max) { name = modifier ? name + "_" + modifier : name; - if (!cur) { + if (settingException && !cur) { + cur = curArr[curArr.push(newException) - 1]; + } else if (!cur) { curArr.push({}); cur = curArr[0]; } @@ -1175,14 +1177,37 @@ later = function() { add(last.n, start, end); return this; }, - and: function() { - cur = curArr[curArr.push({}) - 1]; + and: function(exceptionTag) { + if (exceptionTag && settingException) { + cur = curArr[curArr.push({ + tag: exceptionTag + }) - 1]; + } else { + cur = curArr[curArr.push({}) - 1]; + } + if (curArr !== exceptions) { + newException = {}; + settingException = false; + } return this; }, - except: function() { + except: function(tag) { + if (tag) { + newException.tag = tag; + } + settingException = true; curArr = exceptions; cur = null; return this; + }, + removeException: function(tag) { + for (var i = 0; i < exceptions.length; i++) { + if (exceptions[i].tag === tag) { + exceptions.splice(i, 1); + break; + } + } + return this; } }; }; diff --git a/src/parse/recur.js b/src/parse/recur.js index f626c36..fe5fa2c 100644 --- a/src/parse/recur.js +++ b/src/parse/recur.js @@ -32,11 +32,11 @@ later.parse.recur = function () { name = modifier ? name + '_' + modifier : name; if (settingException && !cur) { - currArr.push(newException); + cur = curArr[curArr.push(newException) - 1]; } else if (!cur) { curArr.push({}); + cur = curArr[0]; } - cur = curArr[0]; if (!cur[name]) { cur[name] = []; @@ -493,12 +493,11 @@ later.parse.recur = function () { */ and: function (exceptionTag) { if (exceptionTag && settingException) { - cur = curArr[curArr.push({tag: tag}) - 1]; + cur = curArr[curArr.push({tag: exceptionTag}) - 1]; } else { cur = curArr[curArr.push({}) - 1]; } - - if (currArr !== exceptions) { + if (curArr !== exceptions) { newException = {}; settingException = false; } @@ -521,14 +520,14 @@ later.parse.recur = function () { */ except: function (tag) { if (tag) { - newException[tag] = tag; + newException.tag = tag; } settingException = true; curArr = exceptions; cur = null; return this; - } - + }, + /** * Removes exceptions from a schedule. The given tag will be checked * against the exceptions' tags in the array and will be removed diff --git a/test/parse/recur-test.js b/test/parse/recur-test.js index e0d6d76..cef209d 100644 --- a/test/parse/recur-test.js +++ b/test/parse/recur-test.js @@ -218,33 +218,29 @@ describe('Parse Recur', function() { r.exceptions[0].m.should.eql([5]); r.exceptions[1].M.should.eql([0]); }); - + it('should tag exception schedules', function() { var r = recur().except('Sunday').on(0).dayOfWeek(); - r.exceptions[0].should.eql({d: [0]}); + r.exceptions[0].should.eql({tag: 'Sunday', d: [0]}); r.exceptions[0].tag.should.eql('Sunday'); }); - + it('should tag both exception schedules when using .and()', function() { var r = recur().except('Start time').on(5).minute().and('Skip month').on(0).month(); - r.exceptions[0].m.should.eql([5]); - r.exceptions[1].M.should.eql([0]); + r.exceptions[0].should.eql({tag: 'Start time', m: [5]}); + r.exceptions[1].should.eql({tag: 'Skip month', M: [0]}); r.exceptions[0].tag.should.eql('Start time'); r.exceptions[1].tag.should.eql('Skip month'); }); - + it('should remove an exception from the exception schedule', function() { var r = recur().except('Sunday').on(0).dayOfWeek(); - r.exceptions[0].should.eql({d: [0]}); - r.exceptions[0].tag.should.eql('Sunday'); - r.removeException('Monday'); + r.removeException('Sunday'); r.exceptions.should.eql([]); }); - + it('should remove an exception from a composite exception schedule', function() { var r = recur().except('Start time').on(5).minute().and('Skip month').on(0).month(); - r.exceptions[0].m.should.eql([5]); - r.exceptions[1].M.should.eql([0]); r.exceptions[0].tag.should.eql('Start time'); r.exceptions[1].tag.should.eql('Skip month'); r.removeException('Start time');