-
Notifications
You must be signed in to change notification settings - Fork 55
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 #137 from alexdebril/issue/134
Issue/134
- Loading branch information
Showing
4 changed files
with
162 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/* | ||
* This file is part of the feed-io package. | ||
* | ||
* (c) Alexandre Debril <alex.debril@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
require __DIR__.DIRECTORY_SEPARATOR.'bootstrap.php'; | ||
|
||
$feedIo = \FeedIo\Factory::create()->getFeedIo(); | ||
|
||
$feedIo->getDateTimeBuilder()->setFeedTimezone(new \DateTimeZone('-0500')); | ||
$result = $feedIo->read('http://news.php.net/group.php?group=php.announce&format=rss'); | ||
|
||
echo "First item's pubDate raw value in the feed" .PHP_EOL; | ||
|
||
$domItems = $result->getDocument()->getDOMDocument()->getElementsByTagName('item'); | ||
|
||
/** @var \DOMElement $firstDomItem */ | ||
$firstDomItem = $domItems->item(0); | ||
$pubDate = $firstDomItem->getElementsByTagName('pubDate')->item(0); | ||
|
||
var_dump($pubDate->nodeValue); | ||
|
||
$pubDateTime = new \DateTime($pubDate->nodeValue); | ||
|
||
echo "here is its timestamp : {$pubDateTime->getTimestamp()}" . PHP_EOL; | ||
|
||
$feed = $result->getFeed(); | ||
|
||
/** @var \FeedIo\Feed\ItemInterface $item */ | ||
$feed->rewind(); | ||
$item = $feed->current(); | ||
|
||
echo "var_dump the first item's pubDate after parsing. It's the same date converted in your local configuration's timezone" . PHP_EOL; | ||
var_dump($item->getLastModified()); | ||
echo "here is its timestamp : {$item->getLastModified()->getTimestamp()}" . PHP_EOL; | ||
|
||
if($pubDateTime->getTimestamp() === $item->getLastModified()->getTimestamp()) { | ||
echo "HOURAY, both timestamps match !" . PHP_EOL; | ||
} |
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,39 @@ | ||
<?php | ||
/* | ||
* This file is part of the feed-io package. | ||
* | ||
* (c) Alexandre Debril <alex.debril@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
require __DIR__.DIRECTORY_SEPARATOR.'bootstrap.php'; | ||
|
||
echo 'see https://github.com/alexdebril/feed-io/issues/134 for full explanations' . PHP_EOL; | ||
|
||
$dateTimeBuilder = new \FeedIo\Rule\DateTimeBuilder(); | ||
$pubDate = 'Wed, 02 Aug 2017 07:21:29'; | ||
|
||
echo 'the publish date\'s timezone is America/chicago but $dateTimeBuilder ignores it. The date below is wrong' . PHP_EOL; | ||
|
||
$dateTime = $dateTimeBuilder->convertToDateTime($pubDate); | ||
|
||
var_dump($dateTime); | ||
echo "timestamp : {$dateTime->getTimestamp()}" . PHP_EOL; | ||
|
||
echo 'after setting the feed\'s timezone in the builder\'s attributes, the date is right' . PHP_EOL; | ||
|
||
$dateTimeBuilder->setFeedTimezone(new \DateTimeZone('America/Chicago')); | ||
|
||
$dateTime = $dateTimeBuilder->convertToDateTime($pubDate); | ||
|
||
var_dump($dateTime); | ||
echo "timestamp : {$dateTime->getTimestamp()}" . PHP_EOL; | ||
|
||
echo 'if I really want the date in its original timezone, I can set it' . PHP_EOL; | ||
|
||
$dateTime->setTimezone(new \DateTimeZone('America/Chicago')); | ||
|
||
var_dump($dateTime); | ||
echo "timestamp : {$dateTime->getTimestamp()}" . PHP_EOL; |
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