Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
Display correct timezones
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Jun 6, 2016
1 parent 71f56af commit 5768ffc
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions install/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,26 @@
*/
function timezones()
{
$list = DateTimeZone::listIdentifiers();
$data = array();
foreach ($list as $id => $zone) {
$date= new DateTime(null, new DateTimeZone($zone));
$ds = $date->format('I');
$offset = $date->getOffset();
$gmt = round(abs($offset / 3600), 2);
$gmt = ($ds == 1 ? $gmt : $gmt-1);
$minutes = fmod($gmt, 1);
if ($minutes == 0) {
$offset_label = $gmt.'  ';
} elseif ($minutes == 0.5) {
$offset_label = (int)$gmt.'.30';
} elseif ($minutes == 0.75) {
$offset_label = (int)$gmt.'.45';
}
$sign = $offset > 0 ? '+' : '-';
if ($offset == 0) {
$sign = ' ';
$offset = '';
}
$label = 'GMT' . $sign . $offset_label . ' ' . $zone;
$data[$offset][$zone] = array('offset'=> $offset, 'label' => $label, 'timezone_id' => $zone);
}
ksort($data);
$timezones = array();
foreach ($data as $offsets) {
ksort($offsets);
foreach ($offsets as $zone) {
$timezones[] = $zone;
$now = new DateTime('now', new DateTimeZone('UTC'));
foreach (DateTimeZone::listIdentifiers() as $timezone) {
$now->setTimezone(new DateTimeZone($timezone));
$offset = $now->getOffset();
$hours = intval($offset / 3600);
$minutes = abs(intval($offset % 3600 / 60));
//Create the label
$label = 'GMT';
if ($offset) {
$label .= ($hours < 0 ? '' : '+') . $hours;
$label .= $minutes ? '.' . $minutes : '&nbsp;&nbsp;';
}
$label .= '&nbsp;' . $timezone;
$timezones[] = array('offset' => $offset, 'timezone_id' => $timezone, 'label' => $label);
}
//Sort by offset, and then by timezone_id.
usort($timezones, function($a, $b) {
return ($a['offset'] - $b['offset']) - strcmp($b['timezone_id'], $a['timezone_id']);
});
return $timezones;
}

Expand Down

0 comments on commit 5768ffc

Please sign in to comment.