1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-13 17:09:46 +01:00

Merge pull request #2139 from lonalore/timezone

Timezone settings improvement: Display time-offset in timezone dropdown.
This commit is contained in:
Cameron 2016-12-13 10:31:35 -08:00 committed by GitHub
commit a1588ed318
2 changed files with 35 additions and 3 deletions

View File

@ -1140,7 +1140,7 @@ if (($_SERVER['QUERY_STRING'] == 'logout')/* || (($pref['user_tracking'] == 'ses
*
*/
$tz = vartrue($pref['timezone'],'GMT'); //TODO Adjust on the front-end based on user timezone value.
$tz = vartrue($pref['timezone'], 'UTC'); //TODO Adjust on the front-end based on user timezone value.
date_default_timezone_set($tz); // Must be set or PHP Warning thrown.

View File

@ -750,7 +750,7 @@ foreach($toffset as $o)
$timeZones = timezone_identifiers_list();
$timeZones = systemTimeZones();
@ -763,7 +763,7 @@ $text .= "
<tr>
<td><label for='timezone'>".PRFLAN_56."</label></td>
<td>
".$frm->select('timezone', $timeZones, vartrue($pref['timezone'],'GMT'), 'useValues=1')."
".$frm->select('timezone', $timeZones, vartrue($pref['timezone'], 'UTC'))."
</td>
</tr>
</tbody>
@ -772,6 +772,38 @@ $text .= "
</fieldset>
";
/**
* Generate an array of time zones.
*/
function systemTimeZones()
{
$zonelist = timezone_identifiers_list();
$timeNow = date('m/d/Y H:i', $_SERVER['REQUEST_TIME']);
$zones = array();
foreach($zonelist as $zone)
{
// Because many time zones exist in PHP only for backward compatibility
// reasons and should not be used, the list is filtered by a regular
// expression.
if(preg_match('!^((Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)/|UTC$)!', $zone))
{
$dateTimeZone = new DateTimeZone($zone);
$dateTime = new DateTime($timeNow, $dateTimeZone);
$offset = $dateTime->format('O');
$offset = chunk_split($offset, 3, ':');
$zones[$zone] = str_replace('_', ' ', $zone) . ' (' . rtrim($offset, ':') . ')';
}
}
// Sort time zones alphabetically.
asort($zones);
return $zones;
}
// =========== Registration Preferences. ==================