Correct. My code is wrong. I was searching for this answer today and didn't even remember I'd written this.
I have revised my answer just now:
// Add these lines to your config.php file.
// Tell PHP to use this timezone as the default when a timezone API call doesn't specify a zone.
// Change to your local time zone name: https://www.php.net/manual/en/timezones.php
date_default_timezone_set('America/New_York');
// Initialize database connection with session time zone based on PHP's time zone.
$config->dbInitCommand = (function() {
$charset = 'utf8';
// What is the timezone offset (in minutes) from UTC for the current time in the current timezone?
$minutes = (new \DateTime())->getOffset() / 60;
$sign = ($minutes >= 0) ? '+' : '-';
$h = str_pad(intdiv(abs($minutes), 60), 2, '0', STR_PAD_LEFT);
$m = str_pad(abs($minutes) % 60, 2, '0', STR_PAD_LEFT);
$dbTimeZone = "{$sign}{$h}:{$m}";
return "SET NAMES '{$charset}', time_zone = '{$dbTimeZone}'";
})();
// Tell ProcessWire to use this timezone.
// (You'll find this in your config file already under the comment "Installer: Time zone setting".)
$config->timezone = 'America/New_York';