From 577a85c9b1521f61e03884cef774e94dbba29318 Mon Sep 17 00:00:00 2001 From: Konstantin Mamalakis Date: Fri, 16 Mar 2018 17:54:44 +0200 Subject: [PATCH] Fixes --- lib/ofac/loading.js | 6 ++++++ lib/ofac/parsing.js | 4 +--- tests/ofac/parsing.js | 10 ++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/ofac/loading.js b/lib/ofac/loading.js index 84827a20..8c422977 100644 --- a/lib/ofac/loading.js +++ b/lib/ofac/loading.js @@ -54,6 +54,12 @@ const parseSource = source => { const readStream = fs.createReadStream(source) const jsonStream = readStream.pipe(ndjson.parse()) jsonStream.on('data', individual => { + _.forEach(period => { + _.forEach(date => { + const {year, month, day} = date + date.date = new Date(year, month - 1, day) + }, [period.start, period.end]) + }, individual.birthDatePeriods) individuals.push(individual) }) diff --git a/lib/ofac/parsing.js b/lib/ofac/parsing.js index 65c97d87..a62eb69f 100644 --- a/lib/ofac/parsing.js +++ b/lib/ofac/parsing.js @@ -93,9 +93,7 @@ function processDate (dateNode) { const year = parseInt(dateNode.Year) const month = parseInt(dateNode.Month) const day = parseInt(dateNode.Day) - const date = new Date(year, month - 1, day) - - return {year, month, day, date} + return {year, month, day} } function processFeature (featureNode) { diff --git a/tests/ofac/parsing.js b/tests/ofac/parsing.js index 982da6bb..b616d9c1 100644 --- a/tests/ofac/parsing.js +++ b/tests/ofac/parsing.js @@ -114,8 +114,8 @@ const individualA = {id: '9', aliases: [{id: '5', {value: 'john', phonetics: ['JN', 'AN']}, {value: 'doe', phonetics: ['T']}]}], birthDatePeriods: [{ - start: {year: 1955, month: 10, day: 5, date: new Date(1955, 9, 5)}, - end: {year: 1955, month: 10, day: 5, date: new Date(1955, 9, 5)}}] + start: {year: 1955, month: 10, day: 5}, + end: {year: 1955, month: 10, day: 5}}] } const individualB = {id: '11', aliases: [{id: '15', @@ -129,8 +129,8 @@ const individualB = {id: '11', aliases: [{id: '15', {value: 'de', phonetics: ['T']}, {value: 'gaul', phonetics: ['KL']}]}], birthDatePeriods: [{ - start: {year: 1965, month: 11, day: 20, date: new Date(1965, 10, 20)}, - end: {year: 1965, month: 11, day: 20, date: new Date(1965, 10, 20)}}] + start: {year: 1965, month: 11, day: 20}, + end: {year: 1965, month: 11, day: 20}}] } @@ -180,6 +180,8 @@ describe('OFAC', function () { .then(([individuals]) => { assert.ok(Array.isArray(individuals)) assert.equal(individuals.length, 2) + console.log(JSON.stringify(individuals[0])) + console.log(JSON.stringify(individualA)) assert.deepEqual(individuals, [individualA, individualB]) }) })