private static function detectSystemTimezone()
    {
        // Mac OS X (and older Linuxes): /etc/localtime is a symlink to the
        // timezone in /usr/share/zoneinfo or /var/db/timezone/zoneinfo.
        if (is_link('/etc/localtime')) {
            $filename = readlink('/etc/localtime');
            $prefixes = [
                '/usr/share/zoneinfo/',
                '/var/db/timezone/zoneinfo/',
            ];
            foreach ($prefixes as $prefix) {
                if (strpos($filename, $prefix) === 0) {
                    return substr($filename, strlen($prefix));
                }
            }
        }

        // Ubuntu and Debian.
        if (file_exists('/etc/timezone')) {
            $data = file_get_contents('/etc/timezone');
            if ($data !== false) {
                return trim($data);
            }
        }

        // RHEL and CentOS.
        if (file_exists('/etc/sysconfig/clock')) {
            $data = parse_ini_file('/etc/sysconfig/clock');
            if (!empty($data['ZONE'])) {
                return trim($data['ZONE']);
            }
        }

        return false;
    }