Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 8d37cd0

Browse files
committed
Merge pull request zendframework/zendframework#3375 branch 'hotfix/hotfix/iso8601-factrion-of-seconds'
156 parents 1112202 + b6d0c88 + 7edee62 + 60ea64c + a08bcca + b40ec3e + 63172ed + 448f428 + 92a516a + 5ecbc99 + a2df21b + 4de87f2 + 7c259ec + a22bdcb + 084ad9f + 9414e5a + 489be93 + cb39e7e + 54a28dc + c9c769e + dda791d + 70d382a + 8bbad0e + 9321185 + 7ab35a6 + b93694e + 3ea7087 + 0fe3d3a + bd5e189 + d1cba17 + 8d75392 + 3fb5b55 + 6cb0ccb + 30aa565 + 8409977 + 8074ba0 + 8f92486 + 94860d1 + 05d33c4 + 425826b + f0e91f0 + e31468f + 7d2af87 + 2e4dc80 + 19d128f + 1b9e4b2 + 1c46483 + fdda3f2 + 595fcd1 + 213395c + 8e514a8 + 2f30186 + bb4ed65 + 132d5b6 + 030ff33 + f2f20f3 + a50e133 + 4c554ee + dbfb1b8 + ccab83f + 00b350f + 78945d0 + f0e5f4b + ceb7d8c + 9e124d1 + 3de5912 + b6a974a + 10a6438 + cb6c1e7 + 18afd6c + 3baf1bd + c800904 + f52dcb8 + 126ccb2 + e7d6206 + e2d24ab + ec1abfc + 290ea90 + 9f4ca1b + edaa760 + c4c0c95 + d21f055 + 5b18029 + e6b97af + 010fb36 + 64c7b8d + 636523e + 4cc2cd6 + e34098a + 16367cd + 943c77f + 8226e5b + 0b47726 + 3cd8a03 + cc4782c + 9c653a6 + 656dbe5 + 9bce1ba + 7dc18ca + 861130d + 2d2ffbd + 4f413a5 + 2e1067a + 1d082e4 + e8aeb79 + b562091 + ff2fdc3 + 4aa72c0 + 1bb67ac + cd015c8 + 5e89910 + 0c21258 + dd54faf + 57f9063 + b88ce2e + af68643 + 06cd3b4 + 2c71b71 + ee02c35 + 9456314 + 5a77a7b + e98a077 + 738f2e6 + cb1e63c + 736df07 + d0a0154 + 990523c + 78687de + a5b6e79 + 6e9dfe9 + e201a1c + d9b45ef + 76222ad + 16d67da + 1ab2258 + b81d711 + ed2e9bc + 61efe82 + f353ea5 + 1f02519 + 58c1fe8 + ed502d9 + 2defba6 + 4885013 + 06a8384 + 17d9eed + 3b21b5d + c62101c + 909ef34 + 13d376a + efcb00e + 0a0842f + 8a75367 + 98a3cf5 + 270f2c4 + d33133a commit 8d37cd0

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

src/DateTime.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
* @package Zend_Stdlib
9+
*/
10+
11+
namespace Zend\Stdlib;
12+
13+
use DateTimeZone;
14+
15+
/**
16+
* DateTime
17+
*
18+
* An extension of the \DateTime object.
19+
*
20+
* @category Zend
21+
* @package Zend_Stdlib
22+
*/
23+
class DateTime extends \DateTime
24+
{
25+
/**
26+
* The DateTime::ISO8601 constant used by php's native DateTime object does
27+
* not allow for fractions of a second. This function better handles ISO8601
28+
* formatted date strings.
29+
*
30+
* @param string $time
31+
* @param DateTimeZone $timezone
32+
* @return mixed
33+
*/
34+
public static function createFromISO8601($time, DateTimeZone $timezone = null)
35+
{
36+
$format = self::ISO8601;
37+
if (isset($time[19]) && $time[19] === '.') {
38+
$format = 'Y-m-d\TH:i:s.uO';
39+
}
40+
41+
if ($timezone !== null) {
42+
return self::createFromFormat($format, $time, $timezone);
43+
}
44+
45+
return self::createFromFormat($format, $time);
46+
}
47+
48+
}

test/DateTimeTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
* @package Zend_Stdlib
9+
*/
10+
11+
namespace ZendTest\Stdlib;
12+
13+
use Zend\Stdlib\DateTime;
14+
15+
/**
16+
* @category Zend
17+
* @package Zend_Stdlib
18+
* @subpackage UnitTests
19+
* @group Zend_Stdlib
20+
*/
21+
class DateTimeTest extends \PHPUnit_Framework_TestCase
22+
{
23+
public $dateTime;
24+
25+
public function testCreatesIS08601WithoutFractionalSeconds()
26+
{
27+
$time = '2009-03-07T08:03:50Z';
28+
29+
$date = DateTime::createFromISO8601($time);
30+
31+
$this->assertEquals( \DateTime::createFromFormat(\DateTime::ISO8601, $time), $date);
32+
}
33+
34+
public function testCreatesIS08601WithFractionalSeconds()
35+
{
36+
$time = '2009-03-07T08:03:50.012Z';
37+
38+
$date = DateTime::createFromISO8601($time);
39+
40+
$standard = \DateTime::createFromFormat('Y-m-d\TH:i:s.uO', $time);
41+
42+
$this->assertEquals( $standard, $date);
43+
}
44+
}

0 commit comments

Comments
 (0)