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

fix: issue #74 use local timezone #76

Merged
merged 6 commits into from
Feb 5, 2021
Merged

fix: issue #74 use local timezone #76

merged 6 commits into from
Feb 5, 2021

Conversation

snrmwg
Copy link
Contributor

@snrmwg snrmwg commented Jan 17, 2021

Use local timezone for jobs created with cron pattern or intervals written as human-friendly time representations.

Fixes #74.

@shadowgate15
Copy link
Member

you would also need to add to job-builder.js and job-utils.js.

it also might be good to have this as an option in config with the default being local tz.

@snrmwg
Copy link
Contributor Author

snrmwg commented Jan 18, 2021

@shadowgate15 why? For my newly added tests the one place to fix seems to be enough. Could you provide additional tests that make clear the other places also need the extension?

And the broken build is a different test that also breaks the PR #75 currently.

@shadowgate15
Copy link
Member

if anything, it isn't needed in index, since it is only used to schedule intervals and timeouts. In job-builder, it is used to create a schedule which is then used to set timeouts and intervals. I believe job-utils, uses it similarly.

@niftylettuce
Copy link
Contributor

I'll defer to you @shadowgate15 and @naz to merge/review

bree.start('basic');
bree.on('worker created', () => {
const now = new Date(clock.now);
t.is(now.getHours(), 18);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's change this to the timezone offset instead, so that we are testing explicitly what we want instead of an after effect. you should be able to use now.getTimezoneOffset()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think now.getTimezoneOffset() makes assertion unnecessary complex. Because then the result will depend on the timezone the test is executed. For my local system for example (CET) the result would be -60.

The check on now.getHours() simply checks the wanted effect: the cron pattern says "do it at 18:00 o'clock". So when the job gets executed, the hour of now is expected to be 18. Independent of timezone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want to be testing the actual offset not just what the hours say.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I added the offset check in the tests.

@snrmwg
Copy link
Contributor Author

snrmwg commented Jan 31, 2021

Anything I can do to speedup process?

@shadowgate15
Copy link
Member

does it still work correctly when you add a new job after bree has been created?

moved localTime init to job-builder.js;
new test to verify functionality when job is added;
extended verification of timezone offset in test
Copy link
Contributor Author

@snrmwg snrmwg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it still work correctly when you add a new job after bree has been created?

I added another test to verify your scenario ("add > job created with cron string is using local timezone") and it is also green.

bree.start('basic');
bree.on('worker created', () => {
const now = new Date(clock.now);
t.is(now.getHours(), 18);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think now.getTimezoneOffset() makes assertion unnecessary complex. Because then the result will depend on the timezone the test is executed. For my local system for example (CET) the result would be -60.

The check on now.getHours() simply checks the wanted effect: the cron pattern says "do it at 18:00 o'clock". So when the job gets executed, the hour of now is expected to be 18. Independent of timezone.

bree.start('basic');
bree.on('worker created', () => {
const now = new Date(clock.now);
t.is(now.getHours(), 18);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I added the offset check in the tests.

@snrmwg
Copy link
Contributor Author

snrmwg commented Feb 1, 2021

if anything, it isn't needed in index, since it is only used to schedule intervals and timeouts. In job-builder, it is used to create a schedule which is then used to set timeouts and intervals. I believe job-utils, uses it similarly.

I have done it in index because it is the first place where later is used. In NodeJs each call of require('@breejs/later') will return the same instance. But I have moved the config call now to job-utils. Behaviour stays the same, my newly added tests are still green.

@shadowgate15
Copy link
Member

Thanks for all the work @snrmwg!

@shadowgate15 shadowgate15 merged commit 7be21b4 into breejs:master Feb 5, 2021
@snrmwg
Copy link
Contributor Author

snrmwg commented Feb 5, 2021

Thanks for all the work @snrmwg!

My pleasure! Looking forward to the next release of breejs. @shadowgate15

@snrmwg snrmwg deleted the issue/74-use-local-timezone branch February 5, 2021 14:31
@niftylettuce
Copy link
Contributor

v5.0.0 released https://github.com/breejs/bree/releases/tag/v5.0.0 🎉 you all rock. thank you @shadowgate15 et all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cron job times are interpreted as UTC timezone
3 participants