塔地丝
临时财产 执行情况 读取所显示的数据.
安装
npm install @georges-tech/tardis
使用量
您通过 Tardis 创建服务 createHistoryService 通过提供一系列文档 必须 包含
下列属性:
/**
* Date at which the configuration starts to be valid
*/
effective_date: Date;
/**
* Date at which the new configuration has been created
*/
known_at: Date;
/**
* Optional end date for limited time configurations
*/
end_date?: Date;
您可以随意添加多少属性, 取决于您的使用大小写, 这些属性会被服务返回 .
文件可包含一个计算公式 end_date,是下一个有效的文件日期,如果它存在。 否则,它
实值 undefined。 。 。 .
在创建服务时,您可以提供相关时间段的工作日期.
示例
import tardis from '@georges-tech/tardis';
const documents = [{
effective_date: new Date('2020-01-01'),
known_at: new Date('2020-05-01'),
data: {
value: 'old',
}
}, {
effective_date: new Date('2020-03-01'),
known_at: new Date('2020-10-01'),
data: {
value: 'new',
}
}]
const historyService = tardis.createHistoryService({ documents });
const januaryConfiguration = historyService.getConfigurationAtDate({ date: new Date('2020-01-03') });
// januaryConfiguration.data.value = 'old'
// januaryConfiguration.end_date = new Date('2020-03-01')
const mayConfiguration = historyService.getConfigurationAtDate({ date: new Date('2020-05-03') });
// mayConfiguration.data.value = 'new'
// mayConfiguration.end_date = undefined
特定日期
import tardis from '@georges-tech/tardis';
const documents = [{
effective_date: new Date('2020-01-01'),
known_at: new Date('2020-05-01'),
data: {
value: 'old',
}
}, {
effective_date: new Date('2020-03-01'),
known_at: new Date('2020-10-01'),
data: {
value: 'new',
},
{
effective_date: new Date('2020-04-01'),
known_at: new Date('2020-12-01'),
data: {
value: 'new 2',
}
}]
const historyService = tardis.createHistoryService({ documents, date: new Date('2020-11-01') });
const januaryConfiguration = historyService.getConfigurationAtDate({ date: new Date('2020-01-03') });
// januaryConfiguration.data.value = 'old'
// januaryConfiguration.end_date = new Date('2020-03-01')
const mayConfiguration = historyService.getConfigurationAtDate({ date: new Date('2020-05-03') });
// mayConfiguration.data.value = 'new'
// mayConfiguration.end_date = undefined
// Here we keep the configuration known on 01/10 because on the given date we did not yet know the "new2" configuration