Files
yii2-usuario/lib/User/Helper/TimezoneHelper.php
2016-12-20 14:00:41 +06:00

45 lines
1.1 KiB
PHP

<?php
/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Da\User\Helper;
use DateTimeZone;
use yii\helpers\ArrayHelper;
use DateTime;
class TimezoneHelper
{
/**
* Get all of the time zones with the offsets sorted by their offset.
*
* @return array
*/
public static function getAll()
{
$timeZones = [];
$timeZoneIdentifiers = DateTimeZone::listIdentifiers();
foreach ($timeZoneIdentifiers as $timeZone) {
$date = new DateTime('now', new DateTimeZone($timeZone));
$offset = $date->getOffset() / 60 / 60;
$timeZones[] = [
'timezone' => $timeZone,
'name' => "{$timeZone} (UTC ".($offset > 0 ? '+' : '')."{$offset})",
'offset' => $offset,
];
}
ArrayHelper::multisort($timeZones, 'offset', SORT_DESC, SORT_NUMERIC);
return $timeZones;
}
}