From 0f4d381ac01a88571865679a9c99ea4c4bea701f Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Sat, 8 Aug 2026 22:35:31 -0400 Subject: [PATCH] Make PHP agree with the clock the rest of the server keeps --- Plugin/unraid/include/config.php | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Plugin/unraid/include/config.php b/Plugin/unraid/include/config.php index ff2a28c..ed6b9ed 100644 --- a/Plugin/unraid/include/config.php +++ b/Plugin/unraid/include/config.php @@ -56,9 +56,46 @@ // varaverk.cfg SCRIPTS_DIR, CUSTOM_SCRIPTS_DIR // master.conf HOST / HOST_NAME — host identity // host*.conf HOST*_SSH_KEY — used for setup-state and conf push +// ident.cfg timeZone — Unraid's own setting, adopted for the whole PHP layer // VV_CACHE_DIR /tmp/vv_cache (tmpfs — RAM speed, cleared on reboot) // ═══════════════════════════════════════════════════════════════════════════════════════════════ +// ── Timezone ────────────────────────────────────────────────────────────────── +// Set here, before anything else, because every PHP entry point in the plugin reaches this file +// and nothing that runs earlier has a date in it. +// +// PHP on Unraid has no date.timezone set and therefore runs in UTC, while the server itself runs +// local — America/New_York on this one. Every date this layer produced was consequently offset +// from every date the shell layer wrote, and the two are compared constantly: the token ledger, +// the rsync history, the arr run dates, the parity cron. The AI tab's "Today" tile read zero for +// the four hours between 8pm and midnight, the 7-day windows were cut at the wrong instant, and +// the next parity check was displayed four hours out. All of it silent, all of it in the same +// direction, all of it invisible for two thirds of the day. +// +// /etc/php.ini is the wrong place to fix it twice over: /etc is a RAM filesystem here, so the +// edit dies at the next reboot, and it would change the timezone for every other PHP application +// on the box to fix one of ours. +// +// ident.cfg is Unraid's own setting, on the flash, and is what the WebGUI's own clock uses — so +// this follows the operator's configured timezone rather than asserting one, and a second host +// in another zone gets its own. The /etc/localtime symlink is the fallback because it is what +// the C library actually honours; UTC last, which is merely today's broken behaviour made +// explicit rather than accidental. +$_vv_tz = ''; +foreach (@file('/boot/config/ident.cfg') ?: [] as $_l) { + if (preg_match('/^\s*timeZone\s*=\s*"?([^"\r\n]+)"?/', $_l, $_m)) { $_vv_tz = trim($_m[1]); break; } +} +if ($_vv_tz === '') { + $_link = @readlink('/etc/localtime') ?: ''; + if (preg_match('#zoneinfo/(.+)$#', $_link, $_m)) $_vv_tz = $_m[1]; +} +// Validated before use. An unparseable value would otherwise raise a warning on every request +// and leave the process in UTC anyway, which is the bug this exists to remove. +if ($_vv_tz === '' || !@timezone_open($_vv_tz)) $_vv_tz = 'UTC'; +date_default_timezone_set($_vv_tz); +define('VV_TIMEZONE', $_vv_tz); +unset($_vv_tz, $_l, $_m, $_link); + define('PLUGIN_CFG', '/boot/config/plugins/varaverk/varaverk.cfg'); $_vv_cfg = @parse_ini_file(PLUGIN_CFG) ?: [];