Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node-cron with timezones

i have a node(v0.7.3-pre) server with node-cron(0.3.2) and node-time(0.8.2):

var cronJob = require('cron').CronJob;
var cronJ = new cronJob({
 cronTime: "00 29 16 6 * *",
 onTick: function() {
  console.log("Tick");
 },
 start:true,
 timeZone: "America/Los_Angeles"
});
console.log(cronJ);

it runs, but the Cron is allways working with the server time(UTC), and the returned cron is:

{ _callbacks: [ [Function] ],
  onComplete: undefined,
  cronTime:
   { source: '00 29 16 6 * *',
     zone: undefined,
     second: { '0': true },
     minute: { '29': true },
     hour: { '16': true },
     dayOfWeek:
...

the zone is set as undefined, am i missing something?

like image 312
Joaolvcm Avatar asked Jun 06 '12 16:06

Joaolvcm


People also ask

How do I change the timezone on my crontab?

Thankfully, you can configure a specific timezone for your Cron job as follows: First, you need to export the TZ variable in your Shell script before any other Shell entries. Next, access your crontab and use the crontab environment variable CRON_TZ at the start of the crontab file.

How do I schedule a cron job in node js?

Scheduling a Simple Task with node-cron Input the following code into the index. js file to create our simple task scheduler: const cron = require("node-cron"); const express = require("express"); const app = express(); cron. schedule("*/15 * * * * *", function () { console.

What is node-cron?

The node-cron module is tiny task scheduler in pure JavaScript for node. js based on GNU crontab. This module allows you to schedule task in node. js using full crontab syntax.


1 Answers

Because an error in node-cron module. I already send a pull request that will fix it. You can change this lines in your local copy of this module.

You also can use several function parameters to initialize cronJob instead of one object:

var cronJob = require('cron').CronJob;
var cronJ = new cronJob("00 29 16 6 * *", function() {
        console.log("Tick");
}, undefined, true, "America/Los_Angeles");

console.log(cronJ);
like image 159
Vadim Baryshev Avatar answered Sep 23 '22 22:09

Vadim Baryshev