cron-style scheduled task starts on UTC, not local time
-
Problem:
- I scheduled a task to begin at 15:30 (CDT)
- The task began at 10:30 (CDT) instead
Background:
- I am in US Central time zone (CDT, aka UTC -5)
- On the FOG server web GUI, in FOG Settings->General Settings “TZ INFO” is set to “America/Chicago [CDT -05:00]”
- The FOG server is set to use CDT:
lrwxrwxrwx 1 root root 30 Apr 22 10:16 localtime -> /usr/share/zoneinfo/US/Central
- Time according to my fog server when the above cron scheduled task kicked off:
root@masterfog-1-5-10:~# date Wed Oct 15 10:00:10 AM CDT 2025
My understanding is if a Linux computer’s localtime is set different from UTC, the cron should use the local time automatically.
-
@RAThomas Even (slightly) better:
$GLOBALS['TimeZone'] = $fog_settings[4] ?? (ini_get('date.timezone') ?: 'UTC');
We lose a storage variable (freeing up a tiny bit of memory) and just get the value directly as possible.
-
@RAThomas So the display time of thigns should follow the TZ Info, but hte /etc/php.ini (or its equivalent) for timezone will need to be set as well as that’s the point the service starts up with.
-
@Tom-Elliott Thank you for pointing me in the right direction. I’ve corrected it for myself, but after looking around in the PHP code, I’d like to ponder a change in defaults/settings priority.
Right now the FOG timezone selection logic is: If php.ini specifies a timezone (and PHP 8.2 appears to “specify” UTC if there’s nothing explicitly set in php.ini), then use that timezone. Ie, FOG will always use UTC or what is specified in php.ini, and FOG will never use $fogsettings[4].
I propose (only if my above analysis is correct) that we flip the priority logic to favor $fogsettings[4] timezone setting.
fogcore.class.php::setEnv() existing logic:
$defTz = ini_get('date.timezone'); if (empty($defTz)) { if (empty($fog_settings[4])) { $GLOBALS['TimeZone'] = 'UTC'; } else { $GLOBALS['TimeZone'] = $fog_settings[4]; } } else { $GLOBALS['TimeZone'] = $defTz; }
Proposed logic:
$defTz = ini_get('date.timezone'); if (empty($fog_settings[4])) { if (empty($defTz)) { $GLOBALS['TimeZone'] = 'UTC'; } else { $GLOBALS['TimeZone'] = $defTz; } } else { $GLOBALS['TimeZone'] = $fog_settings[4]; }
-
@RAThomas screencap showing the above proposed change working correctly (scheduled task above, resulting active task below, shown at ~15:00:10
Ie. my proposed code change is working for me. My php.ini still does not explicitly set a timezone, but FOG settings does set my CDT timezone.
-
@RAThomas What about simplifying the whole stanza?
I’m not saying I don’t like your suggestions, just that this stanza should effectively do exactly the same thing, just much more simplified.
$GLOBALS['TimeZone'] = $fog_settings[4] ?? ($defTz ?? 'UTC');
-
@Tom-Elliott I do like me some simplification. I will try your suggestion and report back.
-
@RAThomas Even (slightly) better:
$GLOBALS['TimeZone'] = $fog_settings[4] ?? (ini_get('date.timezone') ?: 'UTC');
We lose a storage variable (freeing up a tiny bit of memory) and just get the value directly as possible.
-
@Tom-Elliott I’ve tested it with a deploy task scheduled for 15:30 and it fired off the active task at 15:30:34, which is a big PASS in my book.
Now, are you going to make me do a pull request?
PS: I will, pro forma, test your last tweak, but that looks fine too.
-
-
@RAThomas Confirmed the very last tweak to be working, as expected.