<?php
namespace Moto\Validator; use Moto\Application\Util\Timezones; class TimezoneValidator extends AbstractValidator { const INVALID_TIMEZONE = 'invalidTimezone'; protected $messageTemplates = array( self::INVALID_TIMEZONE => "Timezone '%zone%' is invalid" ); protected $messageVariables = array( 'zone' => '_zone' ); protected $_zone; public function isValid($value, array $context = null) { $this->setValue($value); $this->_zone = $value; $isValid = Timezones::isExists($value); if ($isValid) { $currentZone = @date_default_timezone_get(); $isValid = @date_default_timezone_set($value); @date_default_timezone_set($currentZone); } if (!$isValid) { $this->error(self::INVALID_TIMEZONE); } return $isValid; } } 