Skip to content

Commit

Permalink
fix(metascrapper-date): chrono as defalt date parser fix microlinkhq#241
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaGanzin committed Dec 10, 2019
1 parent 87576a1 commit 1418093
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 0 additions & 4 deletions packages/metascraper-helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ const date = value => {
// convert isodates to restringify, because sometimes they are truncated
if (isIso(value)) return new Date(value).toISOString()

// try to parse with the built-in date parser
const native = new Date(value)
if (!isNaN(native.getTime())) return native.toISOString()

// try to parse a complex date string
const parsed = chrono.parseDate(value)
if (parsed) return parsed.toISOString()
Expand Down
8 changes: 7 additions & 1 deletion packages/metascraper-helpers/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const {
url,
jsonld,
titleize,
hasValue
has,
date
} = require('..')

describe('metascraper-helpers', () => {
Expand Down Expand Up @@ -266,6 +267,11 @@ describe('metascraper-helpers', () => {
).be.equal('Wikipedia: #Edit2014')
})
})
it('.date', () => {
should(date('Jun 20')).be.equal('2019-06-20T12:00:00.000Z')
should(date('Jun 20 2018')).be.equal('2018-06-20T12:00:00.000Z')
should(date('Jun 2018')).be.equal('2018-06-01T12:00:00.000Z')
})
})

describe('.hasValue', () => {
Expand Down

0 comments on commit 1418093

Please sign in to comment.