Make DateTimeFactory expecting a string instead of a DateTimeZone
This commit is contained in:
parent
1db9b1ede4
commit
891d36dbd7
|
@ -456,13 +456,8 @@ abstract class ApplicationBootstrap
|
|||
protected function setupTimezone()
|
||||
{
|
||||
$timeZoneString = $this->config->global !== null ? $this->config->global->get('timezone', 'UTC') : 'UTC';
|
||||
try {
|
||||
$tz = new DateTimeZone($timeZoneString);
|
||||
} catch (Exception $e) {
|
||||
throw new ConfigurationError(t('Invalid timezone') . ' "' . $timeZoneString . '"');
|
||||
}
|
||||
date_default_timezone_set($timeZoneString);
|
||||
DateTimeFactory::setConfig(array('timezone' => $tz));
|
||||
DateTimeFactory::setConfig(array('timezone' => $timeZoneString));
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -337,13 +337,12 @@ class Web extends ApplicationBootstrap
|
|||
}
|
||||
|
||||
try {
|
||||
$tz = new DateTimeZone($userTimezone);
|
||||
} catch (Exception $e) {
|
||||
DateTimeFactory::setConfig(array('timezone' => $userTimezone));
|
||||
date_default_timezone_set($userTimezone);
|
||||
} catch (ConfigurationError $e) {
|
||||
return parent::setupTimezone();
|
||||
}
|
||||
|
||||
date_default_timezone_set($userTimezone);
|
||||
DateTimeFactory::setConfig(array('timezone' => $tz));
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ namespace {
|
|||
namespace Icinga\Test {
|
||||
|
||||
use \Exception;
|
||||
use \DateTimeZone;
|
||||
use \RuntimeException;
|
||||
use \Mockery;
|
||||
use \Zend_Config;
|
||||
|
@ -113,7 +112,7 @@ namespace Icinga\Test {
|
|||
public static function setupTimezone()
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
DateTimeFactory::setConfig(array('timezone' => 'UTC'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,8 +29,9 @@
|
|||
|
||||
namespace Icinga\Util;
|
||||
|
||||
use \DateTime;
|
||||
use \DateTimeZone;
|
||||
use Exception;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Icinga\Util\ConfigAwareFactory;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
||||
|
@ -55,10 +56,13 @@ class DateTimeFactory implements ConfigAwareFactory
|
|||
*/
|
||||
public static function setConfig($config)
|
||||
{
|
||||
if (!array_key_exists('timezone', $config)) {
|
||||
throw new ConfigurationError(t('"DateTimeFactory" expects a valid time zone to be set via "setConfig"'));
|
||||
try {
|
||||
$tz = new DateTimeZone(isset($config['timezone']) ? $config['timezone'] : '');
|
||||
} catch (Exception $e) {
|
||||
throw new ConfigurationError('"DateTimeFactory" expects a valid time zone be set via "setConfig"');
|
||||
}
|
||||
self::$timeZone = $config['timezone'];
|
||||
|
||||
self::$timeZone = $tz;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
namespace Tests\Icinga\Views\Helper;
|
||||
|
||||
use Mockery;
|
||||
use DateTimeZone;
|
||||
use Zend_View_Helper_DateFormat;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Application\Config;
|
||||
|
@ -26,12 +25,12 @@ class DateFormatTest extends BaseTestCase
|
|||
{
|
||||
parent::tearDown();
|
||||
Config::$configDir = $this->oldConfigDir;
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone(date_default_timezone_get())));
|
||||
DateTimeFactory::setConfig(array('timezone' => date_default_timezone_get()));
|
||||
}
|
||||
|
||||
public function testFormatReturnsCorrectDateWithTimezoneApplied()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('Europe/Berlin')));
|
||||
DateTimeFactory::setConfig(array('timezone' => 'Europe/Berlin'));
|
||||
$helper = new Zend_View_Helper_DateFormat($this->getRequestMock());
|
||||
|
||||
$this->assertEquals(
|
||||
|
|
Loading…
Reference in New Issue