Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getAbsoluteMomentForTimezone(jsDate) {
return this.dashboard.isTimezoneUtc() ? dateTime(jsDate).utc() : dateTime(jsDate);
}
export function convertSeriesListToCsv(seriesList, dateTimeFormat = DEFAULT_DATETIME_FORMAT, excel = false) {
let text = formatSpecialHeader(excel) + formatRow(['Series', 'Time', 'Value']);
for (let seriesIndex = 0; seriesIndex < seriesList.length; seriesIndex += 1) {
for (let i = 0; i < seriesList[seriesIndex].datapoints.length; i += 1) {
text += formatRow(
[
seriesList[seriesIndex].alias,
dateTime(seriesList[seriesIndex].datapoints[i][POINT_TIME_INDEX]).format(dateTimeFormat),
seriesList[seriesIndex].datapoints[i][POINT_VALUE_INDEX],
],
i < seriesList[seriesIndex].datapoints.length - 1 || seriesIndex < seriesList.length - 1
);
}
}
return text;
}
getFrom(options: any) {
const from = options.range.from;
return `datetime(${dateTime(from)
.startOf('minute')
.toISOString()})`;
}
static dateTimeToEpoch(dateTimeValue: any) {
return dateTime(dateTimeValue).valueOf();
}
}
getUntil(options: any) {
if (options.rangeRaw.to === 'now') {
const now = Date.now();
return `datetime(${dateTime(now)
.startOf('minute')
.toISOString()})`;
} else {
const until = options.range.to;
return `datetime(${dateTime(until)
.startOf('minute')
.toISOString()})`;
}
}
getUntil(options: any) {
if (options.rangeRaw.to === 'now') {
const now = Date.now();
return `datetime(${dateTime(now)
.startOf('minute')
.toISOString()})`;
} else {
const until = options.range.to;
return `datetime(${dateTime(until)
.startOf('minute')
.toISOString()})`;
}
}
getIndexList(from, to) {
if (!this.interval) {
return this.pattern;
}
const intervalInfo = intervalMap[this.interval];
const start = dateTime(from)
.utc()
.startOf(intervalInfo.startOf);
const endEpoch = dateTime(to)
.utc()
.startOf(intervalInfo.startOf)
.valueOf();
const indexList = [];
while (start.valueOf() <= endEpoch) {
indexList.push(start.format(this.pattern));
start.add(1, intervalInfo.amount);
}
return indexList;
}
}
getIndexList(from, to) {
if (!this.interval) {
return this.pattern;
}
const intervalInfo = intervalMap[this.interval];
const start = dateTime(from)
.utc()
.startOf(intervalInfo.startOf);
const endEpoch = dateTime(to)
.utc()
.startOf(intervalInfo.startOf)
.valueOf();
const indexList = [];
while (start.valueOf() <= endEpoch) {
indexList.push(start.format(this.pattern));
start.add(1, intervalInfo.amount);
}
return indexList;
}
}