Skip to content

Commit

Permalink
Add getTimezonesWithAbbreviations().
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Mar 23, 2016
1 parent 794c3d9 commit 26fb9b9
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions framework/Nls/lib/Horde/Nls.php
@@ -1,9 +1,5 @@
<?php
/**
* The Horde_Nls:: class provides Native Language Support. This includes
* common methods for handling language data, timezones, and hostname->country
* lookups.
*
* Copyright 1999-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
Expand All @@ -17,6 +13,21 @@
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Nls
*/

/**
* The Horde_Nls class provides Native Language Support.
*
* This includes common methods for handling language data, timezones, and
* hostname->country lookups.
*
* @author Jon Parise <jon@horde.org>
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Jan Schneider <jan@horde.org>
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Nls
*/
class Horde_Nls
{
/**
Expand Down Expand Up @@ -69,6 +80,29 @@ public static function getTimezones()
return array_combine($timezones, $timezones);
}

/**
* Returns a list of available timezones, including timezone abbreviations.
*
* Contrary to getTimezones() the timezone IDs are values and the timezone
* labels are the keys, to allow multiple labels for the same timezone.
*
* @since 2.2.0
*
* @return array List of timezones.
*/
public static function getTimezonesWithAbbreviations()
{
$timezones = array_flip(self::getTimezones());
foreach (DateTimeZone::listAbbreviations() as $abbreviation => $timezone) {
$abbreviation = Horde_String::upper($abbreviation);
if ($abbreviation == 'UTC' || strlen($abbreviation) < 2) {
continue;
}
$timezones[$abbreviation] = $timezone[0]['timezone_id'];
}
return $timezones;
}

/**
* Get the locale info returned by localeconv(), but cache it, to
* avoid repeated calls.
Expand Down

0 comments on commit 26fb9b9

Please sign in to comment.