From 80e4b3fe941ab43c3e4f04bdaf799f063972f53f Mon Sep 17 00:00:00 2001 From: bramski Date: Tue, 3 Feb 2015 14:14:10 -0800 Subject: [PATCH] Fixes a case where calendar recurrences don't work with moment-tz. --- moment-recur.js | 6 +++++- tests/spec/jasmine-event-recur.js | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/moment-recur.js b/moment-recur.js index 62e3393..e873aad 100644 --- a/moment-recur.js +++ b/moment-recur.js @@ -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); + } }; diff --git a/tests/spec/jasmine-event-recur.js b/tests/spec/jasmine-event-recur.js index 1a32ab7..58d325a 100755 --- a/tests/spec/jasmine-event-recur.js +++ b/tests/spec/jasmine-event-recur.js @@ -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() {