Commit a7a5f36b by Torkel Ödegaard

Merge branch 'issue-2971' of https://github.com/alexanderzobnin/grafana into…

Merge branch 'issue-2971' of https://github.com/alexanderzobnin/grafana into alexanderzobnin-issue-2971
parents 53c424ca ab0155c8
define([
'jquery',
'lodash',
'moment'
],
function($, _) {
function($, _, moment) {
'use strict';
var kbn = {};
......@@ -580,6 +581,45 @@ function($, _) {
}
};
// Date and time
kbn.toDateTime = function(size, timeScale) {
var datetime;
if (timeScale === 's') {
datetime = moment.unix(size);
} else {
datetime = moment(size);
}
return datetime;
};
kbn.toDuration = function(size, timeScale) {
return moment.duration(size, timeScale);
};
kbn.valueFormats.dtms = function(size) {
return kbn.toDateTime(size, 'ms').format('YYYY-MM-DD hh:mm:ss');
};
kbn.valueFormats.dts = function(size) {
return kbn.toDateTime(size, 's').format('YYYY-MM-DD hh:mm:ss');
};
kbn.valueFormats.dtfromnowms = function(size) {
return kbn.toDateTime(size, 'ms').fromNow(true);
};
kbn.valueFormats.dtfromnows = function(size) {
return kbn.toDateTime(size, 's').fromNow(true);
};
kbn.valueFormats.dtdurationms = function(size) {
return kbn.toDuration(size, 'ms').humanize();
};
kbn.valueFormats.dtdurations = function(size) {
return kbn.toDuration(size, 's').humanize();
};
///// FORMAT MENU /////
kbn.getUnitFormats = function() {
......@@ -619,6 +659,17 @@ function($, _) {
]
},
{
text: 'date and time',
submenu: [
{text: 'date and time (ms)', value: 'dtms'},
{text: 'date and time (s)', value: 'dts' },
{text: 'from now (ms)', value: 'dtfromnowms' },
{text: 'from now (s)', value: 'dtfromnows' },
{text: 'duration (ms)', value: 'dtdurationms' },
{text: 'duration (s)', value: 'dtdurations' }
]
},
{
text: 'data',
submenu: [
{text: 'bits', value: 'bits' },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment