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

This commit is contained in:
Torkel Ödegaard 2016-06-21 21:00:00 +02:00
commit a7a5f36b49

View File

@ -1,8 +1,9 @@
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() {
@ -618,6 +658,17 @@ function($, _) {
{text: 'days (d)', value: 'd' },
]
},
{
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: [