11

My system's timezone is US/Eastern, my default store is US/Central and the database is UTC. At what time will the following doStuff method be called?

<mymodule_do_stuff>
    <schedule><cron_expr>15 0 * * *</cron_expr></schedule>
    <run>
        <model>mymodule/observer::doStuff</model>
    </run>
</mymodule_do_stuff>

Update: I ran this script .

echo date('r'), PHP_EOL;
require_once 'app/Mage.php';
Mage::app();

echo date('r'), PHP_EOL;

and got

Mon, 30 Dec 2013 18:01:33 -0600
Tue, 31 Dec 2013 00:01:34 +0000

So it looks like UTC is what I should be using.

1
  • Your config setting for your timezone with date/time stored as UTC in the database. – Fiasco Labs Dec 31 '13 at 0:17
9

The default time used will be the system time of linux. Use the date function on the command line to find out what it is set to.

Magento 'overwrites' that by setting the locale to whatever you have specified during the installation of the shop. This is specified in the System > Configuration > General per store or on default scope.

3
  • I don't think this is right. Magento calls date_default_timezone_set('UTC') in Mage::isInstalled() which is called in cron.php. Where is the locale set to the default store? – nachito Dec 31 '13 at 0:09
  • 3
    by default it's UTC but, as far as I know, when initializing a store so also default scope, uses the locale set in the sys/config. Please correct me if I'm wrong but even store scope 0 uses the defined locale settings – Sander Mangel Dec 31 '13 at 0:42
  • 1
    Yes, this is correct for M2 - if you look at module-cron/Model/Schedule.php, specifically under the trySchedule() method, you'll see where the conversion from UTC to timezone set in the config takes place (including a comment stating we assume that all schedules in configuration (crontab.xml and DB tables) are in admin store timezone) – Phil Birnie Jan 27 '20 at 13:11
3

Times stored in the cron_schedule table are in UTC, but Magento converts it to your store's configured timezone (general/locale/timezone) when checking if a job should run.

I recommend installing Aoe_Scheduler to get a better idea of when your store's cron jobs are being run.

1

Looking at the code in the function:

Mage_Cron_Model_Observer::_generateJobs

The scheduled time is based on the PHP function time(), this uses the configured timezone for PHP (depening on your specific configurationbut) I would say that this is configured just like the system timezone (US/Eastern).

I could not find a place where there is a calculation for the used timezone offset.

1
  • I don't think this is right. See my update – nachito Dec 31 '13 at 0:07
0

Open the file Mage_Cron_Model_Observer and put a Mage::log() just after or before
$now = time(); line

public function dispatch($observer)
    {
        $schedules = $this->getPendingSchedules();
        $scheduleLifetime = Mage::getStoreConfig(self::XML_PATH_SCHEDULE_LIFETIME) * 60;
        $now = time();
        Mage::log("cron timezone: " . date_default_timezone_get(), Zend_Log::DEBUG); // this will log the cron timezone into var/log/system.log file
        $jobsRoot = Mage::getConfig()->getNode('crontab/jobs');
        $defaultJobsRoot = Mage::getConfig()->getNode('default/crontab/jobs');
 . . . . .
}

Then if you check var/log/system.log you can exactly know which time zone has been used by Magento.

1
  • And then add/subtract UTC offset to convert any dates stored in the cron log table or elsewhere. – Fiasco Labs Dec 31 '13 at 17:27
0

They trigger per your Locale config setting in Magento for your timezone with date/time stored as UTC in the database.

The system timezone that Magento is running on can be separate from Magento's config setting.

This is all by observation. My server runs MST, Magento is PST which means that for part of the year, external cron jobs diverge from Magento's cron jobs by 1 hour due to one of them observing DST.

If you want confirmation, install the AOE Scheduler module and you can read it off the mouseover. Currently AOE is showing 16:30 PST which is 4:30 PM PST.

Runtime: 2013-12-30   Server: 17:44:59 MST   Store: 16:44:59   Zulu: 00:44:59 UTC
Note: All logged times are UTC, your server timezone offset is -07:00 hours from UTC

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.