Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Deprecate Zend\Stdlib\DateTime and use \DateTime constructor internally instead #3951

Closed
wants to merge 1 commit into from

4 participants

@DASPRiD
Collaborator

Zend\Stdlib\DateTime was introduced for no real reason; at least not without looking more deeply into how the native DateTime object works. The main reason was to be able to parse fractional seconds in ISO8601 dates, which was not possible with DateTime::createFromFormat(), but is actually possible with the DateTime constructor itself.

This PR deprecates that unnecessary class again and puts the DateTime constructor in place where needed.

@Freeaqingme
Collaborator

Imho we can't do this for ZF2 as this effectively is a BC Break. Time to get a version3 branch up & running ;)

@iquabius

:+1: for a version3 branch. :)

@DASPRiD
Collaborator

In case we can't make the Zend\Stdlib\DateTime removal anymore, we can at least incorporate the Zend\Feed changes.

@DASPRiD
Collaborator

Just for the record: I highly doubt that anyone has really used this class yet apart from our internal usage. It has been documented nowhere and is only in for this single version.

@DASPRiD
Collaborator

Also, I talked with Derick; He actually stated that the constants were not meant to be used with the createFromFormat() method, but only for formatting dates for output:

[Derick] using the constants for createfromformat is kinda ... odd

So eventually, Zend\Feed was already doing it "wrong". He also approved that the DateTime constructor is perfectly fine for parsing such dates.

@weierophinney weierophinney was assigned
@weierophinney

I'll accept this on the conditions that:

  • Zend\Stdlib\DateTime and related tests remain in the repository (removing them is a BC break)
  • Change the title to reflect that you're replacing Zend\Stdlib\DateTime usage with DateTime in Zend\Feed.

If that's done, we can merge this for 2.2.0.

@DASPRiD
Collaborator

@weierophinney Is it fine to mark Zend\Stdlib\DateTime as deprecated as we did with the Query route?

@weierophinney
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#3951] Add error handler for deprecation warning
- Added an error handler to catch the deprecation warning now emitted by
  Zend\Stdlib\DateTime
ed4c2bd
@weierophinney

Merged to develop for release with 2.2.0

@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney [#3951] Add error handler for deprecation warning
- Added an error handler to catch the deprecation warning now emitted by
  Zend\Stdlib\DateTime
2137e8d
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'feature/3951' into develop
Close #3951
e460b67
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-stdlib
@weierophinney weierophinney Merge pull request zendframework/zf2#3951 from DASPRiD/removal/stdlib…
…-datetime

Deprecate Zend\Stdlib\DateTime and use \DateTime constructor internally instead
81105d4
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-stdlib
@weierophinney weierophinney [zendframework/zf2#3951] Add error handler for deprecation warning
- Added an error handler to catch the deprecation warning now emitted by
  Zend\Stdlib\DateTime
3efb86f
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-stdlib
@weierophinney weierophinney Merge branch 'feature/3951' into develop cc95b18
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-feed
@weierophinney weierophinney Merge pull request zendframework/zf2#3951 from DASPRiD/removal/stdlib…
…-datetime

Deprecate Zend\Stdlib\DateTime and use \DateTime constructor internally instead
08153af
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-feed
@weierophinney weierophinney Merge branch 'feature/3951' into develop a320b87
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 12, 2013
  1. @DASPRiD
This page is out of date. Refresh to see the latest.
View
6 library/Zend/Feed/Reader/Extension/Atom/Entry.php
@@ -9,13 +9,13 @@
namespace Zend\Feed\Reader\Extension\Atom;
+use DateTime;
use DOMDocument;
use DOMElement;
use stdClass;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Collection;
use Zend\Feed\Reader\Extension;
-use Zend\Stdlib\DateTime;
use Zend\Uri;
class Entry extends Extension\AbstractEntry
@@ -170,7 +170,7 @@ public function getDateCreated()
}
if ($dateCreated) {
- $date = DateTime::createFromISO8601($dateCreated);
+ $date = new DateTime($dateCreated);
}
$this->data['datecreated'] = $date;
@@ -198,7 +198,7 @@ public function getDateModified()
}
if ($dateModified) {
- $date = DateTime::createFromISO8601($dateModified);
+ $date = new DateTime($dateModified);
}
$this->data['datemodified'] = $date;
View
6 library/Zend/Feed/Reader/Extension/Atom/Feed.php
@@ -9,11 +9,11 @@
namespace Zend\Feed\Reader\Extension\Atom;
+use DateTime;
use DOMElement;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Collection;
use Zend\Feed\Reader\Extension;
-use Zend\Stdlib\DateTime;
use Zend\Uri;
class Feed extends Extension\AbstractFeed
@@ -120,7 +120,7 @@ public function getDateCreated()
}
if ($dateCreated) {
- $date = DateTime::createFromISO8601($dateCreated);
+ $date = new DateTime($dateCreated);
}
$this->data['datecreated'] = $date;
@@ -148,7 +148,7 @@ public function getDateModified()
}
if ($dateModified) {
- $date = DateTime::createFromISO8601($dateModified);
+ $date = new DateTime($dateModified);
}
$this->data['datemodified'] = $date;
View
4 library/Zend/Feed/Reader/Extension/DublinCore/Entry.php
@@ -9,10 +9,10 @@
namespace Zend\Feed\Reader\Extension\DublinCore;
+use DateTime;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Collection;
use Zend\Feed\Reader\Extension;
-use Zend\Stdlib\DateTime;
class Entry extends Extension\AbstractEntry
{
@@ -217,7 +217,7 @@ public function getDate()
}
if ($date) {
- $d = DateTime::createFromISO8601($date);
+ $d = new DateTime($date);
}
$this->data['date'] = $d;
View
4 library/Zend/Feed/Reader/Extension/DublinCore/Feed.php
@@ -9,10 +9,10 @@
namespace Zend\Feed\Reader\Extension\DublinCore;
+use DateTime;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Collection;
use Zend\Feed\Reader\Extension;
-use Zend\Stdlib\DateTime;
class Feed extends Extension\AbstractFeed
{
@@ -226,7 +226,7 @@ public function getDate()
}
if ($date) {
- $d = DateTime::createFromISO8601($date);
+ $d = new DateTime($date);
}
$this->data['date'] = $d;
View
4 library/Zend/Stdlib/DateTime.php
@@ -11,10 +11,14 @@
use DateTimeZone;
+trigger_error('DateTime extension deprecated as of ZF 2.1.4; use the \DateTime constructor to parse extended ISO8601 dates instead', E_USER_DEPRECATED);
+
/**
* DateTime
*
* An extension of the \DateTime object.
+ *
+ * @deprecated
*/
class DateTime extends \DateTime
{
View
20 tests/ZendTest/Feed/Reader/Entry/AtomTest.php
@@ -109,6 +109,16 @@ public function testGetsDateCreatedFromAtom10()
$this->assertEquals($edate, $entry->getDateCreated());
}
+ public function testGetsDateCreatedWithFractional()
+ {
+ $feed = Reader\Reader::importString(
+ file_get_contents($this->feedSamplePath . '/datecreated/plain/fractional.xml')
+ );
+ $entry = $feed->current();
+ $edate = DateTime::createFromFormat(DateTime::ISO8601, '2009-03-07T08:03:50Z');
+ $this->assertEquals($edate, $entry->getDateCreated());
+ }
+
/**
* Get modification date (Unencoded Text)
*/
@@ -132,6 +142,16 @@ public function testGetsDateModifiedFromAtom10()
$this->assertEquals($edate, $entry->getDateModified());
}
+ public function testGetsDateModifiedWithFractional()
+ {
+ $feed = Reader\Reader::importString(
+ file_get_contents($this->feedSamplePath . '/datemodified/plain/fractional.xml')
+ );
+ $entry = $feed->current();
+ $edate = DateTime::createFromFormat(DateTime::ISO8601, '2009-03-07T08:03:50Z');
+ $this->assertEquals($edate, $entry->getDateModified());
+ }
+
/**
* Get Title (Unencoded Text)
*/
View
6 tests/ZendTest/Feed/Reader/Entry/_files/Atom/datecreated/plain/fractional.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed version="0.3" xmlns="http://purl.org/atom/ns#">
+ <entry>
+ <created>2009-03-07T08:03:50.80Z</created>
+ </entry>
+</feed>
View
6 tests/ZendTest/Feed/Reader/Entry/_files/Atom/datemodified/plain/fractional.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed version="0.3" xmlns="http://purl.org/atom/ns#">
+ <entry>
+ <modified>2009-03-07T08:03:50.80Z</modified>
+ </entry>
+</feed>
Something went wrong with that request. Please try again.