diff --git a/package.json b/package.json index 9e0d898..c628f49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "publikator", - "version": "0.17.5", + "version": "0.17.7", "main": "index.js", "repository": "https://github.com/aengl/publikator.git", "author": "Lynn Smeria ", diff --git a/src/generate.js b/src/generate.js index 00114d7..f99230e 100644 --- a/src/generate.js +++ b/src/generate.js @@ -23,6 +23,18 @@ const collect = (tracks, callback) => { const find = (tracks, path) => _.get(tracks.find(track => !_.isNil(_.get(track, path))), path); +/** + * Parses a date and returns it in the form of `year-month-day`. + */ +const parseDate = s => { + if (!_.isNil(s)) { + const d = new Date(s.toString()); + if (!_.isNaN(d.getTime())) { + return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`; + } + } +}; + /** * Creates release information for a single album. */ @@ -34,13 +46,14 @@ const getAlbumInfo = (root, tracks) => ({ bitrate: collect(tracks, t => t.format.bitrate), trackCount: tracks.length, cover: find(tracks, 'cover'), - date: + date: parseDate( find(tracks, 'common.date') || - find(tracks, 'common.originaldate') || - find(tracks, 'all.ORIGINALDATE') || - find(tracks, 'common.year') || - find(tracks, 'common.originalyear') || - find(tracks, 'all.ORIGINALYEAR'), + find(tracks, 'common.originaldate') || + find(tracks, 'all.ORIGINALDATE') || + find(tracks, 'common.year') || + find(tracks, 'common.originalyear') || + find(tracks, 'all.ORIGINALYEAR') + ), tracks: _.sortBy(tracks, 'common.track.no'), });