Framework/DateTime: No longer use the Unix timestamp format since this ignores the time zone

refs #4440
This commit is contained in:
Eric Lippmann 2013-08-12 14:18:58 +02:00
parent 9f22905837
commit 2c217d1d06
3 changed files with 22 additions and 33 deletions

View File

@ -5,11 +5,14 @@
// {{{ICINGA_LICENSE_HEADER}}}
use \DateTime;
use Icinga\Application\Icinga;
use Icinga\Application\Config as IcingaConfig;
use \Icinga\Application\Icinga;
use \Icinga\Application\Config as IcingaConfig;
use \Icinga\Util\DateTimeFactory;
/**
* Helper to format date and time
* Helper to format date and time. Utilizes DateTimeFactory to ensure time zone awareness
*
* @see \Icinga\Util\DateTimeFactory::create()
*/
class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
{
@ -49,8 +52,8 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
*/
private function format($timestamp, $format)
{
// Using the Unix timestamp format to construct a new DateTime
$dt = new DateTime('@' . $timestamp, $this->getTimeZone());
$dt = DateTimeFactory::create();
$dt->setTimestamp($timestamp);
return $dt->format($format);
}
@ -87,16 +90,6 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
return $this->format($timestamp, $this->getDateTimeFormat());
}
/**
* Retrieve the user's timezone
*
* @return DateTimeZone
*/
private function getTimeZone()
{
return $this->request->getUser()->getTimeZone();
}
/**
* Retrieve the user's date format string
*

View File

@ -85,20 +85,20 @@ class DateTimePicker extends Zend_Form_Element_Xhtml
}
if ($this->isUnixTimestamp($value)) {
// Using the Unix timestamp format to construct a new DateTime
$value = '@' . $value;
}
try {
$dt = DateTimeFactory::create($value);
} catch (Exception $e) {
$this->addErrorMessage(
_(
'Failed to parse datetime string. See '
. 'http://www.php.net/manual/en/datetime.formats.php for valid formats'
)
);
return false;
$dt = DateTimeFactory::create();
$dt->setTimestamp($value);
} else {
try {
$dt = DateTimeFactory::create($value);
} catch (Exception $e) {
$this->addErrorMessage(
_(
'Failed to parse datetime string. See '
. 'http://www.php.net/manual/en/datetime.formats.php for valid formats'
)
);
return false;
}
}
$this->setValue($dt->getTimestamp());

View File

@ -64,10 +64,6 @@ class DateTimeTest extends PHPUnit_Framework_TestCase
$dt->isValid('2013-07-12 08:03:43'),
'Using a valid date/time string must not fail'
);
$this->assertTrue(
$dt->isValid('@' . 1373616223),
'Using the Unix timestamp format must not fail'
);
$this->assertTrue(
$dt->isValid(1373616223),
'Using valid Unix timestamps must not fail'