Classes

File util/Timezone.class.php

File util/Timezone.class.php

 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 
<?php
/**
 * @package     Util
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Benoit SAUTEL <ben.popeye@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2015 01 01
 * @since       PHPBoost 3.0 - 2010 10 30
 * @contributor Kevin MASSY <reidlos@phpboost.com>
*/

class Timezone
{
    const SERVER_TIMEZONE = 1;
    const SITE_TIMEZONE = 2;
    const USER_TIMEZONE = 3;

    private static $server_timezone;
    private static $site_timezone;
    private static $user_timezone;

    public static function get_supported_timezones()
    {
        return DateTimeZone::listIdentifiers();
    }

    /**
     * Returns the PHP timezone corresponding to the timezone code
     * @param int $timezone SERVER_TIMEZONE, SITE_TIMEZONE or USER_TIMEZONE
     * @return DateTimeZone The PHP timezone
     */
    public static function get_timezone($timezone_code)
    {
        switch($timezone_code)
        {
            case self::SERVER_TIMEZONE:
                return self::get_server_timezone();
            case self::SITE_TIMEZONE:
                return self::get_site_timezone();
            default:
                return self::get_user_timezone();
        }
    }

    public static function get_server_timezone()
    {
        if (self::$server_timezone == null)
        {
            self::$server_timezone = new DateTimeZone(date_default_timezone_get());
        }
        return self::$server_timezone;
    }

    public static function get_site_timezone()
    {
        if (self::$site_timezone == null)
        {
            self::$site_timezone = new DateTimeZone(GeneralConfig::load()->get_site_timezone());
        }
        return self::$site_timezone;
    }

    public static function get_user_timezone()
    {
        if (self::$user_timezone == null)
        {
            self::$user_timezone = new DateTimeZone(AppContext::get_current_user()->get_timezone());
        }
        return self::$user_timezone;
    }
}
?>