Skip to content

Commit

Permalink
Add example demonstrating UTC parameter usage
Browse files Browse the repository at this point in the history
  • Loading branch information
intcreator committed Feb 18, 2023
1 parent 0926269 commit d07333f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Parameter Based
- `timeZone` - [OPTIONAL] - Specify the timezone for the execution. This will modify the actual time relative to your timezone. If the timezone is invalid, an error is thrown. You can check all timezones available at [Moment Timezone Website](http://momentjs.com/timezone/). Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
- `context` - [OPTIONAL] - The context within which to execute the onTick method. This defaults to the cronjob itself allowing you to call `this.stop()`. However, if you change this you'll have access to the functions and values within your context object.
- `runOnInit` - [OPTIONAL] - This will immediately fire your `onTick` function as soon as the requisite initialization has happened. This option is set to `false` by default for backwards compatibility.
- `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your timezone rather than using the `timeZone` param. Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
- `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your timezone rather than using the `timeZone` param. This should be an integer amount representing the number of minutes offset (like `120` for +2 hours or `-90` for -1.5 hours) Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
- `unrefTimeout` - [OPTIONAL] - If you have code that keeps the event loop running and want to stop the node process when that finishes regardless of the state of your cronjob, you can do so making use of this parameter. This is off by default and cron will run as if it needs to control the event loop. For more information take a look at [timers#timers_timeout_unref](https://nodejs.org/api/timers.html#timers_timeout_unref) from the NodeJS docs.
- `start` - Runs your job.
- `stop` - Stops your job.
Expand Down
16 changes: 16 additions & 0 deletions examples/utc_offset_syntax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const CronJob = require('../lib/cron.js').CronJob;

console.log('first');
const job = new CronJob(
'0 0 9 4 * *',
function() {
console.log('message');
},
null,
true,
null,
null,
null,
-360, // UTC-6, represented in minutes
);
console.log('second');

0 comments on commit d07333f

Please sign in to comment.