aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2012-06-04 18:09:35 +0200
committerJoas Schilling <nickvergessen@gmx.de>2012-06-04 18:09:35 +0200
commit8f027b68d64c1baa99b272d45f382c17310f1480 (patch)
tree396e3a0db22b10060c42ad3cec8640e87a96c3c2 /phpBB/includes/functions.php
parent4af503e11bc2c42654cf783f031bdb074fdd91ed (diff)
parentb672fc7ae113c0e01f1d7ce4ffae3eb26e57b586 (diff)
downloadforums-8f027b68d64c1baa99b272d45f382c17310f1480.tar
forums-8f027b68d64c1baa99b272d45f382c17310f1480.tar.gz
forums-8f027b68d64c1baa99b272d45f382c17310f1480.tar.bz2
forums-8f027b68d64c1baa99b272d45f382c17310f1480.tar.xz
forums-8f027b68d64c1baa99b272d45f382c17310f1480.zip
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
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r--phpBB/includes/functions.php100
1 files changed, 93 insertions, 7 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 95f2cf8d26..3ec4b76091 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -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;
+ static $timezones;
+
+ if (!isset($timezones))
+ {
+ $timezones = DateTimeZone::listIdentifiers();
+
+ foreach ($timezones as &$timezone)
+ {
+ $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 ($user->lang['tz_zones'] as $offset => $zone)
+
+ foreach ($timezones as $timezone)
{
- if ($truncate)
+ if (isset($user->lang['timezones'][$timezone]))
{
- $zone_trunc = truncate_string($zone, 50, 255, false, '...');
+ $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;