forked from zendframework/zendframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request zendframework#3375 branch 'hotfix/hotfix/iso8601-f…
…actrion-of-seconds'
- Loading branch information
Showing
6 changed files
with
102 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @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 | ||
*/ | ||
|
||
namespace Zend\Stdlib; | ||
|
||
use DateTimeZone; | ||
|
||
/** | ||
* DateTime | ||
* | ||
* An extension of the \DateTime object. | ||
* | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
*/ | ||
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 | ||
* @return mixed | ||
*/ | ||
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) { | ||
return self::createFromFormat($format, $time, $timezone); | ||
} | ||
|
||
return self::createFromFormat($format, $time); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @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 | ||
*/ | ||
|
||
namespace ZendTest\Stdlib; | ||
|
||
use Zend\Stdlib\DateTime; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @subpackage UnitTests | ||
* @group Zend_Stdlib | ||
*/ | ||
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); | ||
} | ||
} |