Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
a3388ef4
Commit
a3388ef4
authored
Mar 13, 2018
by
Yohann BARRE
Committed by
Carl Bergquist
Mar 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Second to HH:mm:ss formatter (#11105)
* Seconds to HH:MM:SS format
parent
18638c21
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
public/app/core/specs/kbn.jest.ts
+15
-0
public/app/core/utils/kbn.ts
+16
-0
No files found.
public/app/core/specs/kbn.jest.ts
View file @
a3388ef4
...
...
@@ -355,3 +355,18 @@ describe('volume', function() {
expect
(
str
).
toBe
(
'1000.0 m3'
);
});
});
describe
(
'hh:mm:ss'
,
function
()
{
it
(
'00:04:06'
,
function
()
{
var
str
=
kbn
.
valueFormats
[
'dthms'
](
246
,
1
);
expect
(
str
).
toBe
(
'00:04:06'
);
});
it
(
'24:00:00'
,
function
()
{
var
str
=
kbn
.
valueFormats
[
'dthms'
](
86400
,
1
);
expect
(
str
).
toBe
(
'24:00:00'
);
});
it
(
'6824413:53:20'
,
function
()
{
var
str
=
kbn
.
valueFormats
[
'dthms'
](
24567890000
,
1
);
expect
(
str
).
toBe
(
'6824413:53:20'
);
});
});
public/app/core/utils/kbn.ts
View file @
a3388ef4
...
...
@@ -131,6 +131,17 @@ kbn.secondsToHms = function(seconds) {
return
'less than a millisecond'
;
//'just now' //or other string you like;
};
kbn
.
secondsToHhmmss
=
function
(
seconds
)
{
var
strings
=
[];
var
numhours
=
Math
.
floor
(
seconds
/
3600
);
var
numminutes
=
Math
.
floor
((
seconds
%
3600
)
/
60
);
var
numseconds
=
Math
.
floor
((
seconds
%
3600
)
%
60
);
numhours
>
9
?
strings
.
push
(
''
+
numhours
)
:
strings
.
push
(
'0'
+
numhours
);
numminutes
>
9
?
strings
.
push
(
''
+
numminutes
)
:
strings
.
push
(
'0'
+
numminutes
);
numseconds
>
9
?
strings
.
push
(
''
+
numseconds
)
:
strings
.
push
(
'0'
+
numseconds
);
return
strings
.
join
(
':'
);
};
kbn
.
to_percent
=
function
(
nr
,
outof
)
{
return
Math
.
floor
(
nr
/
outof
*
10000
)
/
100
+
'%'
;
};
...
...
@@ -795,6 +806,10 @@ kbn.valueFormats.dtdurations = function(size, decimals) {
return kbn.toDuration(size, decimals, '
second
');
};
kbn.valueFormats.dthms = function(size, decimals) {
return kbn.secondsToHhmmss(size);
};
kbn.valueFormats.timeticks = function(size, decimals, scaledDecimals) {
return kbn.valueFormats.s(size / 100, decimals, scaledDecimals);
};
...
...
@@ -869,6 +884,7 @@ kbn.getUnitFormats = function() {
{ text: '
days
(
d
)
', value: '
d
' },
{ text: '
duration
(
ms
)
', value: '
dtdurationms
' },
{ text: '
duration
(
s
)
', value: '
dtdurations
' },
{ text: '
duration
(
hh
:
mm
:
ss
)
', value: '
dthms
' },
{ text: '
Timeticks
(
s
/
100
)
', value: '
timeticks
' },
],
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment