From 398e9f5195840db8312a95d193483b4923a766a1 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Fri, 17 Jun 2016 17:30:14 +0300 Subject: [PATCH] issue #4747 - add date and time units to singlestat panel. --- public/app/core/utils/kbn.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/public/app/core/utils/kbn.js b/public/app/core/utils/kbn.js index f54979b0e97..dbcf41f30e7 100644 --- a/public/app/core/utils/kbn.js +++ b/public/app/core/utils/kbn.js @@ -1,8 +1,9 @@ define([ 'jquery', 'lodash', + 'moment' ], -function($, _) { +function($, _, moment) { 'use strict'; var kbn = {}; @@ -580,6 +581,20 @@ function($, _) { } }; + // Date and time + kbn.toDateTime = function(size, timeScale) { + var datetime = moment(size * timeScale); + return datetime.format('YYYY-MM-DD hh:mm:ss'); + }; + + kbn.valueFormats.datems = function(size) { + return kbn.toDateTime(size, 1000); + }; + + kbn.valueFormats.dates = function(size) { + return kbn.toDateTime(size, 1); + }; + ///// FORMAT MENU ///// kbn.getUnitFormats = function() { @@ -618,6 +633,13 @@ function($, _) { {text: 'days (d)', value: 'd' }, ] }, + { + text: 'date and time', + submenu: [ + {text: 'date (ms)', value: 'datems'}, + {text: 'date (s)', value: 'dates' } + ] + }, { text: 'data', submenu: [