Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 5eeb261

Browse files
committed
Merge pull request zendframework#450 from bskendig/master
[Zend_Date] Add support for time strings without seconds.
2 parents 2b8d4cb + a0c0349 commit 5eeb261

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

library/Zend/Date.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,9 +2067,18 @@ private function _calculate($calc, $date, $part, $locale)
20672067
}
20682068
// (T)hh:mm:ss
20692069
preg_match('/[T,\s]{0,1}(\d{2}):(\d{2}):(\d{2})/', $tmpdate, $timematch);
2070+
// (T)hhmmss
20702071
if (empty($timematch)) {
20712072
preg_match('/[T,\s]{0,1}(\d{2})(\d{2})(\d{2})/', $tmpdate, $timematch);
20722073
}
2074+
// (T)hh:mm
2075+
if (empty($timematch)) {
2076+
preg_match('/[T,\s]{0,1}(\d{2}):(\d{2})/', $tmpdate, $timematch);
2077+
}
2078+
// (T)hhmm
2079+
if (empty($timematch)) {
2080+
preg_match('/[T,\s]{0,1}(\d{2})(\d{2})/', $tmpdate, $timematch);
2081+
}
20732082
if (empty($datematch) and empty($timematch)) {
20742083
require_once 'Zend/Date/Exception.php';
20752084
throw new Zend_Date_Exception("unsupported ISO8601 format ($date)", 0, null, $date);
@@ -2093,6 +2102,9 @@ private function _calculate($calc, $date, $part, $locale)
20932102
$timematch[2] = 0;
20942103
$timematch[3] = 0;
20952104
}
2105+
if (!isset($timematch[3])) {
2106+
$timematch[3] = 0;
2107+
}
20962108

20972109
if (($calc == 'set') || ($calc == 'cmp')) {
20982110
--$datematch[2];

tests/Zend/DateTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,15 @@ public function testSet2()
19551955
$date->set('20071020T20:10:30', Zend_Date::ISO_8601);
19561956
$this->assertSame('2007-10-20T20:10:30+05:00', $date->get(Zend_Date::W3C));
19571957
$date->set(1234567890);
1958+
$date->set('20071020T10:30', Zend_Date::ISO_8601);
1959+
$this->assertSame('2007-10-20T10:30:00+05:00', $date->get(Zend_Date::W3C));
1960+
$date->set(1234567890);
1961+
$date->set('20071020T103000', Zend_Date::ISO_8601);
1962+
$this->assertSame('2007-10-20T10:30:00+05:00', $date->get(Zend_Date::W3C));
1963+
$date->set(1234567890);
1964+
$date->set('20071020T1020', Zend_Date::ISO_8601);
1965+
$this->assertSame('2007-10-20T10:20:00+05:00', $date->get(Zend_Date::W3C));
1966+
$date->set(1234567890);
19581967
$date->set('-00071020T20:10:30', Zend_Date::ISO_8601);
19591968
$this->assertSame('-7-10-20T20:10:30+00:00', $date->get(Zend_Date::W3C));
19601969
$date->setTimezone('Indian/Maldives');

0 commit comments

Comments
 (0)