Skip to content

Commit

Permalink
Fix a problem with intervals when not dealing with days. Add tests to…
Browse files Browse the repository at this point in the history
… verify this�.
  • Loading branch information
bramski committed Feb 4, 2015
1 parent 9802196 commit 987f364
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 4 additions & 1 deletion moment-recur.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
} else {
diff = date.diff(start, type, true);
}
diff = parseInt(diff);
if( type == 'days') {
// if we are dealing with days, we deal with whole days only.
diff = parseInt(diff);
}

// Check to see if any of the units provided match the date
for (var unit in units) {
Expand Down
2 changes: 1 addition & 1 deletion moment-recur.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions tests/spec/jasmine-event-recur.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,31 @@ describe("An interval", function() {
it("can be weekly", function() {
var recurrence = moment(startDate).recur().every(2).weeks();
expect(recurrence.matches( moment(startDate).add(2, "weeks") )).toBe(true);
expect(recurrence.matches( moment(startDate).add(2, "days") )).toBe(false);
expect(recurrence.matches( moment(startDate).add(3, "weeks") )).toBe(false);
});

it("can be monthly", function() {
var recurrence = moment(startDate).recur().every(3).months();
expect(recurrence.matches( moment(startDate).add(3, "months") )).toBe(true);
expect(recurrence.matches( moment(startDate).add(2, "months") )).toBe(false);
expect(recurrence.matches( moment(startDate).add(2, "days"))).toBe(false);
});

it("can be yearly", function() {
var recurrence = moment(startDate).recur().every(2).years();
expect(recurrence.matches( moment(startDate).add(2, "year") )).toBe(true);
expect(recurrence.matches( moment(startDate).add(3, "year") )).toBe(false);
expect(recurrence.matches( moment(startDate).add(2, "days") )).toBe(false);
});

it("can be an array of intervals", function() {
var recurrence = moment(startDate).recur().every([3,5]).days();
expect(recurrence.matches( moment(startDate).add(3, "days"))).toBe(true);
expect(recurrence.matches( moment(startDate).add(5, "days"))).toBe(true);
expect(recurrence.matches( moment(startDate).add(10, "days"))).toBe(true);
expect(recurrence.matches( moment(startDate).add(4, "days"))).toBe(false);
expect(recurrence.matches( moment(startDate).add(8, "days"))).toBe(false);
});
});

Expand All @@ -184,10 +189,15 @@ describe("The Calendar Interval", function() {
});

it("daysOfMonth should work", function() {
var recurrence = moment.recur().every([1, 10]).daysOfMonth();
expect(recurrence.matches( moment().date(1) )).toBe(true);
expect(recurrence.matches( moment().date(10) )).toBe(true);
expect(recurrence.matches( moment().date(15) )).toBe(false);
var recurrence = moment('2015-01-01').recur().every([1, 10]).daysOfMonth();
expect(recurrence.matches( moment('2015-01-01'))).toBe(true);
expect(recurrence.matches( moment('2015-01-02'))).toBe(false);
expect(recurrence.matches( moment('2015-01-10'))).toBe(true);
expect(recurrence.matches( moment('2015-01-15'))).toBe(false);
expect(recurrence.matches( moment('2015-02-01'))).toBe(true);
expect(recurrence.matches( moment('2015-02-02'))).toBe(false);
expect(recurrence.matches( moment('2015-02-10'))).toBe(true);
expect(recurrence.matches( moment('2015-02-15'))).toBe(false);
});

it("weeksOfMonth should work", function() {
Expand Down

0 comments on commit 987f364

Please sign in to comment.