From c415d4586ab3c210b2008bff694c38f46d52e584 Mon Sep 17 00:00:00 2001 From: Gianni Chiappetta Date: Fri, 17 Jul 2015 14:00:09 -0400 Subject: [PATCH] Add a missing test case for the `subtract` method (fixes #86) --- lib/moment-range.js | 3 +++ test/moment-range.js | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/moment-range.js b/lib/moment-range.js index 6f2649b..1fcc34b 100644 --- a/lib/moment-range.js +++ b/lib/moment-range.js @@ -174,6 +174,9 @@ DateRange.prototype.subtract = function(other) { else if ((start < other.start) && (other.start < other.end) && (other.end < end)) { return [new DateRange(start, other.start), new DateRange(other.end, end)]; } + else if ((start < other.start) && (other.start < end) && (other.end < end)) { + return [new DateRange(start, other.start), new DateRange(other.start, end)]; + } }; /** diff --git a/test/moment-range.js b/test/moment-range.js index bae8e1b..9554e47 100644 --- a/test/moment-range.js +++ b/test/moment-range.js @@ -566,7 +566,7 @@ describe('DateRange', function() { var d7 = new Date(Date.UTC(2011, 6, 6)); var d8 = new Date(Date.UTC(2011, 8, 8)); - it('should turn [--{==}--] into (--) (--) where (a=[], b={})', function() { + it('should turn [--{==}--] into (--) (--) where (a=[], b={})', function() { var dr1 = moment.range(d5, d8); var dr2 = moment.range(d6, d7); @@ -628,6 +628,12 @@ describe('DateRange', function() { dr1.subtract(dr2).should.eql([dr1]); }); + + it('should turn [--{==}--] into (--) where (a=[], b={})', function() { + var o = moment.range('2015-04-07T00:00:00+00:00/2015-04-08T00:00:00+00:00'); + var s = moment.range('2015-04-07T17:12:18+00:00/2015-04-07T17:12:18+00:00'); + o.subtract(s).should.eql([moment.range('2015-04-07T00:00:00+00:00/2015-04-07T17:12:18+00:00'), moment.range('2015-04-07T17:12:18+00:00/2015-04-08T00:00:00+00:00')]); + }); }); describe('#isSame()', function() {