2017-09-28 05:52:39 -05:00
|
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
const intervalMap = {
|
|
|
|
"Hourly": { startOf: 'hour', amount: 'hours'},
|
|
|
|
"Daily": { startOf: 'day', amount: 'days'},
|
|
|
|
"Weekly": { startOf: 'isoWeek', amount: 'weeks'},
|
|
|
|
"Monthly": { startOf: 'month', amount: 'months'},
|
|
|
|
"Yearly": { startOf: 'year', amount: 'years'},
|
|
|
|
};
|
|
|
|
|
|
|
|
export class IndexPattern {
|
|
|
|
|
|
|
|
constructor(private pattern, private interval: string | null) { }
|
|
|
|
|
|
|
|
getIndexForToday() {
|
|
|
|
if (this.interval) {
|
|
|
|
return moment.utc().format(this.pattern);
|
|
|
|
} else {
|
|
|
|
return this.pattern;
|
|
|
|
}
|
2017-10-07 03:31:39 -05:00
|
|
|
}
|
2017-09-28 05:52:39 -05:00
|
|
|
|
|
|
|
getIndexList(from, to) {
|
|
|
|
if (!this.interval) {
|
|
|
|
return this.pattern;
|
|
|
|
}
|
|
|
|
|
|
|
|
var intervalInfo = intervalMap[this.interval];
|
|
|
|
var start = moment(from).utc().startOf(intervalInfo.startOf);
|
2017-10-03 11:27:25 -05:00
|
|
|
var endEpoch = moment(to).utc().startOf(intervalInfo.startOf).valueOf();
|
2017-09-28 05:52:39 -05:00
|
|
|
var indexList = [];
|
|
|
|
|
2017-10-03 12:38:52 -05:00
|
|
|
while (start.valueOf() <= endEpoch) {
|
2017-09-28 05:52:39 -05:00
|
|
|
indexList.push(start.format(this.pattern));
|
|
|
|
start.add(1, intervalInfo.amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
return indexList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|