From dc54cde6dc3376f49d0cceb46c8a4ad1cb3bfc07 Mon Sep 17 00:00:00 2001 From: David Kidd Date: Wed, 9 Jan 2013 09:38:04 -0500 Subject: [PATCH 1/4] Refactored Zend\Stdlib\DateTime::createISO8601Date to Zend\Stdlib\DateTime::createFromISO8601, updated documentation --- src/DateTime.php | 6 ++++-- test/DateTimeTest.php | 7 +++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/DateTime.php b/src/DateTime.php index 397793899..ba388e135 100644 --- a/src/DateTime.php +++ b/src/DateTime.php @@ -23,13 +23,15 @@ class DateTime extends \DateTime { /** - * Creates a DateTime object from a string and (optional) timezone. + * The DateTime::ISO8601 constant used by php's native DateTime object does + * not allow for fractions of a second. This function better handles ISO8601 + * formatted date strings. * * @param string $time * @param DateTimeZone $timezone * @return mixed */ - public static function createISO8601Date($time, DateTimeZone $timezone = null){ + public static function createFromISO8601($time, DateTimeZone $timezone = null){ $format = self::ISO8601; if (isset($time[19]) && $time[19] === '.') { $format = 'Y-m-d\TH:i:s.uO'; diff --git a/test/DateTimeTest.php b/test/DateTimeTest.php index a401ecc91..e981f948e 100644 --- a/test/DateTimeTest.php +++ b/test/DateTimeTest.php @@ -5,7 +5,7 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Feed + * @package Zend_Stdlib */ namespace ZendTest\Stdlib; @@ -27,7 +27,7 @@ public function testCreatesIS08601WithoutFractionalSeconds() { $time = '2009-03-07T08:03:50Z'; - $date = DateTime::createISO8601Date($time); + $date = DateTime::createFromISO8601($time); $this->assertEquals( \DateTime::createFromFormat(\DateTime::ISO8601, $time), $date); } @@ -36,11 +36,10 @@ public function testCreatesIS08601WithFractionalSeconds() { $time = '2009-03-07T08:03:50.012Z'; - $date = DateTime::createISO8601Date($time); + $date = DateTime::createFromISO8601($time); $standard = \DateTime::createFromFormat('Y-m-d\TH:i:s.uO', $time); $this->assertEquals( $standard, $date); } - } \ No newline at end of file From 7d1820b470f05145c6cb5b3125dcb5ab47fcb556 Mon Sep 17 00:00:00 2001 From: David Kidd Date: Wed, 9 Jan 2013 10:49:44 -0500 Subject: [PATCH 2/4] Fixed annotation of ZendTest\DateTimeTest --- test/DateTimeTest.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/DateTimeTest.php b/test/DateTimeTest.php index e981f948e..5929da034 100644 --- a/test/DateTimeTest.php +++ b/test/DateTimeTest.php @@ -13,13 +13,12 @@ use Zend\Stdlib\DateTime; /** -* @category Zend -* @package Zend_Feed -* @subpackage UnitTests -* @group Zend_Feed -* @group Zend_Feed_Reader -*/ -class AtomTest extends \PHPUnit_Framework_TestCase + * @category Zend + * @package Zend_Stdlib + * @subpackage UnitTests + * @group Zend_Stdlib + */ +class DateTimeTest extends \PHPUnit_Framework_TestCase { public $dateTime; From 45016f956c4d9868daf4b9dd3b28fccfc718e1ae Mon Sep 17 00:00:00 2001 From: David Kidd Date: Wed, 9 Jan 2013 12:47:41 -0500 Subject: [PATCH 3/4] Ran php-cs-fixer on Zend\Stdlib\DateTime.php and ZendTest\Stdlib\DateTimeTest.php --- src/DateTime.php | 22 ++++++++++++---------- test/DateTimeTest.php | 16 ++++++++-------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/DateTime.php b/src/DateTime.php index ba388e135..a3d8a651d 100644 --- a/src/DateTime.php +++ b/src/DateTime.php @@ -20,27 +20,29 @@ * @category Zend * @package Zend_Stdlib */ -class DateTime extends \DateTime { - +class DateTime extends \DateTime +{ /** * The DateTime::ISO8601 constant used by php's native DateTime object does * not allow for fractions of a second. This function better handles ISO8601 * formatted date strings. - * - * @param string $time - * @param DateTimeZone $timezone + * + * @param string $time + * @param DateTimeZone $timezone * @return mixed */ - public static function createFromISO8601($time, DateTimeZone $timezone = null){ + public static function createFromISO8601($time, DateTimeZone $timezone = null) + { $format = self::ISO8601; if (isset($time[19]) && $time[19] === '.') { $format = 'Y-m-d\TH:i:s.uO'; } - - if( $timezone !== null ) + + if ($timezone !== null) { return self::createFromFormat($format, $time, $timezone); + } return self::createFromFormat($format, $time); } - -} \ No newline at end of file + +} diff --git a/test/DateTimeTest.php b/test/DateTimeTest.php index 5929da034..45d4f8909 100644 --- a/test/DateTimeTest.php +++ b/test/DateTimeTest.php @@ -21,24 +21,24 @@ class DateTimeTest extends \PHPUnit_Framework_TestCase { public $dateTime; - + public function testCreatesIS08601WithoutFractionalSeconds() { $time = '2009-03-07T08:03:50Z'; - + $date = DateTime::createFromISO8601($time); - + $this->assertEquals( \DateTime::createFromFormat(\DateTime::ISO8601, $time), $date); } - + public function testCreatesIS08601WithFractionalSeconds() { $time = '2009-03-07T08:03:50.012Z'; - + $date = DateTime::createFromISO8601($time); - + $standard = \DateTime::createFromFormat('Y-m-d\TH:i:s.uO', $time); - + $this->assertEquals( $standard, $date); } -} \ No newline at end of file +} From d33133a5e30be0a8ba38843411216e84b219b80a Mon Sep 17 00:00:00 2001 From: Maks3w Date: Wed, 9 Jan 2013 20:53:45 +0100 Subject: [PATCH 4/4] [zendframework/zf2#3375] Update copyright year --- src/DateTime.php | 2 +- test/DateTimeTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DateTime.php b/src/DateTime.php index a3d8a651d..032fc94ff 100644 --- a/src/DateTime.php +++ b/src/DateTime.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @package Zend_Stdlib */ diff --git a/test/DateTimeTest.php b/test/DateTimeTest.php index 45d4f8909..f6c2e0553 100644 --- a/test/DateTimeTest.php +++ b/test/DateTimeTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @package Zend_Stdlib */