diff options
author | Nils Adermann <naderman@naderman.de> | 2012-07-19 08:46:25 -0700 |
---|---|---|
committer | Nils Adermann <naderman@naderman.de> | 2012-07-19 08:46:25 -0700 |
commit | 737828f00911ba145697ef4060401e50e5b711af (patch) | |
tree | 4ec7097ac7c5ffeb3b00c62d09ce9d5955a5c5d8 | |
parent | c896cd06dd8fba023e2ab6f9cd3f8293d382fb70 (diff) | |
parent | 7df1c84447903ecc97a8418339ec6933bdfc9035 (diff) | |
download | forums-737828f00911ba145697ef4060401e50e5b711af.tar forums-737828f00911ba145697ef4060401e50e5b711af.tar.gz forums-737828f00911ba145697ef4060401e50e5b711af.tar.bz2 forums-737828f00911ba145697ef4060401e50e5b711af.tar.xz forums-737828f00911ba145697ef4060401e50e5b711af.zip |
Merge pull request #843 from nickvergessen/feature/new-tz-handling
Feature/new tz handling
48 files changed, 934 insertions, 280 deletions
diff --git a/phpBB/adm/style/acp_users_prefs.html b/phpBB/adm/style/acp_users_prefs.html index a519447b2f..9439f0cf03 100644 --- a/phpBB/adm/style/acp_users_prefs.html +++ b/phpBB/adm/style/acp_users_prefs.html @@ -52,15 +52,7 @@ <dt><label for="style">{L_BOARD_STYLE}:</label></dt> <dd><select id="style" name="style">{S_STYLE_OPTIONS}</select></dd> </dl> - <dl> - <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> + <!-- INCLUDE timezone_option.html --> <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> diff --git a/phpBB/adm/style/timezone.js b/phpBB/adm/style/timezone.js new file mode 100644 index 0000000000..4556ea5f94 --- /dev/null +++ b/phpBB/adm/style/timezone.js @@ -0,0 +1,11 @@ +(function($) { // Avoid conflicts with other libraries + +$('#tz_date').change(function() { + phpbb.timezone_switch_date(false); +}); + +$(document).ready( + phpbb.timezone_enable_date_selection +); + +})(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/adm/style/timezone_option.html b/phpBB/adm/style/timezone_option.html new file mode 100644 index 0000000000..23c0ee19e9 --- /dev/null +++ b/phpBB/adm/style/timezone_option.html @@ -0,0 +1,19 @@ +<dl> + <dt><label for="timezone">{L_BOARD_TIMEZONE}:</label></dt> + <!-- IF S_TZ_DATE_OPTIONS --> + <dd id="tz_select_date" style="display: none;"> + <select name="tz_date" id="tz_date" class="autowidth tz_select"> + <option value="">{L_SELECT_CURRENT_TIME}</option> + {S_TZ_DATE_OPTIONS} + </select> + </dd> + <!-- ENDIF --> + <dd> + <select name="tz" id="timezone" class="autowidth tz_select"> + <option value="">{L_SELECT_TIMEZONE}</option> + {S_TZ_OPTIONS} + </select> + + <!-- INCLUDEJS timezone.js --> + </dd> +</dl> diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 76615eb051..c40852388e 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -411,6 +411,99 @@ phpbb.ajaxify = function(options) { return this; } +/** +* Hide the optgroups that are not the selected timezone +* +* @param bool keep_selection Shall we keep the value selected, or shall the user be forced to repick one. +*/ +phpbb.timezone_switch_date = function(keep_selection) { + $('#timezone > optgroup').css('display', 'none'); + $("#timezone > optgroup[label='" + $('#tz_date').val() + "']").css('display', 'block'); + + if ($('#tz_date').val() == $('#tz_select_date_suggest').attr('data-suggested-tz')) { + $('#tz_select_date_suggest').css('display', 'none'); + } else { + $('#tz_select_date_suggest').css('display', 'inline'); + } + + if ($("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option").size() == 1) { + // If there is only one timezone for the selected date, we just select that automatically. + $("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option:first").attr('selected', true); + keep_selection = true; + } + + if (typeof keep_selection !== 'undefined' && !keep_selection) { + $('#timezone > option:first').attr('selected', true); + } +} + +/** +* Display the date/time select +*/ +phpbb.timezone_enable_date_selection = function() { + $('#tz_select_date').css('display', 'block'); +} + +/** +* Preselect a date/time or suggest one, if it is not picked. +* +* @param bool force_selector Shall we select the suggestion? +*/ +phpbb.timezone_preselect_select = function(force_selector) { + + // 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; + var selector_options = $('#tz_date > option'); + + for (var i = 0; i < selector_options.length; ++i) { + var option = selector_options[i]; + + if (option.value.substring(0, prefix_length) == prefix) { + if ($('#tz_date').val() != option.value && !force_selector) { + // We do not select the option for the user, but notify him, + // that we would suggest a different setting. + $('#tz_select_date_suggest').css('display', 'inline'); + $('#tz_select_date_suggest').attr('title', $('#tz_select_date_suggest').attr('data-l-suggestion').replace("%s", option.innerHTML)); + $('#tz_select_date_suggest').attr('value', $('#tz_select_date_suggest').attr('data-l-suggestion').replace("%s", option.innerHTML.substring(0, 9))); + $('#tz_select_date_suggest').attr('data-suggested-tz', option.innerHTML); + phpbb.timezone_switch_date(true); + } else { + option.selected = true; + phpbb.timezone_switch_date(!force_selector); + $('#tz_select_date_suggest').attr('data-suggested-tz', option.innerHTML); + $('#tz_select_date_suggest').css('display', 'none'); + } + break; + } + } +} + phpbb.ajax_callbacks = {}; /** diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 0193e57f23..6825ba1bf6 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -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), diff --git a/phpBB/develop/mysql_upgrader.php b/phpBB/develop/mysql_upgrader.php index 0498f826ab..7f82ebfeab 100644 --- a/phpBB/develop/mysql_upgrader.php +++ b/phpBB/develop/mysql_upgrader.php @@ -1229,8 +1229,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), diff --git a/phpBB/develop/repair_bots.php b/phpBB/develop/repair_bots.php index 790d3d9f2f..2c6e9ce091 100644 --- a/phpBB/develop/repair_bots.php +++ b/phpBB/develop/repair_bots.php @@ -128,7 +128,7 @@ function add_bots($bots) 'user_email' => '', 'user_lang' => $config['default_lang'], 'user_style' => 1, - 'user_timezone' => 0, + 'user_timezone' => 'UTC', 'user_allow_massemail' => 0, ); diff --git a/phpBB/feed.php b/phpBB/feed.php index fcf42a83ae..9b7ef3a575 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -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; diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index d537885ef1..575d05933f 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -57,8 +57,7 @@ class acp_board 'board_disable_msg' => false, 'default_lang' => array('lang' => 'DEFAULT_LANGUAGE', 'validate' => 'lang', 'type' => 'select', 'function' => 'language_select', 'params' => array('{CONFIG_VALUE}'), 'explain' => false), 'default_dateformat' => array('lang' => 'DEFAULT_DATE_FORMAT', 'validate' => 'string', 'type' => 'custom', 'method' => 'dateformat_select', 'explain' => true), - 'board_timezone' => array('lang' => 'SYSTEM_TIMEZONE', 'validate' => 'string', 'type' => 'select', 'function' => 'tz_select', 'params' => array('{CONFIG_VALUE}', 1), 'explain' => true), - 'board_dst' => array('lang' => 'SYSTEM_DST', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), + 'board_timezone' => array('lang' => 'SYSTEM_TIMEZONE', 'validate' => 'timezone', 'type' => 'custom', 'method' => 'timezone_select', 'explain' => true), 'default_style' => array('lang' => 'DEFAULT_STYLE', 'validate' => 'int', 'type' => 'select', 'function' => 'style_select', 'params' => array('{CONFIG_VALUE}', false), 'explain' => false), 'override_user_style' => array('lang' => 'OVERRIDE_STYLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), @@ -897,6 +896,18 @@ class acp_board '<br /><br /><input class="button2" type="submit" id="' . $key . '_enable" name="' . $key . '_enable" value="' . $user->lang['ALLOW_QUICK_REPLY_BUTTON'] . '" />'; } + /** + * Select guest timezone + */ + function timezone_select($value, $key) + { + global $user; + + $timezone_select = phpbb_timezone_select($user, $value, true); + $timezone_select['tz_select']; + + return '<select name="config[' . $key . ']" id="' . $key . '">' . $timezone_select['tz_select'] . '</select>'; + } /** * Select default dateformat @@ -907,10 +918,14 @@ class acp_board // Let the format_date function operate with the acp values $old_tz = $user->timezone; - $old_dst = $user->dst; - - $user->timezone = $config['board_timezone'] * 3600; - $user->dst = $config['board_dst'] * 3600; + try + { + $user->timezone = new DateTimeZone($config['board_timezone']); + } + catch (Exception $e) + { + // If the board timezone is invalid, we just use the users timezone. + } $dateformat_options = ''; @@ -930,7 +945,6 @@ class acp_board // Reset users date options $user->timezone = $old_tz; - $user->dst = $old_dst; return "<select name=\"dateoptions\" id=\"dateoptions\" onchange=\"if (this.value == 'custom') { document.getElementById('" . addslashes($key) . "').value = '" . addslashes($value) . "'; } else { document.getElementById('" . addslashes($key) . "').value = this.value; }\">$dateformat_options</select> <input type=\"text\" name=\"config[$key]\" id=\"$key\" value=\"$value\" maxlength=\"30\" />"; diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 1f827d00aa..79c91dd7ee 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1460,9 +1460,8 @@ class acp_users $data = array( 'dateformat' => utf8_normalize_nfc(request_var('dateformat', $user_row['user_dateformat'], true)), 'lang' => basename(request_var('lang', $user_row['user_lang'])), - 'tz' => request_var('tz', (float) $user_row['user_timezone']), + 'tz' => request_var('tz', $user_row['user_timezone']), 'style' => request_var('style', $user_row['user_style']), - 'dst' => request_var('dst', $user_row['user_dst']), 'viewemail' => request_var('viewemail', $user_row['user_allow_viewemail']), 'massemail' => request_var('massemail', $user_row['user_allow_massemail']), 'hideonline' => request_var('hideonline', !$user_row['user_allow_viewonline']), @@ -1497,7 +1496,7 @@ class acp_users $error = validate_data($data, array( 'dateformat' => array('string', false, 1, 30), 'lang' => array('match', false, '#^[a-z_\-]{2,}$#i'), - 'tz' => array('num', false, -14, 14), + 'tz' => array('timezone'), 'topic_sk' => array('string', false, 1, 1), 'topic_sd' => array('string', false, 1, 1), @@ -1533,7 +1532,6 @@ class acp_users 'user_notify_type' => $data['notifymethod'], 'user_notify_pm' => $data['notifypm'], - 'user_dst' => $data['dst'], 'user_dateformat' => $data['dateformat'], 'user_lang' => $data['lang'], 'user_timezone' => $data['tz'], @@ -1643,6 +1641,7 @@ class acp_users ${'s_sort_' . $sort_option . '_dir'} .= '</select>'; } + $timezone_selects = phpbb_timezone_select($user, $data['tz'], true); $template->assign_vars(array( 'S_PREFS' => true, 'S_JABBER_DISABLED' => ($config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml')) ? false : true, @@ -1656,7 +1655,6 @@ class acp_users 'NOTIFY_BOTH' => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false, 'NOTIFY_PM' => $data['notifypm'], 'POPUP_PM' => $data['popuppm'], - 'DST' => $data['dst'], 'BBCODE' => $data['bbcode'], 'SMILIES' => $data['smilies'], 'ATTACH_SIG' => $data['sig'], @@ -1683,7 +1681,8 @@ class acp_users 'S_LANG_OPTIONS' => language_select($data['lang']), 'S_STYLE_OPTIONS' => style_select($data['style']), - 'S_TZ_OPTIONS' => tz_select($data['tz'], true), + 'S_TZ_OPTIONS' => $timezone_selects['tz_select'], + 'S_TZ_DATE_OPTIONS' => $timezone_selects['tz_dates'], ) ); diff --git a/phpBB/includes/datetime.php b/phpBB/includes/datetime.php new file mode 100644 index 0000000000..b3462ddf67 --- /dev/null +++ b/phpBB/includes/datetime.php @@ -0,0 +1,158 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +*/ + +/** +* 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($user, $time = 'now', DateTimeZone $timezone = null) + { + $this->user = $user; + $timezone = $timezone ?: $this->user->timezone; + + parent::__construct($time, $timezone); + } + + /** + * 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($this->user, 'now', $this->user->timezone); + + $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]; + } +} diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 633ac3d307..e5b721b1f5 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1069,32 +1069,209 @@ function style_select($default = '', $all = false) } /** +* Format the timezone offset with hours and minutes +* +* @param int $tz_offset Timezone offset in seconds +* @return string Normalized offset string: -7200 => -02:00 +* 16200 => +04:30 +*/ +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 phpbb_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; + } + } +} + +/** +* Return list of timezone identifiers +* We also add the selected timezone if we can create an object with it. +* DateTimeZone::listIdentifiers seems to not add all identifiers to the list, +* because some are only kept for backward compatible reasons. If the user has +* a deprecated value, we add it here, so it can still be kept. Once the user +* changed his value, there is no way back to deprecated values. +* +* @param string $selected_timezone Additional timezone that shall +* be added to the list of identiers +* @return array DateTimeZone::listIdentifiers and additional +* selected_timezone if it is a valid timezone. +*/ +function phpbb_get_timezone_identifiers($selected_timezone) +{ + $timezones = DateTimeZone::listIdentifiers(); + + if (!in_array($selected_timezone, $timezones)) + { + try + { + // Add valid timezones that are currently selected but not returned + // by DateTimeZone::listIdentifiers + $validate_timezone = new DateTimeZone($selected_timezone); + $timezones[] = $selected_timezone; + } + catch (Exception $e) + { + } + } + + return $timezones; +} + +/** * Pick a timezone +* +* @param string $default A timezone to select +* @param boolean $truncate Shall we truncate the options text +* +* @return string Returns the options for timezone selector only +* +* @deprecated */ function tz_select($default = '', $truncate = false) { global $user; - $tz_select = ''; - foreach ($user->lang['tz_zones'] as $offset => $zone) + $timezone_select = phpbb_timezone_select($user, $default, $truncate); + return $timezone_select['tz_select']; +} + +/** +* Options to pick a timezone and date/time +* +* @param phpbb_user $user Object of the current user +* @param string $default A timezone to select +* @param boolean $truncate Shall we truncate the options text +* +* @return array Returns an array, also containing the options for the time selector. +*/ +function phpbb_timezone_select($user, $default = '', $truncate = false) +{ + static $timezones; + + $default_offset = ''; + if (!isset($timezones)) { - if ($truncate) + $unsorted_timezones = phpbb_get_timezone_identifiers($default); + + $timezones = array(); + foreach ($unsorted_timezones as $timezone) { - $zone_trunc = truncate_string($zone, 50, 255, false, '...'); + $tz = new DateTimeZone($timezone); + $dt = new phpbb_datetime($user, 'now', $tz); + $offset = $dt->getOffset(); + $current_time = $dt->format($user->lang['DATETIME_FORMAT'], true); + $offset_string = phpbb_format_timezone_offset($offset); + $timezones['GMT' . $offset_string . ' - ' . $timezone] = array( + 'tz' => $timezone, + 'offest' => 'GMT' . $offset_string, + 'current' => $current_time, + ); + if ($timezone === $default) + { + $default_offset = 'GMT' . $offset_string; + } + } + unset($unsorted_timezones); + + uksort($timezones, 'phpbb_tz_select_compare'); + } + + $tz_select = $tz_dates = $opt_group = ''; + + foreach ($timezones as $timezone) + { + if ($opt_group != $timezone['offest']) + { + $tz_select .= ($opt_group) ? '</optgroup>' : ''; + $tz_select .= '<optgroup label="' . $timezone['offest'] . ' - ' . $timezone['current'] . '">'; + $opt_group = $timezone['offest']; + + $selected = ($default_offset == $timezone['offest']) ? ' selected="selected"' : ''; + $tz_dates .= '<option value="' . $timezone['offest'] . ' - ' . $timezone['current'] . '"' . $selected . '>' . $timezone['offest'] . ' - ' . $timezone['current'] . '</option>'; + } + + if (isset($user->lang['timezones'][$timezone['tz']])) + { + $title = $label = $user->lang['timezones'][$timezone['tz']]; } else { - $zone_trunc = $zone; + // No label, we'll figure one out + $bits = explode('/', str_replace('_', ' ', $timezone['tz'])); + + $label = implode(' - ', $bits); + $title = $timezone['offest'] . ' - ' . $label; } - 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['tz'] === $default) ? ' selected="selected"' : ''; + $tz_select .= '<option title="' . $title . '" value="' . $timezone['tz'] . '"' . $selected . '>' . $label . '</option>'; } + $tz_select .= '</optgroup>'; - return $tz_select; + return array( + 'tz_select' => $tz_select, + 'tz_dates' => $tz_dates, + ); } // Functions handling topic/post tracking/marking @@ -4701,9 +4878,6 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 $board_url = generate_board_url() . '/'; $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $phpbb_root_path; - // Which timezone? - $tz = ($user->data['user_id'] != ANONYMOUS) ? strval(doubleval($user->data['user_timezone'])) : strval(doubleval($config['board_timezone'])); - // Send a proper content-language to the output $user_lang = $user->lang['USER_LANG']; if (strpos($user_lang, '-x-') !== false) @@ -4726,6 +4900,14 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 } } + $dt = new phpbb_datetime($user, 'now', $user->timezone); + $timezone_offset = 'GMT' . phpbb_format_timezone_offset($dt->getOffset()); + $timezone_name = $user->timezone->getName(); + if (isset($user->lang['timezones'][$timezone_name])) + { + $timezone_name = $user->lang['timezones'][$timezone_name]; + } + // The following assigns all _common_ variables that may be used at any point in a template. $template->assign_vars(array( 'SITENAME' => $config['sitename'], @@ -4793,7 +4975,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'S_CONTENT_FLOW_BEGIN' => ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right', 'S_CONTENT_FLOW_END' => ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left', 'S_CONTENT_ENCODING' => 'UTF-8', - 'S_TIMEZONE' => ($user->data['user_dst'] || ($user->data['user_id'] == ANONYMOUS && $config['board_dst'])) ? sprintf($user->lang['ALL_TIMES'], $user->lang['tz'][$tz], $user->lang['tz']['dst']) : sprintf($user->lang['ALL_TIMES'], $user->lang['tz'][$tz], ''), + 'S_TIMEZONE' => sprintf($user->lang['ALL_TIMES'], $timezone_offset, $timezone_name), 'S_DISPLAY_ONLINE_LIST' => ($l_online_time) ? 1 : 0, 'S_DISPLAY_SEARCH' => (!$config['load_search']) ? 0 : (isset($auth) ? ($auth->acl_get('u_search') && $auth->acl_getf_global('f_search')) : 1), 'S_DISPLAY_PM' => ($config['allow_privmsg'] && !empty($user->data['is_registered']) && ($auth->acl_get('u_readpm') || $auth->acl_get('u_sendpm'))) ? true : false, diff --git a/phpBB/includes/functions_convert.php b/phpBB/includes/functions_convert.php index e9ec153c50..ac791e0d9b 100644 --- a/phpBB/includes/functions_convert.php +++ b/phpBB/includes/functions_convert.php @@ -1884,7 +1884,7 @@ function add_bots() 'user_email' => '', 'user_lang' => $config['default_lang'], 'user_style' => 1, - 'user_timezone' => 0, + 'user_timezone' => 'UTC', 'user_allow_massemail' => 0, ); diff --git a/phpBB/includes/functions_profile_fields.php b/phpBB/includes/functions_profile_fields.php index 3399334f94..1c15ef897f 100644 --- a/phpBB/includes/functions_profile_fields.php +++ b/phpBB/includes/functions_profile_fields.php @@ -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; diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 9b102b7387..6e658b4ef4 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -197,7 +197,6 @@ function user_add($user_row, $cp_data = false) 'user_lastpost_time' => 0, 'user_lastpage' => '', 'user_posts' => 0, - 'user_dst' => (int) $config['board_dst'], 'user_colour' => '', 'user_occ' => '', 'user_interests' => '', @@ -677,8 +676,10 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reas if (sizeof($ban_other) == 3 && ((int)$ban_other[0] < 9999) && (strlen($ban_other[0]) == 4) && (strlen($ban_other[1]) == 2) && (strlen($ban_other[2]) == 2)) { - $time_offset = (isset($user->timezone) && isset($user->dst)) ? (int) $user->timezone + (int) $user->dst : 0; - $ban_end = max($current_time, gmmktime(0, 0, 0, (int)$ban_other[1], (int)$ban_other[2], (int)$ban_other[0]) - $time_offset); + $ban_end = max($current_time, $user->create_datetime() + ->setDate((int) $ban_other[0], (int) $ban_other[1], (int) $ban_other[2]) + ->setTime(0, 0, 0) + ->getTimestamp() + $user->timezone->getOffset(new DateTime('UTC'))); } else { @@ -1247,10 +1248,21 @@ function validate_data($data, $val_ary) $function = array_shift($validate); array_unshift($validate, $data[$var]); - if ($result = call_user_func_array('validate_' . $function, $validate)) + if (function_exists('phpbb_validate_' . $function)) { - // Since errors are checked later for their language file existence, we need to make sure custom errors are not adjusted. - $error[] = (empty($user->lang[$result . '_' . strtoupper($var)])) ? $result : $result . '_' . strtoupper($var); + if ($result = call_user_func_array('phpbb_validate_' . $function, $validate)) + { + // Since errors are checked later for their language file existence, we need to make sure custom errors are not adjusted. + $error[] = (empty($user->lang[$result . '_' . strtoupper($var)])) ? $result : $result . '_' . strtoupper($var); + } + } + else + { + if ($result = call_user_func_array('validate_' . $function, $validate)) + { + // Since errors are checked later for their language file existence, we need to make sure custom errors are not adjusted. + $error[] = (empty($user->lang[$result . '_' . strtoupper($var)])) ? $result : $result . '_' . strtoupper($var); + } } } } @@ -1396,6 +1408,22 @@ function validate_language_iso_name($lang_iso) } /** +* Validate Timezone Name +* +* Tests whether a timezone name is valid +* +* @param string $timezone The timezone string to test +* +* @return bool|string Either false if validation succeeded or +* a string which will be used as the error message +* (with the variable name appended) +*/ +function phpbb_validate_timezone($timezone) +{ + return (in_array($timezone, phpbb_get_timezone_identifiers($timezone))) ? false : 'TIMEZONE_INVALID'; +} + +/** * Check to see if the username has been taken, or if it is disallowed. * Also checks if it includes the " character, which we don't allow in usernames. * Used for registering, changing names, and posting anonymously with a username diff --git a/phpBB/includes/questionnaire/questionnaire.php b/phpBB/includes/questionnaire/questionnaire.php index 46a743d7e9..5cb441d536 100644 --- a/phpBB/includes/questionnaire/questionnaire.php +++ b/phpBB/includes/questionnaire/questionnaire.php @@ -304,7 +304,6 @@ class phpbb_questionnaire_phpbb_data_provider 'avatar_max_width' => true, 'avatar_min_height' => true, 'avatar_min_width' => true, - 'board_dst' => true, 'board_email_form' => true, 'board_hide_emails' => true, 'board_timezone' => true, diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 0c9f20f266..2228bc7931 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -41,9 +41,8 @@ class ucp_prefs 'dateformat' => request_var('dateformat', $user->data['user_dateformat'], true), 'lang' => basename(request_var('lang', $user->data['user_lang'])), 'style' => request_var('style', (int) $user->data['user_style']), - 'tz' => request_var('tz', (float) $user->data['user_timezone']), + 'tz' => request_var('tz', $user->data['user_timezone']), - 'dst' => request_var('dst', (bool) $user->data['user_dst']), 'viewemail' => request_var('viewemail', (bool) $user->data['user_allow_viewemail']), 'massemail' => request_var('massemail', (bool) $user->data['user_allow_massemail']), 'hideonline' => request_var('hideonline', (bool) !$user->data['user_allow_viewonline']), @@ -72,7 +71,7 @@ class ucp_prefs $error = validate_data($data, array( 'dateformat' => array('string', false, 1, 30), 'lang' => array('language_iso_name'), - 'tz' => array('num', false, -14, 14), + 'tz' => array('timezone'), )); if (!check_form_key('ucp_prefs_personal')) @@ -93,7 +92,6 @@ class ucp_prefs 'user_notify_pm' => $data['notifypm'], 'user_options' => $user->data['user_options'], - 'user_dst' => $data['dst'], 'user_dateformat' => $data['dateformat'], 'user_lang' => $data['lang'], 'user_timezone' => $data['tz'], @@ -133,6 +131,7 @@ class ucp_prefs } $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>'; + $timezone_selects = phpbb_timezone_select($user, $data['tz'], true); $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '', @@ -145,7 +144,6 @@ class ucp_prefs 'S_HIDE_ONLINE' => $data['hideonline'], 'S_NOTIFY_PM' => $data['notifypm'], 'S_POPUP_PM' => $data['popuppm'], - 'S_DST' => $data['dst'], 'DATE_FORMAT' => $data['dateformat'], 'A_DATE_FORMAT' => addslashes($data['dateformat']), @@ -156,7 +154,8 @@ class ucp_prefs 'S_LANG_OPTIONS' => language_select($data['lang']), 'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['style']), - 'S_TZ_OPTIONS' => tz_select($data['tz'], true), + 'S_TZ_OPTIONS' => $timezone_selects['tz_select'], + 'S_TZ_DATE_OPTIONS' => $timezone_selects['tz_dates'], 'S_CAN_HIDE_ONLINE' => ($auth->acl_get('u_hideonline')) ? true : false, 'S_SELECT_NOTIFY' => ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')) ? true : false) ); diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php index 5d85029e62..6ce53a79ab 100644 --- a/phpBB/includes/ucp/ucp_register.php +++ b/phpBB/includes/ucp/ucp_register.php @@ -100,7 +100,7 @@ class ucp_register 'username' => utf8_normalize_nfc(request_var('username', '', true)), 'email' => strtolower(request_var('email', '')), 'lang' => $user->lang_name, - 'tz' => request_var('tz', (float) $config['board_timezone']), + 'tz' => request_var('tz', $config['board_timezone']), )); } @@ -120,7 +120,10 @@ class ucp_register if ($coppa === false && $config['coppa_enable']) { $now = getdate(); - $coppa_birthday = $user->format_date(mktime($now['hours'] + $user->data['user_dst'], $now['minutes'], $now['seconds'], $now['mon'], $now['mday'] - 1, $now['year'] - 13), $user->lang['DATE_FORMAT']); + $coppa_birthday = $user->create_datetime() + ->setDate($now['year'] - 13, $now['mon'], $now['mday'] - 1) + ->setTime(0, 0, 0) + ->format($user->lang['DATE_FORMAT'], true); unset($now); $template->assign_vars(array( @@ -163,7 +166,6 @@ class ucp_register $captcha->init(CONFIRM_REG); } - $is_dst = $config['board_dst']; $timezone = $config['board_timezone']; $data = array( @@ -172,7 +174,7 @@ class ucp_register 'password_confirm' => request_var('password_confirm', '', true), 'email' => strtolower(request_var('email', '')), 'lang' => basename(request_var('lang', $user->lang_name)), - 'tz' => request_var('tz', (float) $timezone), + 'tz' => request_var('tz', $timezone), ); // Check and initialize some variables if needed @@ -189,7 +191,7 @@ class ucp_register 'email' => array( array('string', false, 6, 60), array('email')), - 'tz' => array('num', false, -14, 14), + 'tz' => array('timezone'), 'lang' => array('language_iso_name'), )); @@ -279,8 +281,7 @@ class ucp_register 'user_password' => phpbb_hash($data['new_password']), 'user_email' => $data['email'], 'group_id' => (int) $group_id, - 'user_timezone' => (float) $data['tz'], - 'user_dst' => $is_dst, + 'user_timezone' => $data['tz'], 'user_lang' => $data['lang'], 'user_type' => $user_type, 'user_actkey' => $user_actkey, @@ -441,6 +442,7 @@ class ucp_register break; } + $timezone_selects = phpbb_timezone_select($user, $data['tz'], true); $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '', 'USERNAME' => $data['username'], @@ -453,7 +455,8 @@ class ucp_register 'L_PASSWORD_EXPLAIN' => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars']), $user->lang('CHARACTERS', (int) $config['max_pass_chars'])), 'S_LANG_OPTIONS' => language_select($data['lang']), - 'S_TZ_OPTIONS' => tz_select($data['tz']), + 'S_TZ_OPTIONS' => $timezone_selects['tz_select'], + 'S_TZ_DATE_OPTIONS' => $timezone_selects['tz_dates'], 'S_CONFIRM_REFRESH' => ($config['enable_confirm'] && $config['confirm_refresh']) ? true : false, 'S_REGISTRATION' => true, 'S_COPPA' => $coppa, diff --git a/phpBB/includes/update_helpers.php b/phpBB/includes/update_helpers.php new file mode 100644 index 0000000000..8e8e9670b0 --- /dev/null +++ b/phpBB/includes/update_helpers.php @@ -0,0 +1,112 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +*/ + +/** +* phpBB Update Helpers +*/ +class phpbb_update_helpers +{ + /** + * Determine the new timezone for a given phpBB 3.0 timezone and + * "Daylight Saving Time" option + * + * @param $timezone float Users timezone in 3.0 + * @param $dst int Users daylight saving time + * @return string Users new php Timezone which is used since 3.1 + */ + function convert_phpbb30_timezone($timezone, $dst) + { + $offset = $timezone + $dst; + + switch ($timezone) + { + case '-12': + return 'Etc/GMT' . $offset; //'[UTC - 12] Baker Island Time' + case '-11': + return 'Etc/GMT' . $offset; //'[UTC - 11] Niue Time, Samoa Standard Time' + case '-10': + return 'Etc/GMT' . $offset; //'[UTC - 10] Hawaii-Aleutian Standard Time, Cook Island Time' + case '-9.5': + return 'Pacific/Marquesas'; //'[UTC - 9:30] Marquesas Islands Time' + case '-9': + return 'Etc/GMT' . $offset; //'[UTC - 9] Alaska Standard Time, Gambier Island Time' + case '-8': + return 'Etc/GMT' . $offset; //'[UTC - 8] Pacific Standard Time' + case '-7': + return 'Etc/GMT' . $offset; //'[UTC - 7] Mountain Standard Time' + case '-6': + return 'Etc/GMT' . $offset; //'[UTC - 6] Central Standard Time' + case '-5': + return 'Etc/GMT' . $offset; //'[UTC - 5] Eastern Standard Time' + case '-4.5': + return 'America/Caracas'; //'[UTC - 4:30] Venezuelan Standard Time' + case '-4': + return 'Etc/GMT' . $offset; //'[UTC - 4] Atlantic Standard Time' + case '-3.5': + return 'America/St_Johns'; //'[UTC - 3:30] Newfoundland Standard Time' + case '-3': + return 'Etc/GMT' . $offset; //'[UTC - 3] Amazon Standard Time, Central Greenland Time' + case '-2': + return 'Etc/GMT' . $offset; //'[UTC - 2] Fernando de Noronha Time, South Georgia & the South Sandwich Islands Time' + case '-1': + return 'Etc/GMT' . $offset; //'[UTC - 1] Azores Standard Time, Cape Verde Time, Eastern Greenland Time' + case '0': + return (!$dst) ? 'UTC' : 'Etc/GMT+1'; //'[UTC] Western European Time, Greenwich Mean Time' + case '1': + return 'Etc/GMT+' . $offset; //'[UTC + 1] Central European Time, West African Time' + case '2': + return 'Etc/GMT+' . $offset; //'[UTC + 2] Eastern European Time, Central African Time' + case '3': + return 'Etc/GMT+' . $offset; //'[UTC + 3] Moscow Standard Time, Eastern African Time' + case '3.5': + return 'Asia/Tehran'; //'[UTC + 3:30] Iran Standard Time' + case '4': + return 'Etc/GMT+' . $offset; //'[UTC + 4] Gulf Standard Time, Samara Standard Time' + case '4.5': + return 'Asia/Kabul'; //'[UTC + 4:30] Afghanistan Time' + case '5': + return 'Etc/GMT+' . $offset; //'[UTC + 5] Pakistan Standard Time, Yekaterinburg Standard Time' + case '5.5': + return 'Asia/Kolkata'; //'[UTC + 5:30] Indian Standard Time, Sri Lanka Time' + case '5.75': + return 'Asia/Kathmandu'; //'[UTC + 5:45] Nepal Time' + case '6': + return 'Etc/GMT+' . $offset; //'[UTC + 6] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time' + case '6.5': + return 'Indian/Cocos'; //'[UTC + 6:30] Cocos Islands Time, Myanmar Time' + case '7': + return 'Etc/GMT+' . $offset; //'[UTC + 7] Indochina Time, Krasnoyarsk Standard Time' + case '8': + return 'Etc/GMT+' . $offset; //'[UTC + 8] Chinese Standard Time, Australian Western Standard Time, Irkutsk Standard Time' + case '8.75': + return 'Australia/Eucla'; //'[UTC + 8:45] Southeastern Western Australia Standard Time' + case '9': + return 'Etc/GMT+' . $offset; //'[UTC + 9] Japan Standard Time, Korea Standard Time, Chita Standard Time' + case '9.5': + return 'Australia/ACT'; //'[UTC + 9:30] Australian Central Standard Time' + case '10': + return 'Etc/GMT+' . $offset; //'[UTC + 10] Australian Eastern Standard Time, Vladivostok Standard Time' + case '10.5': + return 'Australia/Lord_Howe'; //'[UTC + 10:30] Lord Howe Standard Time' + case '11': + return 'Etc/GMT+' . $offset; //'[UTC + 11] Solomon Island Time, Magadan Standard Time' + case '11.5': + return 'Pacific/Norfolk'; //'[UTC + 11:30] Norfolk Island Time' + case '12': + return 'Etc/GMT+12'; //'[UTC + 12] New Zealand Time, Fiji Time, Kamchatka Standard Time' + case '12.75': + return 'Pacific/Chatham'; //'[UTC + 12:45] Chatham Islands Time' + case '13': + return 'Pacific/Tongatapu'; //'[UTC + 13] Tonga Time, Phoenix Islands Time' + case '14': + return 'Pacific/Kiritimati'; //'[UTC + 14] Line Island Time' + default: + return 'UTC'; + } + } +} diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index cf9e6b9994..fcbfaaddfa 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -29,8 +29,11 @@ class phpbb_user extends phpbb_session var $help = array(); var $style = array(); var $date_format; - var $timezone; - var $dst; + + /** + * DateTimeZone object holding the timezone of the user + */ + public $timezone; var $lang_name = false; var $lang_id = false; @@ -79,15 +82,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; + $user_timezone = $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; + $user_timezone = $config['board_timezone']; /** * If a guest user is surfing, we try to guess his/her language first by obtaining the browser language @@ -126,6 +127,16 @@ class phpbb_user extends phpbb_session */ } + 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'); + } + // We include common language file here to not load it every time a custom language file is included $lang = &$this->lang; @@ -612,70 +623,46 @@ class phpbb_user extends phpbb_session */ function format_date($gmepoch, $format = false, $forcedate = false) { - static $midnight; - static $date_cache; - - $format = (!$format) ? $this->date_format : $format; - $now = time(); - $delta = $now - $gmepoch; - - if (!isset($date_cache[$format])) - { - // 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']; - } - } + static $utc; - // Zone offset - $zone_offset = $this->timezone + $this->dst; - - // 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'])) + if (!isset($utc)) { - return $this->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60))); + $utc = new DateTimeZone('UTC'); } - 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; + $time = new phpbb_datetime($this, "@$gmepoch", $utc); + $time->setTimezone($this->timezone); - if ($gmepoch > $midnight + 86400) - { - $day = 'TOMORROW'; - } - else if ($gmepoch > $midnight) - { - $day = 'TODAY'; - } - else if ($gmepoch > $midnight - 86400) - { - $day = 'YESTERDAY'; - } + return $time->format($format, $forcedate); + } - if ($day !== false) - { - return str_replace('||', $this->lang['datetime'][$day], strtr(@gmdate($date_cache[$format]['format_short'], $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->timezone; + return new phpbb_datetime($this, $time, $timezone); + } - return strtr(@gmdate($date_cache[$format]['format_long'], $gmepoch + $zone_offset), $date_cache[$format]['lang']); + /** + * Get the UNIX timestamp for a datetime in the users timezone, so we can store it in the database. + * + * @param string $format Format of the entered date/time + * @param string $time Date/time with the timezone applied + * @param DateTimeZone $timezone Timezone of the date/time, falls back to timezone of current user + * @return int Returns the unix timestamp + */ + public function get_timestamp_from_format($format, $time, DateTimeZone $timezone = null) + { + $timezone = $timezone ?: $this->timezone; + $date = DateTime::createFromFormat($format, $time, $timezone); + return ($date !== false) ? $date->format('U') : false; } /** diff --git a/phpBB/index.php b/phpBB/index.php index 9a57105d57..a477a876ad 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -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)) . "%'"; } diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 594397c815..6e99fd56a0 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1109,6 +1109,9 @@ function database_update_info() GROUPS_TABLE => array( 'group_legend' => array('UINT', 0), ), + USERS_TABLE => array( + 'user_timezone' => array('VCHAR:100', ''), + ), ), ), ); @@ -1123,6 +1126,8 @@ function change_database_data(&$no_updates, $version) { global $db, $errored, $error_ary, $config, $phpbb_root_path, $phpEx, $db_tools; + $update_helpers = new phpbb_update_helpers(); + switch ($version) { case '3.0.0': @@ -1968,7 +1973,7 @@ function change_database_data(&$no_updates, $version) 'user_email' => '', 'user_lang' => $config['default_lang'], 'user_style' => $config['default_style'], - 'user_timezone' => 0, + 'user_timezone' => 'UTC', 'user_dateformat' => $config['default_dateformat'], 'user_allow_massemail' => 0, ); @@ -2607,6 +2612,32 @@ function change_database_data(&$no_updates, $version) $config->set('assets_version', '1'); } + // If the column exists, we did not yet update the users timezone + if ($db_tools->sql_column_exists(USERS_TABLE, 'user_dst')) + { + // Update user timezones + $sql = 'SELECT user_dst, user_timezone + FROM ' . USERS_TABLE . ' + GROUP BY user_timezone, user_dst'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_timezone = '" . $db->sql_escape($update_helpers->convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "' + WHERE user_timezone = '" . $db->sql_escape($row['user_timezone']) . "' + AND user_dst = " . (int) $row['user_dst']; + _sql($sql, $errored, $error_ary); + } + $db->sql_freeresult($result); + + // Update board default timezone + set_config('board_timezone', $update_helpers->convert_phpbb30_timezone($config['board_timezone'], $config['board_dst'])); + + // After we have calculated the timezones we can delete user_dst column from user table. + $db_tools->sql_column_remove(USERS_TABLE, 'user_dst'); + } + break; } } diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index bbd11f9a6f..40dee7b3d7 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1795,7 +1795,7 @@ class install_install extends module 'user_email' => '', 'user_lang' => $data['default_lang'], 'user_style' => 1, - 'user_timezone' => 0, + 'user_timezone' => 'UTC', 'user_dateformat' => $lang['default_dateformat'], 'user_allow_massemail' => 0, ); diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index 51565ef2d4..155ac2a2d4 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -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, diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 2c78dd009f..3051f17bfa 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -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 , diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index d19f1930d0..d3c287112d 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -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, diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index 3fd8d4f1d1..d7822436b1 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -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, diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 8a0f3e56b1..96ead064a7 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -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, diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index c624024362..bb0563954d 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -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), diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index deefdafbc4..0bb1858c11 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -54,12 +54,11 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('avatar_salt', 'php INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_contact', 'contact@yourdomain.tld'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_disable', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_disable_msg', ''); -INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_dst', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_email', 'address@yourdomain.tld'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_email_form', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_email_sig', '{L_CONFIG_BOARD_EMAIL_SIG}'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_hide_emails', '1'); -INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_timezone', '0'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_timezone', 'UTC'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('browser_check', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('bump_interval', '10'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('bump_type', 'd'); diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index bd002c93ed..2504586e6c 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -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', diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index 384bce75bf..0754884473 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -50,7 +50,6 @@ $lang = array_merge($lang, array( 'OVERRIDE_STYLE_EXPLAIN' => 'Replaces user’s 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', diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index dc35969955..5cebcc89d7 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -401,6 +401,8 @@ $lang = array_merge($lang, array( 'STATISTIC' => 'Statistic', 'STATISTIC_RESYNC_OPTIONS' => 'Resynchronise or reset statistics', + 'TIMEZONE_INVALID' => 'The timezone you selected is invalid.', + 'TIMEZONE_SELECTED' => '(currently selected)', 'TOPICS_PER_DAY' => 'Topics per day', 'UPLOAD_DIR_SIZE' => 'Size of posted attachments', diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index a6da52d4ef..d0afb846b4 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -42,6 +42,7 @@ $lang = array_merge($lang, array( 'TRANSLATION_INFO' => '', 'DIRECTION' => 'ltr', 'DATE_FORMAT' => '|d M Y|', // 01 Jan 2007 (with Relative days enabled) + 'DATETIME_FORMAT' => '|d M Y, H:i|', // 01 Jan 2007, 13:37 (with Relative days enabled) 'USER_LANG' => 'en-gb', // You can define different rules for the determination of plural forms here. @@ -74,7 +75,7 @@ $lang = array_merge($lang, array( 'ALL_FORUMS' => 'All forums', 'ALL_MESSAGES' => 'All messages', 'ALL_POSTS' => 'All posts', - 'ALL_TIMES' => 'All times are %1$s %2$s', + 'ALL_TIMES' => 'All times are <abbr title="%2$s">%1$s</abbr>', 'ALL_TOPICS' => 'All Topics', 'AND' => 'And', 'ARE_WATCHING_FORUM' => 'You have subscribed to be notified of new posts in this forum.', @@ -835,93 +836,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 & 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', diff --git a/phpBB/language/en/help_faq.php b/phpBB/language/en/help_faq.php index f21a8d866e..5c99f81c06 100644 --- a/phpBB/language/en/help_faq.php +++ b/phpBB/language/en/help_faq.php @@ -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!', diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index e3971c75e2..512a4a5c24 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -103,7 +103,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', @@ -419,6 +418,8 @@ $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_CURRENT_TIME' => 'Select current time', + 'SELECT_TIMEZONE' => 'Select timezone', 'SORT' => 'Sort', 'SORT_COMMENT' => 'File comment', 'SORT_DOWNLOADS' => 'Downloads', @@ -428,6 +429,8 @@ $lang = array_merge($lang, array( 'SORT_SIZE' => 'File size', 'TIMEZONE' => 'Timezone', + 'TIMEZONE_DATE_SUGGESTION' => 'Suggestion: %s', + 'TIMEZONE_INVALID' => 'The timezone you selected is invalid.', 'TO' => 'To', 'TOO_MANY_RECIPIENTS' => 'You tried to send a private message to too many recipients.', 'TOO_MANY_REGISTERS' => 'You have exceeded the maximum number of registration attempts for this session. Please try again later.', diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 8e762be0de..4f9a8cdff3 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -1675,7 +1675,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) diff --git a/phpBB/styles/prosilver/template/timezone.js b/phpBB/styles/prosilver/template/timezone.js new file mode 100644 index 0000000000..da0a2b0bfd --- /dev/null +++ b/phpBB/styles/prosilver/template/timezone.js @@ -0,0 +1,19 @@ +(function($) { // Avoid conflicts with other libraries + +$('#tz_date').change(function() { + phpbb.timezone_switch_date(false); +}); + +$('#tz_select_date_suggest').click(function(){ + phpbb.timezone_preselect_select(true); +}); + +$(document).ready( + phpbb.timezone_enable_date_selection +); + +$(document).ready( + phpbb.timezone_preselect_select($('#tz_select_date_suggest').attr('data-is-registration') == 'true') +); + +})(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/prosilver/template/timezone_option.html b/phpBB/styles/prosilver/template/timezone_option.html new file mode 100644 index 0000000000..94e2bbdfbd --- /dev/null +++ b/phpBB/styles/prosilver/template/timezone_option.html @@ -0,0 +1,20 @@ +<dl> + <dt><label for="timezone">{L_BOARD_TIMEZONE}:</label></dt> + <!-- IF S_TZ_DATE_OPTIONS --> + <dd id="tz_select_date" style="display: none;"> + <select name="tz_date" id="tz_date" class="autowidth tz_select"> + <option value="">{L_SELECT_CURRENT_TIME}</option> + {S_TZ_DATE_OPTIONS} + </select> + <input id="tz_select_date_suggest" class="inputbox button2" style="display: none; width: 150px !important;" data-is-registration="<!-- IF S_REGISTRATION -->true<!-- ELSE -->false<!-- ENDIF -->" data-l-suggestion="{L_TIMEZONE_DATE_SUGGESTION}" value="fuu" /> + </dd> + <!-- ENDIF --> + <dd> + <select name="tz" id="timezone" class="autowidth tz_select"> + <option value="">{L_SELECT_TIMEZONE}</option> + {S_TZ_OPTIONS} + </select> + + <!-- INCLUDEJS template/timezone.js --> + </dd> +</dl> diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index 1c829899fd..29c01e03b9 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -73,17 +73,7 @@ <dd><select name="style" id="style">{S_STYLE_OPTIONS}</select></dd> </dl> <!-- 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> - </dd> - </dl> + <!-- INCLUDE timezone_option.html --> <dl> <dt><label for="dateformat">{L_BOARD_DATE_FORMAT}:</label><br /><span>{L_BOARD_DATE_FORMAT_EXPLAIN}</span></dt> <dd> diff --git a/phpBB/styles/prosilver/template/ucp_register.html b/phpBB/styles/prosilver/template/ucp_register.html index 47253af37c..994356efe6 100644 --- a/phpBB/styles/prosilver/template/ucp_register.html +++ b/phpBB/styles/prosilver/template/ucp_register.html @@ -53,10 +53,8 @@ <dt><label for="lang">{L_LANGUAGE}:</label></dt> <dd><select name="lang" id="lang" onchange="change_language(this.value); return false;" tabindex="6" title="{L_LANGUAGE}">{S_LANG_OPTIONS}</select></dd> </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> - </dl> + + <!-- INCLUDE timezone_option.html --> <!-- IF .profile_fields --> <dl><dd><strong>{L_ITEMS_REQUIRED}</strong></dd></dl> @@ -106,4 +104,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 --> diff --git a/phpBB/styles/prosilver/theme/forms.css b/phpBB/styles/prosilver/theme/forms.css index 77b3be5cfa..8829211934 100644 --- a/phpBB/styles/prosilver/theme/forms.css +++ b/phpBB/styles/prosilver/theme/forms.css @@ -32,6 +32,11 @@ option { padding-right: 1em; } +select optgroup option { + padding-right: 1em; + font-family: Verdana, Helvetica, Arial, sans-serif; +} + textarea { font-family: "Lucida Grande", Verdana, Helvetica, Arial, sans-serif; width: 60%; diff --git a/phpBB/styles/subsilver2/template/timezone.js b/phpBB/styles/subsilver2/template/timezone.js new file mode 100644 index 0000000000..da0a2b0bfd --- /dev/null +++ b/phpBB/styles/subsilver2/template/timezone.js @@ -0,0 +1,19 @@ +(function($) { // Avoid conflicts with other libraries + +$('#tz_date').change(function() { + phpbb.timezone_switch_date(false); +}); + +$('#tz_select_date_suggest').click(function(){ + phpbb.timezone_preselect_select(true); +}); + +$(document).ready( + phpbb.timezone_enable_date_selection +); + +$(document).ready( + phpbb.timezone_preselect_select($('#tz_select_date_suggest').attr('data-is-registration') == 'true') +); + +})(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/subsilver2/template/timezone_option.html b/phpBB/styles/subsilver2/template/timezone_option.html new file mode 100644 index 0000000000..3f1e14b33d --- /dev/null +++ b/phpBB/styles/subsilver2/template/timezone_option.html @@ -0,0 +1,20 @@ +<tr> + <td class="row1" width="50%"><b class="genmed">{L_BOARD_TIMEZONE}:</b></td> + <td class="row2"> + <!-- IF S_TZ_DATE_OPTIONS --> + <div id="tz_select_date" style="display: none;"> + <select name="tz_date" id="tz_date" class="autowidth tz_select"> + <option value="">{L_SELECT_CURRENT_TIME}</option> + {S_TZ_DATE_OPTIONS} + </select><br /> + <input id="tz_select_date_suggest" class="btnlite" style="display: none;" data-is-registration="<!-- IF S_REGISTRATION -->true<!-- ELSE -->false<!-- ENDIF -->" data-l-suggestion="{L_TIMEZONE_DATE_SUGGESTION}" value="{L_TIMEZONE_DATE_SUGGESTION}" /> + </div> + <!-- ENDIF --> + <select name="tz" id="timezone" class="autowidth tz_select"> + <option value="">{L_SELECT_TIMEZONE}</option> + {S_TZ_OPTIONS} + </select> + + <!-- INCLUDEJS template/timezone.js --> + </td> +</tr> diff --git a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html index 8e4b04fc10..bf0e67d68b 100644 --- a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html +++ b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html @@ -71,16 +71,7 @@ <td class="row2"><select name="style">{S_STYLE_OPTIONS}</select></td> </tr> <!-- ENDIF --> -<tr> - <td class="row1" width="50%"><b class="genmed">{L_BOARD_TIMEZONE}:</b></td> - <td class="row2"> - <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> <input type="radio" class="radio" name="dst" value="0"<!-- IF not S_DST --> checked="checked"<!-- ENDIF --> /> <span class="genmed">{L_NO}</span></td> -</tr> +<!-- INCLUDE timezone_option.html --> <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"> diff --git a/phpBB/styles/subsilver2/template/ucp_register.html b/phpBB/styles/subsilver2/template/ucp_register.html index 0c3533292d..095c97ed49 100644 --- a/phpBB/styles/subsilver2/template/ucp_register.html +++ b/phpBB/styles/subsilver2/template/ucp_register.html @@ -53,10 +53,9 @@ <td class="row1"><b class="genmed">{L_LANGUAGE}: </b></td> <td class="row2"><select name="lang" onchange="change_language(this.value); return false;">{S_LANG_OPTIONS}</select></td> </tr> -<tr> - <td class="row1"><b class="genmed">{L_TIMEZONE}: </b></td> - <td class="row2"><select name="tz">{S_TZ_OPTIONS}</select></td> -</tr> + +<!-- INCLUDE timezone_option.html --> + <!-- IF .profile_fields --> <tr> <td class="row2" colspan="2"><span class="gensmall">{L_ITEMS_REQUIRED}</span></td> diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index c0dbc12fca..349f53cbe2 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -990,7 +990,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 diff --git a/tests/datetime/from_format_test.php b/tests/datetime/from_format_test.php new file mode 100644 index 0000000000..c28925272e --- /dev/null +++ b/tests/datetime/from_format_test.php @@ -0,0 +1,57 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/session.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/user.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/datetime.php'; +require_once dirname(__FILE__) . '/../mock/lang.php'; + +class phpbb_datetime_from_format_test extends phpbb_test_case +{ + public function from_format_data() + { + return array( + array( + 'UTC', + 'Y-m-d', + '2012-06-08', + ), + + array( + 'Europe/Berlin', + 'Y-m-d H:i:s', + '2012-06-08 14:01:02', + ), + ); + } + + /** + * @dataProvider from_format_data() + */ + public function test_from_format($timezone, $format, $expected) + { + global $user; + + $user = new phpbb_user(); + $user->timezone = new DateTimeZone($timezone); + $user->lang['datetime'] = array( + 'TODAY' => 'Today', + 'TOMORROW' => 'Tomorrow', + 'YESTERDAY' => 'Yesterday', + 'AGO' => array( + 0 => 'less than a minute ago', + 1 => '%d minute ago', + 2 => '%d minutes ago', + ), + ); + + $timestamp = $user->get_timestamp_from_format($format, $expected, new DateTimeZone($timezone)); + $this->assertEquals($expected, $user->format_date($timestamp, $format, true)); + } +} |