mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-19 23:32:02 +02:00
Merge branch '3.3.x'
This commit is contained in:
commit
9b97986351
@ -227,15 +227,7 @@ class user extends \phpbb\session
|
||||
|
||||
$this->language->set_user_language($user_lang_name);
|
||||
|
||||
try
|
||||
{
|
||||
$this->timezone = new \DateTimeZone($user_timezone);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
// If the timezone the user has selected is invalid, we fall back to UTC.
|
||||
$this->timezone = new \DateTimeZone('UTC');
|
||||
}
|
||||
$this->create_timezone($user_timezone);
|
||||
|
||||
$this->add_lang($lang_set);
|
||||
unset($lang_set);
|
||||
@ -631,7 +623,7 @@ class user extends \phpbb\session
|
||||
if (!$format_date_override)
|
||||
{
|
||||
$time = new $this->datetime($this, '@' . (int) $gmepoch, $utc);
|
||||
$time->setTimezone($this->timezone);
|
||||
$time->setTimezone($this->create_timezone());
|
||||
|
||||
return $time->format($format, $forcedate);
|
||||
}
|
||||
@ -641,6 +633,36 @@ class user extends \phpbb\session
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a DateTimeZone object in the context of the current user
|
||||
*
|
||||
* @param string $user_timezone Time zone of the current user.
|
||||
* @return DateTimeZone DateTimeZone object linked to the current users locale
|
||||
*/
|
||||
public function create_timezone($user_timezone = null)
|
||||
{
|
||||
if (!$this->timezone)
|
||||
{
|
||||
if (!$user_timezone)
|
||||
{
|
||||
global $config;
|
||||
$user_timezone = ($this->data['user_id'] != ANONYMOUS) ? $this->data['user_timezone'] : $config['board_timezone'];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$this->timezone = new \DateTimeZone($user_timezone);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
// If the timezone the user has selected is invalid, we fall back to UTC.
|
||||
$this->timezone = new \DateTimeZone('UTC');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->timezone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a \phpbb\datetime object in the context of the current user
|
||||
*
|
||||
@ -651,7 +673,7 @@ class user extends \phpbb\session
|
||||
*/
|
||||
public function create_datetime($time = 'now', \DateTimeZone $timezone = null)
|
||||
{
|
||||
$timezone = $timezone ?: $this->timezone;
|
||||
$timezone = $timezone ?: $this->create_timezone();
|
||||
return new $this->datetime($this, $time, $timezone);
|
||||
}
|
||||
|
||||
@ -665,7 +687,7 @@ class user extends \phpbb\session
|
||||
*/
|
||||
public function get_timestamp_from_format($format, $time, \DateTimeZone $timezone = null)
|
||||
{
|
||||
$timezone = $timezone ?: $this->timezone;
|
||||
$timezone = $timezone ?: $this->create_timezone();
|
||||
$date = \DateTime::createFromFormat($format, $time, $timezone);
|
||||
return ($date !== false) ? $date->format('U') : false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user