-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add parseDate option #273
Add parseDate option #273
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ function FeedParser (options) { | |
if (!('strict' in this.options)) this.options.strict = false; | ||
if (!('normalize' in this.options)) this.options.normalize = true; | ||
if (!('addmeta' in this.options)) this.options.addmeta = true; | ||
if (!('parseDate' in this.options)) this.options.parseDate = true; | ||
if (!('resume_saxerror' in this.options)) this.options.resume_saxerror = true; | ||
if ('MAX_BUFFER_LENGTH' in this.options) { | ||
sax.MAX_BUFFER_LENGTH = this.options.MAX_BUFFER_LENGTH; // set to Infinity to have unlimited buffers | ||
|
@@ -430,6 +431,7 @@ FeedParser.prototype.handleMeta = function handleMeta (node, type, options) { | |
|
||
var meta = {} | ||
, normalize = !options || (options && options.normalize) | ||
, parseDate = !options || (options && options.parseDate) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This logic will need to be flipped: |
||
; | ||
|
||
if (normalize) { | ||
|
@@ -461,6 +463,7 @@ FeedParser.prototype.handleMeta = function handleMeta (node, type, options) { | |
case('dc:date'): | ||
var date = _.get(el) ? new Date(_.get(el)) : null; | ||
if (!date) break; | ||
if (parseDate) date = date.toISOString(); | ||
if (meta.pubdate === null || name == 'pubdate' || name == 'published') | ||
meta.pubdate = meta.pubDate = date; | ||
if (meta.date === null || name == 'lastbuilddate' || name == 'modified' || name == 'updated') | ||
|
@@ -777,6 +780,7 @@ FeedParser.prototype.handleItem = function handleItem (node, type, options){ | |
|
||
var item = {} | ||
, normalize = !options || (options && options.normalize) | ||
, parseDate = !options || (options && options.parseDate) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. |
||
; | ||
|
||
if (normalize) { | ||
|
@@ -815,6 +819,7 @@ FeedParser.prototype.handleItem = function handleItem (node, type, options){ | |
case('dc:date'): | ||
var date = _.get(el) ? new Date(_.get(el)) : null; | ||
if (!date) break; | ||
if (parseDate) date = date.toISOString(); | ||
if (item.pubdate === null || name == 'pubdate' || name == 'published' || name == 'issued') | ||
item.pubdate = item.pubDate = date; | ||
if (item.date === null || name == 'modified' || name == 'updated') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've already parsed the date string into a
Date
object. With this option enabled, we'll actually be stringifying the date. So, let's rename this option: maybestringifydate
. (If you have a different suggestion, that's ok, but let's also ensure the option names are consistent -- one word, all lowercase.) (I know, I know, there'sresume_saxerror
which has an underscore -- 🤷♂️ )Also, we need to preserve the current behavior as the default, so if the option is not provided, it's value should be
false
.