Skip to content

Commit

Permalink
test: add test for "UTC+HH:mm" offset as timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox committed Sep 23, 2023
1 parent bd39c16 commit a3fa57d
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion tests/cron.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ describe('cron', () => {
});

describe('with timezone', () => {
it('should run a job using cron syntax', () => {
it('should run a job using cron syntax with a timezone', () => {
const clock = sinon.useFakeTimers();
const callback = jest.fn();
const luxon = require('luxon');
Expand Down Expand Up @@ -436,6 +436,46 @@ describe('cron', () => {
expect(callback).toHaveBeenCalledTimes(1);
});

it('should run a job using cron syntax with a "UTC+HH:mm" offset as timezone', () => {
const clock = sinon.useFakeTimers();
const callback = jest.fn();
const luxon = require('luxon');

// Current time
const d = luxon.DateTime.local();

// Current time with zone offset
let zone = 'UTC+5:30';
let t = luxon.DateTime.local().setZone(zone);

// If current offset is UTC+5:30, switch to UTC+6:30..
if (t.hour === d.hour && t.minute === d.minute) {
zone = 'UTC+6:30';
t = t.setZone(zone);
}
expect(`${d.hour}:${d.minute}`).not.toBe(`${t.hour}:${t.minute}`);

// If t = 59s12m then t.setSeconds(60)
// becomes 00s13m so we're fine just doing
// this and no testRun callback.
t = t.plus({ seconds: 1 });
// Run a job designed to be executed at a given
// time in `zone`, making sure that it is a different
// hour than local time.
const job = new cron.CronJob(
t.second + ' ' + t.minute + ' ' + t.hour + ' * * *',
callback,
null,
true,
zone
);

clock.tick(1000);
clock.restore();
job.stop();
expect(callback).toHaveBeenCalledTimes(1);
});

it('should run a job using a date', () => {
const luxon = require('luxon');
let zone = 'America/Chicago';
Expand Down

0 comments on commit a3fa57d

Please sign in to comment.