Skip to content

Commit 68f5673

Browse files
Harrison IfeanyichukwuHarrison Ifeanyichukwu
Harrison Ifeanyichukwu
authored and
Harrison Ifeanyichukwu
committed
fix: fixed dates
1 parent d66fd2d commit 68f5673

File tree

8 files changed

+12
-87
lines changed

8 files changed

+12
-87
lines changed

README.md

-10
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ The following configuration options can be passed in when creating an instance o
8888
//constructor signature
8989
new Parser(
9090
string $default_lang = 'en',
91-
string $date_template = '',
9291
bool $remove_styles = true,
9392
bool $remove_scripts = true
9493
);
@@ -103,15 +102,6 @@ new Parser(
103102
$parser->setDefaultLanguage('fr');
104103
```
105104

106-
- **date_template**:
107-
108-
This option sets the date formatter template used when parsing feed date properties such as `lastUpdated`. the default format used is `'jS F, Y, g:i A'`. The formatter template should be a valid php date formatter argument. see [date](http://php.net/manual/en/function.date.php) for details.
109-
110-
```php
111-
$parser = new Parser();
112-
$parser->setDateTemplate('jS F, y, g:i a');
113-
```
114-
115105
- **remove_styles**:
116106

117107
This option states if stylings found in any feed item's content, should be stripped off. The stylings include html `style` element and attribute. Defaults to true.

src/FeedItems/ATOMFeedItem.php

-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ public function __construct(DOMElement $item, XPath $xpath, array $parser_option
4444
//date construct
4545
'lastUpdated' => 'atom:updated || atom:source/atom:updated || atom:published || atom:source/atom:published',
4646

47-
//date construct
48-
'createdAtTimestamp' => 'atom:published || atom:source/atom:published || atom:updated || atom:source/atom:updated',
49-
50-
//date construct
51-
'lastUpdatedTimestamp' => 'atom:updated || atom:source/atom:updated || atom:published || atom:source/atom:published',
52-
5347
'author' => 'atom:author/atom:name || atom:source/atom:author/atom:name || ' .
5448
'parent::atom:feed/atom:author/atom:name',
5549

src/FeedItems/BaseFeedItem.php

-10
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,6 @@ class BaseFeedItem
7777
*/
7878
protected $_lastUpdated = '';
7979

80-
/**
81-
* timestamp describing when this feed item was created
82-
*/
83-
protected $_createdAtTimestamp = '';
84-
85-
/**
86-
* timestamp describing when this feed item was last updated
87-
*/
88-
protected $_lastUpdatedTimestamp = '';
89-
9080
/**
9181
* what category does this feed item belong to
9282
*/

src/FeedItems/RDFFeedItem.php

-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ public function __construct(DOMElement $item, XPath $xpath, array $parser_option
2828
'createdAt' => 'dc:date', // a date construct
2929
'lastUpdated' => 'dc:date', // a date construct
3030

31-
'createdAtTimestamp' => 'dc:date', // a date construct
32-
'lastUpdatedTimestamp' => 'dc:date', // a date construct
33-
3431
'author' => 'dc:creator || dc:contributor',
3532
'category' => 'dc:coverage || dc:subject/taxo:topic/@rdf:value || dc:subject || ' .
3633
'parent::rdf:RDF/def:channel/dc:coverage || ' .

src/FeedItems/RSSFeedItem.php

-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ public function __construct(DOMElement $item, XPath $xpath, array $parser_option
2828
'createdAt' => 'pubDate',
2929
'lastUpdated' => 'lastBuildDate || pubDate',
3030

31-
'createdAtTimestamp' => 'pubDate',
32-
'lastUpdatedTimestamp' => 'lastBuildDate || pubDate',
33-
3431
'author' => 'author || dc:creator',
3532
'category' => 'category'
3633
];

src/Parser.php

+1-26
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class Parser
3535
*/
3636
private $_options = [
3737
'remove-styles' => null,
38-
'remove-scripts' => null,
39-
'date-template' => ''
38+
'remove-scripts' => null
4039
];
4140

4241
/**
@@ -49,12 +48,10 @@ class Parser
4948
*/
5049
public function __construct(
5150
string $default_lang = 'en',
52-
string $date_template = '',
5351
bool $remove_styles = true,
5452
bool $remove_scripts = true
5553
) {
5654
$this->setDefaultLanguage($default_lang);
57-
$this->setDateTemplate($date_template);
5855
$this->removeStyles($remove_styles);
5956
$this->removeScripts($remove_scripts);
6057
}
@@ -76,28 +73,6 @@ public function getDefaultLanguage()
7673
return $this->_default_lang;
7774
}
7875

79-
/**
80-
* sets date template used when processing dates
81-
*/
82-
public function setDateTemplate(string $date_template)
83-
{
84-
if ($date_template !== '')
85-
$this->_options['date-template'] = $date_template;
86-
87-
else if ($this->_options['date-template'] === '')
88-
$this->_options['date-template'] = 'jS F, Y, g:i A';
89-
90-
return $this;
91-
}
92-
93-
/**
94-
* return date template used when processing dates
95-
*/
96-
public function getDateTemplate()
97-
{
98-
return $this->_options['date-template'];
99-
}
100-
10176
/**
10277
* sets or returns the remove styles parse attributes
10378
*

src/Traits/Parser.php

+5-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Forensic\FeedParser\XPath;
88

9-
109
trait Parser
1110
{
1211
private function filterPropertyValue(
@@ -19,16 +18,11 @@ private function filterPropertyValue(
1918
}
2019

2120
switch ($property_name) {
22-
case 'lastUpdated':
23-
case 'createdAt':
24-
$timestamp = strtotime($value);
25-
$value = date($parser_options['date-template'], $timestamp);
26-
break;
27-
28-
case 'lastUpdatedTimestamp':
29-
case 'createdAtTimestamp':
30-
$value = strtotime($value) * 1000;
31-
break;
21+
// case 'lastUpdated':
22+
// case 'createdAt':
23+
// $timestamp = strtotime($value);
24+
// $value = date($parser_options['date-template'], $timestamp);
25+
// break;
3226

3327
case 'textContent':
3428
$value = \strip_tags($value);

tests/ParserTest.php

+6-18
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ public function testDefaultLanguage()
3030
$this->assertSame('en', $this->_parser->getDefaultLanguage());
3131
}
3232

33-
public function testDefaultDateTemplate()
34-
{
35-
$this->assertEquals('jS F, Y, g:i A', $this->_parser->getDateTemplate());
36-
}
37-
3833
public function testDefaultRemoveStyles()
3934
{
4035
$this->assertTrue($this->_parser->removeStyles());
@@ -51,12 +46,6 @@ public function testUpdateDefaultLanguage()
5146
$this->assertSame('fr', $this->_parser->getDefaultLanguage());
5247
}
5348

54-
public function testUpdateDateTemplate()
55-
{
56-
$this->_parser->setDateTemplate('jS f, Y, g:i A');
57-
$this->assertSame('jS f, Y, g:i A', $this->_parser->getDateTemplate());
58-
}
59-
6049
public function testUpdateRemoveStyles()
6150
{
6251
$this->_parser->removeStyles(false);
@@ -71,7 +60,7 @@ public function testUpdateRemoveScripts()
7160

7261
public function testConstructSettings()
7362
{
74-
$parser = new Parser('fr', '', false, false);
63+
$parser = new Parser('fr', false, false);
7564
$this->assertSame('fr', $parser->getDefaultLanguage());
7665
$this->assertFalse($parser->removeStyles());
7766
$this->assertFalse($parser->removeScripts());
@@ -133,7 +122,7 @@ public function testFromExistingURL()
133122

134123
public function testFromString()
135124
{
136-
$parser = new Parser('en', '', false, false);
125+
$parser = new Parser('en', false, false);
137126
$feed = $parser->parseFromString(
138127
file_get_contents(__DIR__ . '/Helpers/Feeds/atom.xml')
139128
);
@@ -145,7 +134,7 @@ public function testFromString()
145134
*/
146135
public function testFeedExistingPropertyAccessibility()
147136
{
148-
$parser = new Parser('en', '', false, false);
137+
$parser = new Parser('en', false, false);
149138
$feed = $parser->parseFromString(
150139
file_get_contents(__DIR__ . '/Helpers/Feeds/atom.xml')
151140
);
@@ -157,7 +146,7 @@ public function testFeedExistingPropertyAccessibility()
157146
*/
158147
public function testFeedNonExistingPropertyAccessibility()
159148
{
160-
$parser = new Parser('en', '', false, false);
149+
$parser = new Parser('en', false, false);
161150
$feed = $parser->parseFromString(
162151
file_get_contents(__DIR__ . '/Helpers/Feeds/atom.xml')
163152
);
@@ -169,7 +158,7 @@ public function testFeedNonExistingPropertyAccessibility()
169158
*/
170159
public function testFeedItemExistingPropertyAccessibility()
171160
{
172-
$parser = new Parser('en', '', false, false);
161+
$parser = new Parser('en', false, false);
173162
$feed = $parser->parseFromString(
174163
file_get_contents(__DIR__ . '/Helpers/Feeds/atom.xml')
175164
);
@@ -181,7 +170,7 @@ public function testFeedItemExistingPropertyAccessibility()
181170
*/
182171
public function testFeedItemNonExistingPropertyAccessibility()
183172
{
184-
$parser = new Parser('en', '', false, false);
173+
$parser = new Parser('en', false, false);
185174
$feed = $parser->parseFromString(
186175
file_get_contents(__DIR__ . '/Helpers/Feeds/atom.xml')
187176
);
@@ -229,7 +218,6 @@ public function testFeedToJSONMethod()
229218
public function testFeedItemToJSONMethod()
230219
{
231220
$feed = $this->_parser->parseFromFile(__DIR__ . '/Helpers/Feeds/rss.xml');
232-
echo $feed->items[0]->toJSON();
233221
$this->assertTrue(is_string($feed->items[0]->toJSON()));
234222
}
235223
}

0 commit comments

Comments
 (0)