Merge branch 'feature/new-tz-handling' of https://github.com/p/phpbb3 into feature/new-tz-handling

Conflicts:
	phpBB/includes/functions_profile_fields.php
	phpBB/includes/session.php
	phpBB/install/database_update.php
This commit is contained in:
Joas Schilling 2012-06-04 18:09:35 +02:00
commit 8f027b68d6
26 changed files with 395 additions and 211 deletions

View file

@ -56,11 +56,6 @@
<dt><label for="tz">{L_BOARD_TIMEZONE}:</label></dt>
<dd><select id="tz" name="tz" style="width: 100%;">{S_TZ_OPTIONS}</select></dd>
</dl>
<dl>
<dt><label for="dst">{L_BOARD_DST}:</label></dt>
<dd><label><input type="radio" class="radio" name="dst" value="1"<!-- IF DST --> id="dst" checked="checked"<!-- ENDIF --> /> {L_YES}</label>
<label><input type="radio" class="radio" name="dst" value="0"<!-- IF not DST --> id="dst" checked="checked"<!-- ENDIF --> /> {L_NO}</label></dd>
</dl>
<dl>
<dt><label for="dateoptions">{L_BOARD_DATE_FORMAT}:</label><br /><span>{L_BOARD_DATE_FORMAT_EXPLAIN}</span></dt>
<dd><select name="dateoptions" id="dateoptions" onchange="if(this.value=='custom'){dE('custom_date',1);}else{dE('custom_date',-1);} if (this.value == 'custom') { document.getElementById('dateformat').value = default_dateformat; } else { document.getElementById('dateformat').value = this.value; }">{S_DATEFORMAT_OPTIONS}</select></dd>

View file

@ -1794,8 +1794,7 @@ function get_schema_struct()
'user_inactive_time' => array('TIMESTAMP', 0),
'user_posts' => array('UINT', 0),
'user_lang' => array('VCHAR:30', ''),
'user_timezone' => array('DECIMAL', 0),
'user_dst' => array('BOOL', 0),
'user_timezone' => array('VCHAR:100', 'UTC'),
'user_dateformat' => array('VCHAR_UNI:30', 'd M Y H:i'),
'user_style' => array('UINT', 0),
'user_rank' => array('UINT', 0),

View file

@ -254,16 +254,8 @@ function feed_format_date($time)
{
global $user;
$zone_offset = (int) $user->timezone + (int) $user->dst;
$sign = ($zone_offset < 0) ? '-' : '+';
$time_offset = abs($zone_offset);
$offset_seconds = $time_offset % 3600;
$offset_minutes = $offset_seconds / 60;
$offset_hours = ($time_offset - $offset_seconds) / 3600;
$offset_string = sprintf("%s%02d:%02d", $sign, $offset_hours, $offset_minutes);
$zone_offset = $user->create_datetime()->getOffset();
$offset_string = phpbb_format_timezone_offset($zone_offset);
}
return gmdate("Y-m-d\TH:i:s", $time + $zone_offset) . $offset_string;

173
phpBB/includes/datetime.php Normal file
View file

@ -0,0 +1,173 @@
<?php
/**
*
* @package phpBB3
* @version $Id$
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
/**
* phpBB custom extensions to the PHP DateTime class
* This handles the relative formats phpBB employs
*/
class phpbb_datetime extends DateTime
{
/**
* String used to wrap the date segment which should be replaced by today/tomorrow/yesterday
*/
const RELATIVE_WRAPPER = '|';
/**
* @var user User who is the context for this DateTime instance
*/
protected $_user;
/**
* @var array Date formats are preprocessed by phpBB, to save constant recalculation they are cached.
*/
static protected $format_cache = array();
/**
* Constructs a new instance of phpbb_datetime, expanded to include an argument to inject
* the user context and modify the timezone to the users selected timezone if one is not set.
*
* @param string $time String in a format accepted by strtotime().
* @param DateTimeZone $timezone Time zone of the time.
* @param user User object for context.
*/
public function __construct($time = 'now', DateTimeZone $timezone = null, $user = null)
{
$this->_user = $user ? $user : $GLOBALS['user'];
$timezone = (!$timezone && $this->_user->tz instanceof DateTimeZone) ? $this->_user->tz : $timezone;
parent::__construct($time, $timezone);
}
/**
* Returns a UNIX timestamp representation of the date time.
*
* @internal This method is for backwards compatibility with 5.2, hence why it doesn't use our method naming standards.
* @return int UNIX timestamp
*/
public function getTimestamp()
{
static $compat;
if (!isset($compat))
{
$compat = !method_exists('DateTime', 'getTimestamp');
}
return !$compat ? parent::getTimestamp() : (int) parent::format('U');
}
/**
* Formats the current date time into the specified format
*
* @param string $format Optional format to use for output, defaults to users chosen format
* @param boolean $force_absolute Force output of a non relative date
* @return string Formatted date time
*/
public function format($format = '', $force_absolute = false)
{
$format = $format ? $format : $this->_user->date_format;
$format = self::_format_cache($format, $this->_user);
$relative = ($format['is_short'] && !$force_absolute);
$now = new self('now', $this->_user->tz, $this->_user);
$timestamp = $this->getTimestamp();
$now_ts = $now->getTimeStamp();
$delta = $now_ts - $timestamp;
if ($relative)
{
// Check the delta is less than or equal to 1 hour
// and the delta not more than a minute in the past
// and the delta is either greater than -5 seconds or timestamp and current time are of the same minute (they must be in the same hour already)
// finally check that relative dates are supported by the language pack
if ($delta <= 3600 && $delta > -60 && ($delta >= -5 || (($now_ts / 60) % 60) == (($timestamp / 60) % 60)) && isset($this->_user->lang['datetime']['AGO']))
{
return $this->_user->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60)));
}
else
{
$midnight = clone $now;
$midnight->setTime(0, 0, 0);
$midnight = $midnight->getTimestamp();
$day = false;
if ($timestamp > $midnight + 86400)
{
$day = 'TOMORROW';
}
else if ($timestamp > $midnight)
{
$day = 'TODAY';
}
else if ($timestamp > $midnight - 86400)
{
$day = 'YESTERDAY';
}
if ($day !== false)
{
// Format using the short formatting and finally swap out the relative token placeholder with the correct value
return str_replace(self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER, $this->_user->lang['datetime'][$day], strtr(parent::format($format['format_short']), $format['lang']));
}
}
}
return strtr(parent::format($format['format_long']), $format['lang']);
}
/**
* Magic method to convert DateTime object to string
*
* @return Formatted date time, according to the users default settings.
*/
public function __toString()
{
return $this->format();
}
/**
* Pre-processes the specified date format
*
* @param string $format Output format
* @param user $user User object to use for localisation
* @return array Processed date format
*/
static protected function _format_cache($format, $user)
{
$lang = $user->lang_name;
if (!isset(self::$format_cache[$lang]))
{
self::$format_cache[$lang] = array();
}
if (!isset(self::$format_cache[$lang][$format]))
{
// Is the user requesting a friendly date format (i.e. 'Today 12:42')?
self::$format_cache[$lang][$format] = array(
'is_short' => strpos($format, self::RELATIVE_WRAPPER) !== false,
'format_short' => substr($format, 0, strpos($format, self::RELATIVE_WRAPPER)) . self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER . substr(strrchr($format, self::RELATIVE_WRAPPER), 1),
'format_long' => str_replace(self::RELATIVE_WRAPPER, '', $format),
'lang' => $user->lang['datetime'],
);
// Short representation of month in format? Some languages use different terms for the long and short format of May
if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false))
{
self::$format_cache[$lang][$format]['lang']['May'] = $user->lang['datetime']['May_short'];
}
}
return self::$format_cache[$lang][$format];
}
}

View file

@ -1068,30 +1068,116 @@ function style_select($default = '', $all = false)
return $style_options;
}
function phpbb_format_timezone_offset($tz_offset)
{
$sign = ($tz_offset < 0) ? '-' : '+';
$time_offset = abs($tz_offset);
$offset_seconds = $time_offset % 3600;
$offset_minutes = $offset_seconds / 60;
$offset_hours = ($time_offset - $offset_seconds) / 3600;
$offset_string = sprintf("%s%02d:%02d", $sign, $offset_hours, $offset_minutes);
return $offset_string;
}
// Compares two time zone labels.
// Arranges them in increasing order by timezone offset.
// Places UTC before other timezones in the same offset.
function tz_select_compare($a, $b)
{
$a_sign = $a[3];
$b_sign = $b[3];
if ($a_sign != $b_sign)
{
return $a_sign == '-' ? -1 : 1;
}
$a_offset = substr($a, 4, 5);
$b_offset = substr($b, 4, 5);
if ($a_offset == $b_offset)
{
$a_name = substr($a, 12);
$b_name = substr($b, 12);
if ($a_name == $b_name)
{
return 0;
} else if ($a_name == 'UTC')
{
return -1;
} else if ($b_name == 'UTC')
{
return 1;
}
else
{
return $a_name < $b_name ? -1 : 1;
}
}
else
{
if ($a_sign == '-')
{
return $a_offset > $b_offset ? -1 : 1;
}
else
{
return $a_offset < $b_offset ? -1 : 1;
}
}
}
/**
* Pick a timezone
* @todo Possible HTML escaping
*/
function tz_select($default = '', $truncate = false)
{
global $user;
$tz_select = '';
foreach ($user->lang['tz_zones'] as $offset => $zone)
static $timezones;
if (!isset($timezones))
{
if ($truncate)
$timezones = DateTimeZone::listIdentifiers();
foreach ($timezones as &$timezone)
{
$zone_trunc = truncate_string($zone, 50, 255, false, '...');
$tz = new DateTimeZone($timezone);
$dt = new phpbb_datetime('now', $tz);
$offset = $dt->getOffset();
$offset_string = phpbb_format_timezone_offset($offset);
$timezone = 'GMT' . $offset_string . ' - ' . $timezone;
}
unset($timezone);
usort($timezones, 'tz_select_compare');
}
$tz_select = '';
foreach ($timezones as $timezone)
{
if (isset($user->lang['timezones'][$timezone]))
{
$title = $label = $user->lang['timezones'][$timezone];
}
else
{
$zone_trunc = $zone;
// No label, we'll figure one out
// @todo rtl languages?
$bits = explode('/', str_replace('_', ' ', $timezone));
$title = $label = implode(' - ', $bits);
}
if (is_numeric($offset))
if ($truncate)
{
$selected = ($offset == $default) ? ' selected="selected"' : '';
$tz_select .= '<option title="' . $zone . '" value="' . $offset . '"' . $selected . '>' . $zone_trunc . '</option>';
$label = truncate_string($label, 50, 255, false, '...');
}
$selected = ($timezone === $default) ? ' selected="selected"' : '';
$tz_select .= '<option title="' . $title . '" value="' . $timezone . '"' . $selected . '>' . $label . '</option>';
}
return $tz_select;

View file

@ -554,9 +554,12 @@ class custom_profile
else if ($day && $month && $year)
{
global $user;
// Date should display as the same date for every user regardless of timezone, so remove offset
// to compensate for the offset added by phpbb_user::format_date()
return $user->format_date(gmmktime(0, 0, 0, $month, $day, $year) - ($user->timezone + $user->dst), $user->lang['DATE_FORMAT'], true);
// Date should display as the same date for every user regardless of timezone
return $user->create_datetime()
->setDate($year, $month, $day)
->setTime(0, 0, 0)
->format($user->lang['DATE_FORMAT'], true);
}
return $value;

View file

@ -29,8 +29,7 @@ class phpbb_user extends phpbb_session
var $help = array();
var $theme = array();
var $date_format;
var $timezone;
var $dst;
public $tz;
var $lang_name = false;
var $lang_id = false;
@ -79,15 +78,13 @@ class phpbb_user extends phpbb_session
$this->lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']);
$this->date_format = $this->data['user_dateformat'];
$this->timezone = $this->data['user_timezone'] * 3600;
$this->dst = $this->data['user_dst'] * 3600;
$this->tz = $this->data['user_timezone'];
}
else
{
$this->lang_name = basename($config['default_lang']);
$this->date_format = $config['default_dateformat'];
$this->timezone = $config['board_timezone'] * 3600;
$this->dst = $config['board_dst'] * 3600;
$this->tz = $config['board_timezone'];
/**
* If a guest user is surfing, we try to guess his/her language first by obtaining the browser language
@ -126,6 +123,14 @@ class phpbb_user extends phpbb_session
*/
}
if (is_numeric($this->tz))
{
// Might still be numeric by chance
$this->tz = sprintf('Etc/GMT%+d', ($this->tz + ($this->data['user_id'] != ANONYMOUS ? $this->data['user_dst'] : $config['board_dst'])));
}
$this->tz = new DateTimeZone($this->tz);
// We include common language file here to not load it every time a custom language file is included
$lang = &$this->lang;
@ -615,70 +620,31 @@ class phpbb_user extends phpbb_session
*/
function format_date($gmepoch, $format = false, $forcedate = false)
{
static $midnight;
static $date_cache;
static $utc;
$format = (!$format) ? $this->date_format : $format;
$now = time();
$delta = $now - $gmepoch;
if (!isset($date_cache[$format]))
if (!isset($utc))
{
// Is the user requesting a friendly date format (i.e. 'Today 12:42')?
$date_cache[$format] = array(
'is_short' => strpos($format, '|'),
'format_short' => substr($format, 0, strpos($format, '|')) . '||' . substr(strrchr($format, '|'), 1),
'format_long' => str_replace('|', '', $format),
'lang' => $this->lang['datetime'],
);
// Short representation of month in format? Some languages use different terms for the long and short format of May
if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false))
{
$date_cache[$format]['lang']['May'] = $this->lang['datetime']['May_short'];
}
$utc = new DateTimeZone('UTC');
}
// Zone offset
$zone_offset = $this->timezone + $this->dst;
$time = new phpbb_datetime("@$gmepoch", $utc, $this);
$time->setTimezone($this->tz);
// Show date < 1 hour ago as 'xx min ago' but not greater than 60 seconds in the future
// A small tolerence is given for times in the future but in the same minute are displayed as '< than a minute ago'
if ($delta < 3600 && $delta > -60 && ($delta >= -5 || (($now / 60) % 60) == (($gmepoch / 60) % 60)) && $date_cache[$format]['is_short'] !== false && !$forcedate && isset($this->lang['datetime']['AGO']))
{
return $this->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60)));
}
return $time->format($format, $forcedate);
}
if (!$midnight)
{
list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $zone_offset));
$midnight = gmmktime(0, 0, 0, $m, $d, $y) - $zone_offset;
}
if ($date_cache[$format]['is_short'] !== false && !$forcedate && !($gmepoch < $midnight - 86400 || $gmepoch > $midnight + 172800))
{
$day = false;
if ($gmepoch > $midnight + 86400)
{
$day = 'TOMORROW';
}
else if ($gmepoch > $midnight)
{
$day = 'TODAY';
}
else if ($gmepoch > $midnight - 86400)
{
$day = 'YESTERDAY';
}
if ($day !== false)
{
return str_replace('||', $this->lang['datetime'][$day], strtr(@gmdate($date_cache[$format]['format_short'], $gmepoch + $zone_offset), $date_cache[$format]['lang']));
}
}
return strtr(@gmdate($date_cache[$format]['format_long'], $gmepoch + $zone_offset), $date_cache[$format]['lang']);
/**
* Create a phpbb_datetime object in the context of the current user
*
* @since 3.1
* @param string $time String in a format accepted by strtotime().
* @param DateTimeZone $timezone Time zone of the time.
* @return phpbb_datetime Date time object linked to the current users locale
*/
public function create_datetime($time = 'now', DateTimeZone $timezone = null)
{
$timezone = $timezone ?: $this->tz;
return new phpbb_datetime($time, $timezone, $this);
}
/**

View file

@ -110,11 +110,12 @@ $legend = implode(', ', $legend);
$birthday_list = array();
if ($config['load_birthdays'] && $config['allow_birthdays'] && $auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'))
{
$now = phpbb_gmgetdate(time() + $user->timezone + $user->dst);
$time = $user->create_datetime();
$now = phpbb_gmgetdate($time->getTimestamp() + $time->getOffset());
// Display birthdays of 29th february on 28th february in non-leap-years
$leap_year_birthdays = '';
if ($now['mday'] == 28 && $now['mon'] == 2 && !$user->format_date(time(), 'L'))
if ($now['mday'] == 28 && $now['mon'] == 2 && !$time->format('L'))
{
$leap_year_birthdays = " OR u.user_birthday LIKE '" . $db->sql_escape(sprintf('%2d-%2d-', 29, 2)) . "%'";
}

View file

@ -1109,6 +1109,9 @@ function database_update_info()
GROUPS_TABLE => array(
'group_legend' => array('UINT', 0),
),
USERS_TABLE => array(
'user_timezone' => array('VCHAR:100', ''),
),
),
),
);

View file

@ -1242,8 +1242,7 @@ CREATE TABLE phpbb_users (
user_inactive_time INTEGER DEFAULT 0 NOT NULL,
user_posts INTEGER DEFAULT 0 NOT NULL,
user_lang VARCHAR(30) CHARACTER SET NONE DEFAULT '' NOT NULL,
user_timezone DOUBLE PRECISION DEFAULT 0 NOT NULL,
user_dst INTEGER DEFAULT 0 NOT NULL,
user_timezone VARCHAR(100) CHARACTER SET NONE DEFAULT 'UTC' NOT NULL,
user_dateformat VARCHAR(30) CHARACTER SET UTF8 DEFAULT 'd M Y H:i' NOT NULL COLLATE UNICODE,
user_style INTEGER DEFAULT 0 NOT NULL,
user_rank INTEGER DEFAULT 0 NOT NULL,

View file

@ -1526,8 +1526,7 @@ CREATE TABLE [phpbb_users] (
[user_inactive_time] [int] DEFAULT (0) NOT NULL ,
[user_posts] [int] DEFAULT (0) NOT NULL ,
[user_lang] [varchar] (30) DEFAULT ('') NOT NULL ,
[user_timezone] [float] DEFAULT (0) NOT NULL ,
[user_dst] [int] DEFAULT (0) NOT NULL ,
[user_timezone] [varchar] (100) DEFAULT ('UTC') NOT NULL ,
[user_dateformat] [varchar] (30) DEFAULT ('d M Y H:i') NOT NULL ,
[user_style] [int] DEFAULT (0) NOT NULL ,
[user_rank] [int] DEFAULT (0) NOT NULL ,

View file

@ -890,8 +890,7 @@ CREATE TABLE phpbb_users (
user_inactive_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
user_posts mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_lang varbinary(30) DEFAULT '' NOT NULL,
user_timezone decimal(5,2) DEFAULT '0' NOT NULL,
user_dst tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
user_timezone varbinary(100) DEFAULT 'UTC' NOT NULL,
user_dateformat varbinary(90) DEFAULT 'd M Y H:i' NOT NULL,
user_style mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,

View file

@ -890,8 +890,7 @@ CREATE TABLE phpbb_users (
user_inactive_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
user_posts mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_lang varchar(30) DEFAULT '' NOT NULL,
user_timezone decimal(5,2) DEFAULT '0' NOT NULL,
user_dst tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
user_timezone varchar(100) DEFAULT 'UTC' NOT NULL,
user_dateformat varchar(30) DEFAULT 'd M Y H:i' NOT NULL,
user_style mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,

View file

@ -1638,8 +1638,7 @@ CREATE TABLE phpbb_users (
user_inactive_time number(11) DEFAULT '0' NOT NULL,
user_posts number(8) DEFAULT '0' NOT NULL,
user_lang varchar2(30) DEFAULT '' ,
user_timezone number(5, 2) DEFAULT '0' NOT NULL,
user_dst number(1) DEFAULT '0' NOT NULL,
user_timezone varchar2(100) DEFAULT 'UTC' NOT NULL,
user_dateformat varchar2(90) DEFAULT 'd M Y H:i' NOT NULL,
user_style number(8) DEFAULT '0' NOT NULL,
user_rank number(8) DEFAULT '0' NOT NULL,

View file

@ -1140,8 +1140,7 @@ CREATE TABLE phpbb_users (
user_inactive_time INT4 DEFAULT '0' NOT NULL CHECK (user_inactive_time >= 0),
user_posts INT4 DEFAULT '0' NOT NULL CHECK (user_posts >= 0),
user_lang varchar(30) DEFAULT '' NOT NULL,
user_timezone decimal(5,2) DEFAULT '0' NOT NULL,
user_dst INT2 DEFAULT '0' NOT NULL CHECK (user_dst >= 0),
user_timezone varchar(100) DEFAULT 'UTC' NOT NULL,
user_dateformat varchar(30) DEFAULT 'd M Y H:i' NOT NULL,
user_style INT4 DEFAULT '0' NOT NULL CHECK (user_style >= 0),
user_rank INT4 DEFAULT '0' NOT NULL CHECK (user_rank >= 0),

View file

@ -864,8 +864,7 @@ CREATE TABLE phpbb_users (
user_inactive_time INTEGER UNSIGNED NOT NULL DEFAULT '0',
user_posts INTEGER UNSIGNED NOT NULL DEFAULT '0',
user_lang varchar(30) NOT NULL DEFAULT '',
user_timezone decimal(5,2) NOT NULL DEFAULT '0',
user_dst INTEGER UNSIGNED NOT NULL DEFAULT '0',
user_timezone varchar(100) NOT NULL DEFAULT 'UTC',
user_dateformat varchar(30) NOT NULL DEFAULT 'd M Y H:i',
user_style INTEGER UNSIGNED NOT NULL DEFAULT '0',
user_rank INTEGER UNSIGNED NOT NULL DEFAULT '0',

View file

@ -50,7 +50,6 @@ $lang = array_merge($lang, array(
'OVERRIDE_STYLE_EXPLAIN' => 'Replaces users style with the default.',
'SITE_DESC' => 'Site description',
'SITE_NAME' => 'Site name',
'SYSTEM_DST' => 'Enable Summer Time/<abbr title="Daylight Saving Time">DST</abbr>',
'SYSTEM_TIMEZONE' => 'Guest timezone',
'SYSTEM_TIMEZONE_EXPLAIN' => 'Timezone to use for displaying times to users who are not logged in (guests, bots). Logged in users set their timezone during registration and can change it in their user control panel.',
'WARNINGS_EXPIRE' => 'Warning duration',

View file

@ -835,93 +835,6 @@ $lang = array_merge($lang, array(
'Dec' => 'Dec',
),
'tz' => array(
'-12' => 'UTC - 12 hours',
'-11' => 'UTC - 11 hours',
'-10' => 'UTC - 10 hours',
'-9.5' => 'UTC - 9:30 hours',
'-9' => 'UTC - 9 hours',
'-8' => 'UTC - 8 hours',
'-7' => 'UTC - 7 hours',
'-6' => 'UTC - 6 hours',
'-5' => 'UTC - 5 hours',
'-4.5' => 'UTC - 4:30 hours',
'-4' => 'UTC - 4 hours',
'-3.5' => 'UTC - 3:30 hours',
'-3' => 'UTC - 3 hours',
'-2' => 'UTC - 2 hours',
'-1' => 'UTC - 1 hour',
'0' => 'UTC',
'1' => 'UTC + 1 hour',
'2' => 'UTC + 2 hours',
'3' => 'UTC + 3 hours',
'3.5' => 'UTC + 3:30 hours',
'4' => 'UTC + 4 hours',
'4.5' => 'UTC + 4:30 hours',
'5' => 'UTC + 5 hours',
'5.5' => 'UTC + 5:30 hours',
'5.75' => 'UTC + 5:45 hours',
'6' => 'UTC + 6 hours',
'6.5' => 'UTC + 6:30 hours',
'7' => 'UTC + 7 hours',
'8' => 'UTC + 8 hours',
'8.75' => 'UTC + 8:45 hours',
'9' => 'UTC + 9 hours',
'9.5' => 'UTC + 9:30 hours',
'10' => 'UTC + 10 hours',
'10.5' => 'UTC + 10:30 hours',
'11' => 'UTC + 11 hours',
'11.5' => 'UTC + 11:30 hours',
'12' => 'UTC + 12 hours',
'12.75' => 'UTC + 12:45 hours',
'13' => 'UTC + 13 hours',
'14' => 'UTC + 14 hours',
'dst' => '[ <abbr title="Daylight Saving Time">DST</abbr> ]',
),
'tz_zones' => array(
'-12' => '[UTC - 12] Baker Island Time',
'-11' => '[UTC - 11] Niue Time, Samoa Standard Time',
'-10' => '[UTC - 10] Hawaii-Aleutian Standard Time, Cook Island Time',
'-9.5' => '[UTC - 9:30] Marquesas Islands Time',
'-9' => '[UTC - 9] Alaska Standard Time, Gambier Island Time',
'-8' => '[UTC - 8] Pacific Standard Time',
'-7' => '[UTC - 7] Mountain Standard Time',
'-6' => '[UTC - 6] Central Standard Time',
'-5' => '[UTC - 5] Eastern Standard Time',
'-4.5' => '[UTC - 4:30] Venezuelan Standard Time',
'-4' => '[UTC - 4] Atlantic Standard Time',
'-3.5' => '[UTC - 3:30] Newfoundland Standard Time',
'-3' => '[UTC - 3] Amazon Standard Time, Central Greenland Time',
'-2' => '[UTC - 2] Fernando de Noronha Time, South Georgia &amp; the South Sandwich Islands Time',
'-1' => '[UTC - 1] Azores Standard Time, Cape Verde Time, Eastern Greenland Time',
'0' => '[UTC] Western European Time, Greenwich Mean Time',
'1' => '[UTC + 1] Central European Time, West African Time',
'2' => '[UTC + 2] Eastern European Time, Central African Time',
'3' => '[UTC + 3] Moscow Standard Time, Eastern African Time',
'3.5' => '[UTC + 3:30] Iran Standard Time',
'4' => '[UTC + 4] Gulf Standard Time, Samara Standard Time',
'4.5' => '[UTC + 4:30] Afghanistan Time',
'5' => '[UTC + 5] Pakistan Standard Time, Yekaterinburg Standard Time',
'5.5' => '[UTC + 5:30] Indian Standard Time, Sri Lanka Time',
'5.75' => '[UTC + 5:45] Nepal Time',
'6' => '[UTC + 6] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time',
'6.5' => '[UTC + 6:30] Cocos Islands Time, Myanmar Time',
'7' => '[UTC + 7] Indochina Time, Krasnoyarsk Standard Time',
'8' => '[UTC + 8] Chinese Standard Time, Australian Western Standard Time, Irkutsk Standard Time',
'8.75' => '[UTC + 8:45] Southeastern Western Australia Standard Time',
'9' => '[UTC + 9] Japan Standard Time, Korea Standard Time, Chita Standard Time',
'9.5' => '[UTC + 9:30] Australian Central Standard Time',
'10' => '[UTC + 10] Australian Eastern Standard Time, Vladivostok Standard Time',
'10.5' => '[UTC + 10:30] Lord Howe Standard Time',
'11' => '[UTC + 11] Solomon Island Time, Magadan Standard Time',
'11.5' => '[UTC + 11:30] Norfolk Island Time',
'12' => '[UTC + 12] New Zealand Time, Fiji Time, Kamchatka Standard Time',
'12.75' => '[UTC + 12:45] Chatham Islands Time',
'13' => '[UTC + 13] Tonga Time, Phoenix Islands Time',
'14' => '[UTC + 14] Line Island Time',
),
// The value is only an example and will get replaced by the current time on view
'dateformats' => array(
'd M Y, H:i' => '01 Jan 2007, 13:37',

View file

@ -87,7 +87,7 @@ $help = array(
),
array(
0 => 'I changed the timezone and the time is still wrong!',
1 => 'If you are sure you have set the timezone and Summer Time/DST correctly and the time is still incorrect, then the time stored on the server clock is incorrect. Please notify an administrator to correct the problem.'
1 => 'If you are sure you have set the timezone correctly and the time is still incorrect, then the time stored on the server clock is incorrect. Please notify an administrator to correct the problem.'
),
array(
0 => 'My language is not in the list!',

View file

@ -102,7 +102,6 @@ $lang = array_merge($lang, array(
'BIRTHDAY_EXPLAIN' => 'Setting a year will list your age when it is your birthday.',
'BOARD_DATE_FORMAT' => 'My date format',
'BOARD_DATE_FORMAT_EXPLAIN' => 'The syntax used is identical to the PHP <a href="http://www.php.net/date">date()</a> function.',
'BOARD_DST' => 'Summer Time/<abbr title="Daylight Saving Time">DST</abbr> is in effect',
'BOARD_LANGUAGE' => 'My language',
'BOARD_STYLE' => 'My board style',
'BOARD_TIMEZONE' => 'My timezone',
@ -413,6 +412,7 @@ $lang = array_merge($lang, array(
'SIGNATURE_EXPLAIN' => 'This is a block of text that can be added to posts you make. There is a %d character limit.',
'SIGNATURE_PREVIEW' => 'Your signature will appear like this in posts',
'SIGNATURE_TOO_LONG' => 'Your signature is too long.',
'SELECT_TIMEZONE' => 'Select timezone',
'SORT' => 'Sort',
'SORT_COMMENT' => 'File comment',
'SORT_DOWNLOADS' => 'Downloads',

View file

@ -1674,7 +1674,8 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f
if ($bday_year)
{
$now = phpbb_gmgetdate(time() + $user->timezone + $user->dst);
$now = $user->create_datetime();
$now = phpbb_gmgetdate($now->getTimestamp() + $now->getOffset());
$diff = $now['mon'] - $bday_month;
if ($diff == 0)

View file

@ -0,0 +1,54 @@
function phpbb_preselect_tz_select()
{
var selector = document.getElementsByClassName('tz_select')[0];
if (selector.value)
{
return;
}
// The offset returned here is in minutes and negated.
// http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp
var offset = (new Date()).getTimezoneOffset();
if (offset < 0)
{
var sign = '+';
offset = -offset;
}
else
{
var sign = '-';
}
var minutes = offset % 60;
var hours = (offset - minutes) / 60;
if (hours < 10)
{
hours = '0' + hours.toString();
}
else
{
hours = hours.toString();
}
if (minutes < 10)
{
minutes = '0' + minutes.toString();
}
else
{
minutes = minutes.toString();
}
var prefix = 'GMT' + sign + hours + ':' + minutes;
var prefix_length = prefix.length;
for (var i = 0; i < selector.options.length; ++i)
{
var option = selector.options[i];
if (option.value.substring(0, prefix_length) == prefix)
{
// Firefox scrolls the selector only to put the option into view;
// for negative-offset timezones, this means the first timezone
// of a particular offset will be the bottom one, and selected,
// with all other timezones not visible. Not much can be done
// about that here unfortunately.
option.selected = true;
break;
}
}
}

View file

@ -75,13 +75,11 @@
<!-- ENDIF -->
<dl>
<dt><label for="timezone">{L_BOARD_TIMEZONE}:</label></dt>
<dd><select name="tz" id="timezone" class="autowidth">{S_TZ_OPTIONS}</select></dd>
</dl>
<dl>
<dt><label for="dst1">{L_BOARD_DST}:</label></dt>
<dd>
<label for="dst1"><input type="radio" name="dst" id="dst1" value="1"<!-- IF S_DST --> checked="checked"<!-- ENDIF --> /> {L_YES}</label>
<label for="dst0"><input type="radio" name="dst" id="dst0" value="0"<!-- IF not S_DST --> checked="checked"<!-- ENDIF --> /> {L_NO}</label>
<select name="tz" id="timezone" class="autowidth tz_select">
<option value="">{L_SELECT_TIMEZONE}</option>
{S_TZ_OPTIONS}
</select>
</dd>
</dl>
<dl>
@ -141,4 +139,7 @@
// ]]>
</script>
<script type="text/javascript" src="{T_SUPER_TEMPLATE_PATH}/timezone.js"></script>
<script type="text/javascript">phpbb_preselect_tz_select();</script>
<!-- INCLUDE ucp_footer.html -->

View file

@ -55,7 +55,12 @@
</dl>
<dl>
<dt><label for="tz">{L_TIMEZONE}:</label></dt>
<dd><select name="tz" id="tz" tabindex="7" class="autowidth">{S_TZ_OPTIONS}</select></dd>
<dd>
<select name="tz" id="tz" tabindex="7" class="autowidth tz_select">
<option value="">{L_SELECT_TIMEZONE}</option>
{S_TZ_OPTIONS}
</select>
</dd>
</dl>
<!-- IF .profile_fields -->
@ -106,4 +111,7 @@
</div>
</form>
<script type="text/javascript" src="{T_SUPER_TEMPLATE_PATH}/timezone.js"></script>
<script type="text/javascript">phpbb_preselect_tz_select();</script>
<!-- INCLUDE overall_footer.html -->

View file

@ -77,10 +77,6 @@
<select id="tz" name="tz">{S_TZ_OPTIONS}</select>
</td>
</tr>
<tr>
<td class="row1" width="50%"><b class="genmed">{L_BOARD_DST}:</b></td>
<td class="row2"><input type="radio" class="radio" name="dst" value="1"<!-- IF S_DST --> checked="checked"<!-- ENDIF --> /> <span class="genmed">{L_YES}</span>&nbsp;&nbsp;<input type="radio" class="radio" name="dst" value="0"<!-- IF not S_DST --> checked="checked"<!-- ENDIF --> /> <span class="genmed">{L_NO}</span></td>
</tr>
<tr>
<td class="row1" width="50%"><b class="genmed">{L_BOARD_DATE_FORMAT}:</b><br /><span class="gensmall">{L_BOARD_DATE_FORMAT_EXPLAIN}</span></td>
<td class="row2">

View file

@ -986,7 +986,8 @@ $sql_ary = array(
$sql = $db->sql_build_query('SELECT', $sql_ary);
$result = $db->sql_query($sql);
$now = phpbb_gmgetdate(time() + $user->timezone + $user->dst);
$now = $user->create_datetime();
$now = phpbb_gmgetdate($now->getTimestamp() + $now->getOffset());
// Posts are stored in the $rowset array while $attach_list, $user_cache
// and the global bbcode_bitfield are built