Skip to content

Commit

Permalink
Add a missing test case for the subtract method (fixes #86)
Browse files Browse the repository at this point in the history
  • Loading branch information
gf3 committed Jul 17, 2015
1 parent 805e767 commit c415d45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/moment-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}
};

/**
Expand Down
8 changes: 7 additions & 1 deletion test/moment-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit c415d45

Please sign in to comment.