Skip to content

Commit

Permalink
fix: issue #74 use local timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
snrmwg committed Jan 17, 2021
1 parent 5abf59f commit 5d56016
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const {
const buildJob = require('./job-builder');
const validateJob = require('./job-validator');

later.date.localTime();

// bthreads requires us to do this for web workers (see bthreads docs for insight)
threads.Buffer = Buffer;

Expand Down
35 changes: 35 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,41 @@ test('fails if cron pattern is invalid', (t) => {
);
});

test.serial('job created with cron string is using local timezone', (t) => {
t.plan(1);
const bree = new Bree({
root,
jobs: [{ name: 'basic', cron: '0 18 * * *' }]
});

const clock = FakeTimers.install({ now: Date.now() });
bree.start('basic');
bree.on('worker created', () => {
const now = new Date(clock.now);
t.is(now.getHours(), 18);
});
clock.next();
clock.uninstall();
});

test.serial('job created with human interval is using local timezone', (t) => {
t.plan(2);
const bree = new Bree({
root,
jobs: [{ name: 'basic', interval: 'at 13:26' }]
});

const clock = FakeTimers.install({ now: Date.now() });
bree.start('basic');
bree.on('worker created', () => {
const now = new Date(clock.now);
t.is(now.getHours(), 13);
t.is(now.getMinutes(), 26);
});
clock.next();
clock.uninstall();
});

test('fails if closeWorkersAfterMs is <= 0 or infinite', (t) => {
t.throws(
() =>
Expand Down

0 comments on commit 5d56016

Please sign in to comment.