Skip to content

Commit b94527f

Browse files
authored
Merge pull request grafana#5383 from alexanderzobnin/issue-4747
issue grafana#4747 - add date and time units to singlestat panel.
2 parents 3adee1e + 398e9f5 commit b94527f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

public/app/core/utils/kbn.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
define([
22
'jquery',
33
'lodash',
4+
'moment'
45
],
5-
function($, _) {
6+
function($, _, moment) {
67
'use strict';
78

89
var kbn = {};
@@ -580,6 +581,20 @@ function($, _) {
580581
}
581582
};
582583

584+
// Date and time
585+
kbn.toDateTime = function(size, timeScale) {
586+
var datetime = moment(size * timeScale);
587+
return datetime.format('YYYY-MM-DD hh:mm:ss');
588+
};
589+
590+
kbn.valueFormats.datems = function(size) {
591+
return kbn.toDateTime(size, 1000);
592+
};
593+
594+
kbn.valueFormats.dates = function(size) {
595+
return kbn.toDateTime(size, 1);
596+
};
597+
583598
///// FORMAT MENU /////
584599

585600
kbn.getUnitFormats = function() {
@@ -618,6 +633,13 @@ function($, _) {
618633
{text: 'days (d)', value: 'd' },
619634
]
620635
},
636+
{
637+
text: 'date and time',
638+
submenu: [
639+
{text: 'date (ms)', value: 'datems'},
640+
{text: 'date (s)', value: 'dates' }
641+
]
642+
},
621643
{
622644
text: 'data',
623645
submenu: [

0 commit comments

Comments
 (0)