Skip to content

fix(metascrapper-date): chrono as default date parser fix #241 #244

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

Merged
merged 3 commits into from
Dec 13, 2019

Conversation

slavaGanzin
Copy link
Contributor

No description provided.

@slavaGanzin slavaGanzin changed the title fix(metascrapper-date): chrono as defalt date parser fix #241 fix(metascrapper-date): chrono as default date parser fix #241 Dec 10, 2019
// try to parse a complex date string
const parsed = chrono.parseDate(value)
const parsed = chrono.parseDate(value, new Date(''), { forwardDate: true }) // magick
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slavaGanzin can you explain why these additional parameters are necessary? I don't understand it 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mainly because

> new Date('')
Invalid Date

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kikobeats I'm not sure why it works, but it was the only way I can get from chrono to convert any date without year to current year. Because in publishing if year is not specified it means "this year". TechCrunch and Substack, for example, do so

But chrono make some bogus assumptions:

SyntaxError: Unexpected identifier
> require('chrono-node').parseDate('Jan 20')
2020-01-20T10:00:00.000Z
> require('chrono-node').parseDate('May 20')
2020-05-20T09:00:00.000Z
> require('chrono-node').parseDate('Sep 20')
2019-09-20T09:00:00.000Z
> require('chrono-node').parseDate('Dec 20')
2019-12-20T10:00:00.000Z

While explaining issue I found better way:

> require('chrono-node').parseDate('Jan 10', String(new Date().getFullYear()), {forwardDate: true})

So this should be 'default', add this please

Verified

This commit was signed with the committer’s verified signature.
Kikobeats Kiko Beats

Verified

This commit was signed with the committer’s verified signature.
Kikobeats Kiko Beats
@coveralls
Copy link
Collaborator

Coverage Status

Coverage remained the same at 96.341% when pulling 2c32ad5 on slavaGanzin:chrono-sync into 1da49c2 on microlinkhq:master.

@Kikobeats Kikobeats merged commit 87e40fe into microlinkhq:master Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants