Skip to content

Commit

Permalink
Fixes a case where calendar recurrences don't work with moment-tz.
Browse files Browse the repository at this point in the history
  • Loading branch information
bramski committed Feb 3, 2015
1 parent 5baa9cf commit 80e4b3f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
6 changes: 5 additions & 1 deletion moment-recur.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,11 @@

// Plugin for removing all time information from a given date
moment.fn.dateOnly = function() {
return this.hours(0).minutes(0).seconds(0).milliseconds(0).add('minute',this.utcOffset()).utcOffset(0);
if (this.tz && typeof(moment.tz) == 'function' ) {
return moment.tz(this.format('YYYY/MM/DD'), 'UTC');
} else {
return this.hours(0).minutes(0).seconds(0).milliseconds(0).add('minute',this.utcOffset()).utcOffset(0);
}
};


Expand Down
19 changes: 14 additions & 5 deletions tests/spec/jasmine-event-recur.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,20 @@ describe("An interval", function() {
});

describe("The Calendar Interval", function() {
it("daysOfWeek should work", function() {
var recurrence = moment.recur().every(["Sunday", 1]).daysOfWeek();
expect(recurrence.matches( moment().day("Sunday") )).toBe(true);
expect(recurrence.matches( moment().day(1) )).toBe(true);
expect(recurrence.matches( moment().day(3) )).toBe(false);

describe("daysOfWeek", function() {
it("should work", function () {
var recurrence = moment.recur().every(["Sunday", 1]).daysOfWeek();
expect(recurrence.matches(moment().day("Sunday"))).toBe(true);
expect(recurrence.matches(moment().day(1))).toBe(true);
expect(recurrence.matches(moment().day(3))).toBe(false);
});

it("should work with timezones", function () {
var recurrence = moment.tz('2015-01-25',"America/Vancouver").recur().every(["Sunday", 1]).daysOfWeek();
var check = moment.tz('2015-02-01',"Asia/Hong_Kong");
expect(recurrence.matches(check)).toBe(true);
});
});

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

0 comments on commit 80e4b3f

Please sign in to comment.