Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Display correct timezones

  • Loading branch information
Gerrit0 committed Jun 6, 2016
1 parent 71f56af commit 5768ffc4735d278d27c7de45464121161fbfb7e7
Showing with 17 additions and 29 deletions.
  1. +17 −29 install/run.php
@@ -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;
}

0 comments on commit 5768ffc

Please sign in to comment.
You can’t perform that action at this time.