From c7a5cf6dcd36bffefd7dd30e68db49b35966bee1 Mon Sep 17 00:00:00 2001 From: Brian Kendig Date: Wed, 29 Oct 2014 13:44:27 -0400 Subject: [PATCH 1/2] Add support for time strings without seconds. --- library/Zend/Date.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/library/Zend/Date.php b/library/Zend/Date.php index 08c7d74eab..11f2f76f16 100644 --- a/library/Zend/Date.php +++ b/library/Zend/Date.php @@ -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); @@ -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]; From b430be53f8b8d88821adcf5b0afc47d80cf6198a Mon Sep 17 00:00:00 2001 From: Brian Kendig Date: Thu, 30 Oct 2014 13:24:44 -0400 Subject: [PATCH 2/2] Unit tests for the time format additions. --- tests/Zend/DateTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Zend/DateTest.php b/tests/Zend/DateTest.php index 01fc0ae6d1..43fcf996bd 100644 --- a/tests/Zend/DateTest.php +++ b/tests/Zend/DateTest.php @@ -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');