Skip to content

Commit

Permalink
fixed date formats for different views
Browse files Browse the repository at this point in the history
  • Loading branch information
Roumen Damianoff committed Sep 23, 2014
1 parent 78cf09a commit 2cd1471
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
32 changes: 24 additions & 8 deletions src/Roumen/Feed/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,33 @@ public function setShortening($b=false)
*
* @return string
*/
private function formatDate($date)
private function formatDate($date, $format="atom")
{
switch ($this->dateFormat)
if ($format == "atom")
{
case "timestamp":
$date = date('c', $date);
break;
case "datetime":
$date = date('c', strtotime($date));
break;
switch ($this->dateFormat)
{
case "timestamp":
$date = date('c', $date);
break;
case "datetime":
$date = date('c', strtotime($date));
break;
}
}
else
{
switch ($this->dateFormat)
{
case "timestamp":
$date = date('D, d M Y H:i:s O', $date);
break;
case "datetime":
$date = date('D, d M Y H:i:s O', strtotime($date));
break;
}
}


return $date;
}
Expand Down
4 changes: 2 additions & 2 deletions src/views/atom.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@if (!empty($channel['icon']))
<icon>{{ $channel['icon'] }}</icon>
@endif
<updated>{{ date('c', strtotime($channel['pubdate'])) }}</updated>
<updated>{{ $channel['pubdate'] }}</updated>
@foreach($items as $item)
<entry>
<author>
Expand All @@ -22,7 +22,7 @@
<link rel="alternate" type="text/html" href="{{ $item['link'] }}"></link>
<id>{{ $item['link'] }}</id>
<summary type="html"><![CDATA[{{ $item['description'] }}]]></summary>
<updated>{{ date('c', strtotime($item['pubdate'])) }}</updated>
<updated>{{ $item['pubdate'] }}</updated>
</entry>
@endforeach

Expand Down
4 changes: 2 additions & 2 deletions src/views/rss.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</image>
@endif
<language>{{ $channel['lang'] }}</language>
<lastBuildDate>{{ date('D, d M Y H:i:s O', strtotime($channel['pubdate'])) }}</lastBuildDate>
<lastBuildDate>{{ $channel['pubdate'] }}</lastBuildDate>
@foreach($items as $item)
<item>
<title>{{ $item['title'] }}</title>
Expand All @@ -24,7 +24,7 @@
<content:encoded><![CDATA[{{ $item['content'] }}]]></content:encoded>
@endif
<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">{{ $item['author'] }}</dc:creator>
<pubDate>{{ date('D, d M Y H:i:s O', strtotime($item['pubdate'])) }}</pubDate>
<pubDate>{{ $item['pubdate'] }}</pubDate>
</item>
@endforeach
</channel>
Expand Down
2 changes: 1 addition & 1 deletion tests/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testFeedAdd()
$this->assertEquals('TestTitle', $this->feed->items[0]['title']);
$this->assertEquals('TestAuthor', $this->feed->items[0]['author']);
$this->assertEquals('TestUrl', $this->feed->items[0]['link']);
$this->assertEquals('2014-02-29 00:00:00', $this->feed->items[0]['pubdate']);
$this->assertEquals(date('c',strtotime("2014-02-29 00:00:00")), $this->feed->items[0]['pubdate']);
$this->assertEquals('<p>TestResume</p>', $this->feed->items[0]['description']);
$this->assertEquals('<p>TestContent</p>', $this->feed->items[0]['content']);
}
Expand Down

0 comments on commit 2cd1471

Please sign in to comment.