@georges-tech/tardis
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -17,5 +17,4 @@ "use strict"; | ||
function _getConfigurationsOnDateRange({ configurationTimeline, startDate, endDate, }) { | ||
return lodash_1.default.filter(configurationTimeline, (configuration) => moment_1.default(configuration.effective_date).isSameOrAfter(startDate) && | ||
moment_1.default(configuration.effective_date).isBefore(endDate) && | ||
(!configuration.end_date || moment_1.default(configuration.end_date).isBefore(endDate))); | ||
return lodash_1.default.filter(configurationTimeline, (configuration) => moment_1.default(configuration.effective_date).isBetween(startDate, endDate, 'ms', '[)') || | ||
moment_1.default(configuration.effective_date).isBefore(startDate) && (!configuration.end_date || moment_1.default(configuration.end_date).isAfter(startDate))); | ||
} | ||
@@ -22,0 +21,0 @@ function filterEffectiveDocuments({ filteredDocuments = [], orderedDocuments, }) { |
{ | ||
"name": "@georges-tech/tardis", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Temporal property implementation for reading historized data", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
@@ -326,4 +326,61 @@ import chai from 'chai'; | ||
}); | ||
it('should known all valid configurations between a start and end date with three effective configurations', () => { | ||
const historyService = createHistoryService({ documents: [ | ||
{ | ||
known_at : new Date("2020-01-20"), | ||
effective_date: new Date("2000-01-01"), | ||
data: { | ||
number: 1, | ||
}, | ||
}, | ||
{ | ||
known_at : new Date("2020-02-20"), | ||
effective_date : new Date("2019-03-01"), | ||
data: { | ||
number: 2, | ||
}, | ||
}, | ||
{ | ||
known_at: new Date("2020-03-20"), | ||
effective_date : new Date("2019-10-01"), | ||
data: { | ||
number: 3, | ||
}, | ||
}, | ||
]}); | ||
expect( | ||
historyService.getConfigurationsOnDateRange({ | ||
startDate: new Date('2019-01-01'), | ||
endDate: new Date('2019-12-31'), | ||
}) | ||
).to.deep.equal([ | ||
{ | ||
known_at : new Date("2020-01-20"), | ||
effective_date: new Date("2000-01-01"), | ||
end_date : new Date("2019-03-01"), | ||
data: { | ||
number: 1, | ||
}, | ||
},{ | ||
known_at : new Date("2020-02-20"), | ||
effective_date : new Date("2019-03-01"), | ||
end_date : new Date("2019-10-01"), | ||
data: { | ||
number: 2, | ||
}, | ||
}, | ||
{ | ||
known_at: new Date("2020-03-20"), | ||
effective_date : new Date("2019-10-01"), | ||
end_date : undefined, | ||
data: { | ||
number: 3, | ||
}, | ||
}]); | ||
}); | ||
}) | ||
}); | ||
}); |
20468
476