icingaweb2/library/Icinga/Util/TimezoneDetect.php
Eric Lippmann 662de28f85 License source files as GPL-3.0-or-later
Add SPDX license headers and mark source files as GPL-3.0-or-later to
preserve the option to relicense under later GPL versions.
2026-03-26 17:49:26 +01:00

79 lines
1.4 KiB
PHP

<?php
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Icinga\Util;
use DateTimeZone;
/**
* Retrieve timezone information from cookie
*/
class TimezoneDetect
{
/**
* If detection was successful
*
* @var bool
*/
private static $success;
/**
* @var string
*/
private static $timezoneName;
/**
* Cookie name
*
* @var string
*/
public static $cookieName = 'icingaweb2-tzo';
/**
* Create new object and try to identify the timezone
*/
public function __construct()
{
if (self::$success !== null) {
return;
}
if (in_array($_COOKIE[self::$cookieName] ?? null, DateTimeZone::listIdentifiers(), true)) {
self::$timezoneName = $_COOKIE[self::$cookieName];
self::$success = true;
} else {
self::$success = false;
}
}
/**
* Get timezone name
*
* @return string
*/
public function getTimezoneName()
{
return self::$timezoneName;
}
/**
* True on success
*
* @return bool
*/
public function success()
{
return self::$success;
}
/**
* Reset object
*/
public function reset()
{
self::$success = null;
self::$timezoneName = null;
}
}