Skip to content

Commit

Permalink
fix: parse years
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Dec 17, 2019
1 parent e470111 commit c65f73e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/metascraper-helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
replace,
size,
toLower,
toString,
trim
} = require('lodash')

Expand Down Expand Up @@ -197,6 +198,10 @@ const date = value => {
// convert isodates to restringify, because sometimes they are truncated
if (isIso(value)) return new Date(value).toISOString()

if (/^\d{4}$/.test(value)) {
return new Date(toString(value)).toISOString()
}

const parsed = chrono.parseDate(value)
if (isDate(parsed)) return parsed.toISOString()
}
Expand Down
1 change: 1 addition & 0 deletions packages/metascraper-helpers/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ describe('metascraper-helpers', () => {
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')
should(date(2010)).be.equal('2010-01-01T00:00:00.000Z')
})
})

Expand Down

0 comments on commit c65f73e

Please sign in to comment.