Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: workaround moment issue with DST transitions #73

Merged
merged 1 commit into from
Oct 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,27 @@ CronDate.prototype.addDay = function() {
};

CronDate.prototype.addHour = function() {
const prev = this.getTime();
this._date.add(1, 'hour').startOf('hour');
if (this.getTime() <= prev) {
this._date.add(1, 'hour');
}
};

CronDate.prototype.addMinute = function() {
const prev = this.getTime();
this._date.add(1, 'minute').startOf('minute');
if (this.getTime() < prev) {
this._date.add(1, 'hour');
}
};

CronDate.prototype.addSecond = function() {
const prev = this.getTime();
this._date.add(1, 'second').startOf('second');
if (this.getTime() < prev) {
this._date.add(1, 'hour');
}
};

CronDate.prototype.getDate = function() {
Expand Down
107 changes: 107 additions & 0 deletions test/timezone.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,113 @@ test('It works on DST end', function(t) {
t.throws(function() {
date = interval.next();
});

options = {
currentDate : new Date('Sun Oct 29 2016 01:00:00 GMT+0200')
}

interval = CronExpression.parse('0 12 * * *', options);
t.ok(interval, 'Interval parsed');

date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 29, '29th');
date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 30, '30th');
date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 31, '31st');

options = {
currentDate : new Date('Sun Oct 29 2016 02:59:00 GMT+0200')
}

interval = CronExpression.parse('0 12 * * *', options);
t.ok(interval, 'Interval parsed');

date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 29, '29th');
date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 30, '30th');
date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 31, '31st');

options = {
currentDate : new Date('Sun Oct 29 2016 02:59:59 GMT+0200')
}

interval = CronExpression.parse('0 12 * * *', options);
t.ok(interval, 'Interval parsed');

date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 29, '29th');
date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 30, '30th');
date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 31, '31st');

options = {
currentDate : new Date('Sun Oct 30 2016 01:00:00 GMT+0200')
}

interval = CronExpression.parse('0 12 * * *', options);
t.ok(interval, 'Interval parsed');

date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 30, '30th');
date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 31, '31st');

options = {
currentDate : new Date('Sun Oct 30 2016 01:59:00 GMT+0200')
}

interval = CronExpression.parse('0 12 * * *', options);
t.ok(interval, 'Interval parsed');

date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 30, '30th');
date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 31, '31st');

options = {
currentDate : new Date('Sun Oct 30 2016 01:59:59 GMT+0200')
}

interval = CronExpression.parse('0 12 * * *', options);
t.ok(interval, 'Interval parsed');

date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 30, '30th');
date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 31, '31st');

options = {
currentDate : new Date('Sun Oct 30 2016 02:59:00 GMT+0200')
}

interval = CronExpression.parse('0 12 * * *', options);
t.ok(interval, 'Interval parsed');

date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 30, '30th');
date = interval.next();
t.equal(date.getHours(), 12, '12');
t.equal(date.getDate(), 31, '31st');
} catch (err) {
t.ifError(err, 'Interval parse error');
}
Expand Down