本文整理汇总了TypeScript中@grafana/ui/src/utils/moment_wrapper.toUtc函数的典型用法代码示例。如果您正苦于以下问题:TypeScript toUtc函数的具体用法?TypeScript toUtc怎么用?TypeScript toUtc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了toUtc函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: toUtc
const parseRawTime = (value): TimeFragment => {
if (value === null) {
return null;
}
if (value.indexOf('now') !== -1) {
return value;
}
if (value.length === 8) {
return toUtc(value, 'YYYYMMDD');
}
if (value.length === 15) {
return toUtc(value, 'YYYYMMDDTHHmmss');
}
// Backward compatibility
if (value.length === 19) {
return toUtc(value, 'YYYY-MM-DD HH:mm:ss');
}
if (!isNaN(value)) {
const epoch = parseInt(value, 10);
return toUtc(epoch);
}
return null;
};
示例2: beforeEach
beforeEach(() => {
builder = new AzureMonitorFilterBuilder(
'Percentage CPU',
toUtc('2017-08-22 06:00'),
toUtc('2017-08-22 07:00'),
'PT1H',
'3m'
);
});
示例3: zoomOut
zoomOut(e: any, factor: number) {
const range = this.timeRange();
const timespan = range.to.valueOf() - range.from.valueOf();
const center = range.to.valueOf() - timespan / 2;
const to = center + (timespan * factor) / 2;
const from = center - (timespan * factor) / 2;
this.setTime({ from: toUtc(from), to: toUtc(to) });
}
示例4: beforeEach
beforeEach(async () => {
createDatasource({
url: 'http://es.com',
index: '[asd-]YYYY.MM.DD',
jsonData: { interval: 'Daily', esVersion: '2' },
});
ctx.backendSrv.datasourceRequest = jest.fn(options => {
requestOptions = options;
return Promise.resolve({
data: {
responses: [
{
aggregations: {
'1': {
buckets: [
{
doc_count: 10,
key: 1000,
},
],
},
},
},
],
},
});
});
query = {
range: {
from: toUtc([2015, 4, 30, 10]),
to: toUtc([2015, 5, 1, 10]),
},
targets: [
{
alias: '$varAlias',
bucketAggs: [{ type: 'date_histogram', field: '@timestamp', id: '1' }],
metrics: [{ type: 'count', id: '1' }],
query: 'escape\\:test',
},
],
};
result = await ctx.ds.query(query);
parts = requestOptions.data.split('\n');
header = angular.fromJson(parts[0]);
});
示例5: toUtc
const fromUser = text => {
if (text.indexOf('now') !== -1) {
if (!dateMath.isValid(text)) {
ngModel.$setValidity('error', false);
return undefined;
}
ngModel.$setValidity('error', true);
return text;
}
let parsed;
if ($scope.ctrl.isUtc) {
parsed = toUtc(text, format);
} else {
parsed = dateTime(text, format);
}
if (!parsed.isValid()) {
ngModel.$setValidity('error', false);
return undefined;
}
ngModel.$setValidity('error', true);
return parsed;
};
示例6: getIndexForToday
getIndexForToday() {
if (this.interval) {
return toUtc().format(this.pattern);
} else {
return this.pattern;
}
}
示例7: describe
describe('When performing query', () => {
const options = {
range: {
from: toUtc('2017-08-22T20:00:00Z'),
to: toUtc('2017-08-22T23:59:00Z'),
},
rangeRaw: {
from: 'now-4h',
to: 'now',
},
targets: [
{
refId: 'A',
},
],
};
describe('and no time series data is returned', () => {
let ds;
const response = {
results: {
A: {
refId: 'A',
meta: {
rawQuery: 'arawquerystring',
},
series: null,
tables: null,
},
},
};
beforeEach(() => {
const backendSrv = ({
datasourceRequest: async () => Promise.resolve({ status: 200, data: response }),
} as unknown) as BackendSrv;
ds = new StackdriverDataSource(instanceSettings, backendSrv, templateSrv, timeSrv);
});
it('should return a list of datapoints', () => {
return ds.query(options).then(results => {
expect(results.data.length).toBe(0);
});
});
});
});
示例8: parseUrlParam
private parseUrlParam(value: any) {
if (value.indexOf('now') !== -1) {
return value;
}
if (value.length === 8) {
return toUtc(value, 'YYYYMMDD');
}
if (value.length === 15) {
return toUtc(value, 'YYYYMMDDTHHmmss');
}
if (!isNaN(value)) {
const epoch = parseInt(value, 10);
return toUtc(epoch);
}
return null;
}
示例9: onMouseUp
onMouseUp() {
$(document).unbind('mouseup', this.mouseUpHandler.bind(this));
this.mouseUpHandler = null;
this.selection.active = false;
const selectionRange = Math.abs(this.selection.x2 - this.selection.x1);
if (this.selection.x2 >= 0 && selectionRange > MIN_SELECTION_WIDTH) {
const timeFrom = this.xScale.invert(Math.min(this.selection.x1, this.selection.x2) - this.yAxisWidth);
const timeTo = this.xScale.invert(Math.max(this.selection.x1, this.selection.x2) - this.yAxisWidth);
this.ctrl.timeSrv.setTime({
from: toUtc(timeFrom),
to: toUtc(timeTo),
});
}
this.clearSelection();
}
示例10: getFieldFromSource
return this.post('_msearch', payload).then(res => {
const list = [];
const hits = res.responses[0].hits.hits;
const getFieldFromSource = (source, fieldName) => {
if (!fieldName) {
return;
}
const fieldNames = fieldName.split('.');
let fieldValue = source;
for (let i = 0; i < fieldNames.length; i++) {
fieldValue = fieldValue[fieldNames[i]];
if (!fieldValue) {
console.log('could not find field in annotation: ', fieldName);
return '';
}
}
return fieldValue;
};
for (let i = 0; i < hits.length; i++) {
const source = hits[i]._source;
let time = getFieldFromSource(source, timeField);
if (typeof hits[i].fields !== 'undefined') {
const fields = hits[i].fields;
if (_.isString(fields[timeField]) || _.isNumber(fields[timeField])) {
time = fields[timeField];
}
}
const event = {
annotation: annotation,
time: toUtc(time).valueOf(),
text: getFieldFromSource(source, textField),
tags: getFieldFromSource(source, tagsField),
};
// legacy support for title tield
if (annotation.titleField) {
const title = getFieldFromSource(source, annotation.titleField);
if (title) {
event.text = title + '\n' + event.text;
}
}
if (typeof event.tags === 'string') {
event.tags = event.tags.split(',');
}
list.push(event);
}
return list;
});