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
3c72b2f9
Unverified
Commit
3c72b2f9
authored
Jul 21, 2020
by
kay delaney
Committed by
GitHub
Jul 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Units: Allow re-scaling nanoseconds up to days (#26458)
Closes #26428
parent
8663f1b3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
1 deletions
+50
-1
packages/grafana-data/src/valueFormats/dateTimeFormatters.test.ts
+45
-0
packages/grafana-data/src/valueFormats/dateTimeFormatters.ts
+5
-1
No files found.
packages/grafana-data/src/valueFormats/dateTimeFormatters.test.ts
View file @
3c72b2f9
...
...
@@ -9,6 +9,7 @@ import {
toDurationInSeconds
,
toDurationInHoursMinutesSeconds
,
toDurationInDaysHoursMinutesSeconds
,
toNanoSeconds
,
}
from
'./dateTimeFormatters'
;
import
{
formattedValueToString
}
from
'./valueFormats'
;
import
{
toUtc
,
dateTime
}
from
'../datetime/moment_wrapper'
;
...
...
@@ -284,3 +285,47 @@ describe('clock', () => {
});
});
});
describe
(
'to nanoseconds'
,
()
=>
{
it
(
'should correctly display as ns'
,
()
=>
{
const
tenNanoseconds
=
toNanoSeconds
(
10
);
expect
(
tenNanoseconds
.
text
).
toBe
(
'10'
);
expect
(
tenNanoseconds
.
suffix
).
toBe
(
' ns'
);
});
it
(
'should correctly display as µs'
,
()
=>
{
const
threeMicroseconds
=
toNanoSeconds
(
3000
);
expect
(
threeMicroseconds
.
text
).
toBe
(
'3'
);
expect
(
threeMicroseconds
.
suffix
).
toBe
(
' µs'
);
});
it
(
'should correctly display as ms'
,
()
=>
{
const
fourMilliseconds
=
toNanoSeconds
(
4000000
);
expect
(
fourMilliseconds
.
text
).
toBe
(
'4'
);
expect
(
fourMilliseconds
.
suffix
).
toBe
(
' ms'
);
});
it
(
'should correctly display as s'
,
()
=>
{
const
fiveSeconds
=
toNanoSeconds
(
5000000000
);
expect
(
fiveSeconds
.
text
).
toBe
(
'5'
);
expect
(
fiveSeconds
.
suffix
).
toBe
(
' s'
);
});
it
(
'should correctly display as minutes'
,
()
=>
{
const
eightMinutes
=
toNanoSeconds
(
480000000000
);
expect
(
eightMinutes
.
text
).
toBe
(
'8'
);
expect
(
eightMinutes
.
suffix
).
toBe
(
' min'
);
});
it
(
'should correctly display as hours'
,
()
=>
{
const
nineHours
=
toNanoSeconds
(
32400000000000
);
expect
(
nineHours
.
text
).
toBe
(
'9'
);
expect
(
nineHours
.
suffix
).
toBe
(
' hour'
);
});
it
(
'should correctly display as days'
,
()
=>
{
const
tenDays
=
toNanoSeconds
(
864000000000000
);
expect
(
tenDays
.
text
).
toBe
(
'10'
);
expect
(
tenDays
.
suffix
).
toBe
(
' day'
);
});
});
packages/grafana-data/src/valueFormats/dateTimeFormatters.ts
View file @
3c72b2f9
...
...
@@ -44,8 +44,12 @@ export function toNanoSeconds(size: number, decimals?: DecimalCount, scaledDecim
return
toFixedScaled
(
size
/
1000000
,
decimals
,
scaledDecimals
,
6
,
' ms'
);
}
else
if
(
Math
.
abs
(
size
)
<
60000000000
)
{
return
toFixedScaled
(
size
/
1000000000
,
decimals
,
scaledDecimals
,
9
,
' s'
);
}
else
{
}
else
if
(
Math
.
abs
(
size
)
<
3600000000000
)
{
return
toFixedScaled
(
size
/
60000000000
,
decimals
,
scaledDecimals
,
12
,
' min'
);
}
else
if
(
Math
.
abs
(
size
)
<
86400000000000
)
{
return
toFixedScaled
(
size
/
3600000000000
,
decimals
,
scaledDecimals
,
13
,
' hour'
);
}
else
{
return
toFixedScaled
(
size
/
86400000000000
,
decimals
,
scaledDecimals
,
14
,
' day'
);
}
}
...
...
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