Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Add support for time strings without seconds. #450

Merged
merged 3 commits into from
Nov 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions library/Zend/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -2067,9 +2067,18 @@ private function _calculate($calc, $date, $part, $locale)
}
// (T)hh:mm:ss
preg_match('/[T,\s]{0,1}(\d{2}):(\d{2}):(\d{2})/', $tmpdate, $timematch);
// (T)hhmmss
if (empty($timematch)) {
preg_match('/[T,\s]{0,1}(\d{2})(\d{2})(\d{2})/', $tmpdate, $timematch);
}
// (T)hh:mm
if (empty($timematch)) {
preg_match('/[T,\s]{0,1}(\d{2}):(\d{2})/', $tmpdate, $timematch);
}
// (T)hhmm
if (empty($timematch)) {
preg_match('/[T,\s]{0,1}(\d{2})(\d{2})/', $tmpdate, $timematch);
}
if (empty($datematch) and empty($timematch)) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception("unsupported ISO8601 format ($date)", 0, null, $date);
Expand All @@ -2093,6 +2102,9 @@ private function _calculate($calc, $date, $part, $locale)
$timematch[2] = 0;
$timematch[3] = 0;
}
if (!isset($timematch[3])) {
$timematch[3] = 0;
}

if (($calc == 'set') || ($calc == 'cmp')) {
--$datematch[2];
Expand Down
9 changes: 9 additions & 0 deletions tests/Zend/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,15 @@ public function testSet2()
$date->set('20071020T20:10:30', Zend_Date::ISO_8601);
$this->assertSame('2007-10-20T20:10:30+05:00', $date->get(Zend_Date::W3C));
$date->set(1234567890);
$date->set('20071020T10:30', Zend_Date::ISO_8601);
$this->assertSame('2007-10-20T10:30:00+05:00', $date->get(Zend_Date::W3C));
$date->set(1234567890);
$date->set('20071020T103000', Zend_Date::ISO_8601);
$this->assertSame('2007-10-20T10:30:00+05:00', $date->get(Zend_Date::W3C));
$date->set(1234567890);
$date->set('20071020T1020', Zend_Date::ISO_8601);
$this->assertSame('2007-10-20T10:20:00+05:00', $date->get(Zend_Date::W3C));
$date->set(1234567890);
$date->set('-00071020T20:10:30', Zend_Date::ISO_8601);
$this->assertSame('-7-10-20T20:10:30+00:00', $date->get(Zend_Date::W3C));
$date->setTimezone('Indian/Maldives');
Expand Down