Skip to content

Commit

Permalink
Pass optional rounded argument in diff (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
gf3 committed Dec 8, 2016
1 parent 3a5d06c commit 0fb4039
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/moment-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ export class DateRange {
return (startInRange && endInRange);
}

diff(unit?: Shorthand): number {
return this.end.diff(this.start, unit);
diff(unit: ?Shorthand = undefined, rounded: bool = undefined): number {
return this.end.diff(this.start, unit, rounded);
}

intersect(other: DateRange): ?DateRange {
Expand Down
8 changes: 8 additions & 0 deletions lib/moment-range_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,14 @@ describe('DateRange', function() {
expect(dr.diff('days')).to.equal(92);
expect(dr.diff()).to.equal(7948800000);
});

it('should optionally pass the rounded argument', function() {
const d1 = new Date(Date.UTC(2011, 4, 1));
const d2 = new Date(Date.UTC(2011, 4, 5, 12));
const dr = moment.range(d1, d2);

expect(dr.diff('days', true)).to.equal(4.5);
});
});

describe('#center()', function() {
Expand Down

0 comments on commit 0fb4039

Please sign in to comment.