Skip to content

Commit

Permalink
Add timezone test
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanoehlman committed Jan 13, 2014
1 parent 229866d commit 16e9cf1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
7 changes: 3 additions & 4 deletions lib/recurring.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var moment = require('moment');


// takes a JSON object with pattern options
function RecurringDate (pattern, date_format, opts) {
function RecurringDate (pattern, date_format) {
if (typeof pattern != 'object') throw new TypeError('pattern must be a JSON');

if (!pattern.every) {
Expand All @@ -36,7 +36,6 @@ function RecurringDate (pattern, date_format, opts) {
}

this.pattern = pattern;
this.opts = opts || {};

// stores generated dates based on recurrence pattern
this.dates = [];
Expand All @@ -57,8 +56,8 @@ function RecurringDate (pattern, date_format, opts) {
RecurringDate.prototype._getDate = function(value) {
var result = moment(value);
// Handle timezone offsets
if (this.opts.timezone) {
result.zone(this.opts.timezone);
if (this.pattern.timezone) {
result.zone(this.pattern.timezone);
}
return result;
}
Expand Down
40 changes: 39 additions & 1 deletion test/recurrence_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,42 @@ describe('by weeks with', function () {
return done();
});

}); // describe by weeks
}); // describe by weeks

describe('with timezone offset', function() {

it('should be able to generate with a timezone offset', function(done) {
var start = moment('13-01-2014 06:30 AM +10:00', 'DD-MM-YYYY hh:mm a Z'),
params = {
start: start.toDate(),
until: '03/21/2014',
every: '1',
unit: 'w',
end_condition: 'until',
days: [1],
timezone: '-0500'
},
r = new Recurrence(params),
results = r.generate(),
expected = [
1389558600000,
1389645000000,
1390249800000,
1390854600000,
1391459400000,
1392064200000,
1392669000000,
1393273800000,
1393878600000,
1394483400000,
1395088200000
];

for (var i = 0; i < results.length; i++) {
if (results[i] != expected[i]) {
return done('Unexpected time');
}
}
return done();
});
});

0 comments on commit 16e9cf1

Please sign in to comment.