4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Extension\Core\Type
;
14 use Symfony\Component\Form\AbstractType
;
15 use Symfony\Component\OptionsResolver\OptionsResolverInterface
;
17 class TimezoneType
extends AbstractType
20 * Stores the available timezone choices
23 private static $timezones;
28 public function setDefaultOptions(OptionsResolverInterface
$resolver)
30 $resolver->setDefaults(array(
31 'choices' => self
::getTimezones(),
38 public function getParent()
46 public function getName()
52 * Returns the timezone choices.
54 * The choices are generated from the ICU function
55 * \DateTimeZone::listIdentifiers(). They are cached during a single request,
56 * so multiple timezone fields on the same page don't lead to unnecessary
59 * @return array The timezone choices
61 public static function getTimezones()
63 if (null === static::$timezones) {
64 static::$timezones = array();
66 foreach (\DateTimeZone
::listIdentifiers() as $timezone) {
67 $parts = explode('/', $timezone);
69 if (count($parts) > 2) {
71 $name = $parts[1].' - '.$parts[2];
72 } elseif (count($parts) > 1) {
80 static::$timezones[$region][$timezone] = str_replace('_', ' ', $name);
84 return static::$timezones;