mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 19:54:10 -06:00
ValueFormats: Fix formatting of 'clock' unit when duration is more than 100 hours (#92656)
This commit is contained in:
parent
2226446318
commit
f0d100d17a
@ -287,19 +287,19 @@ describe('clock', () => {
|
||||
describe('size greater than or equal 1 hour', () => {
|
||||
it('default', () => {
|
||||
const str = toClock(7199999);
|
||||
expect(formattedValueToString(str)).toBe('01h:59m:59s:999ms');
|
||||
expect(formattedValueToString(str)).toBe('1h:59m:59s:999ms');
|
||||
});
|
||||
it('decimals equals 0', () => {
|
||||
const str = toClock(7199999, 0);
|
||||
expect(formattedValueToString(str)).toBe('01h');
|
||||
expect(formattedValueToString(str)).toBe('1h');
|
||||
});
|
||||
it('decimals equals 1', () => {
|
||||
const str = toClock(7199999, 1);
|
||||
expect(formattedValueToString(str)).toBe('01h:59m');
|
||||
expect(formattedValueToString(str)).toBe('1h:59m');
|
||||
});
|
||||
it('decimals equals 2', () => {
|
||||
const str = toClock(7199999, 2);
|
||||
expect(formattedValueToString(str)).toBe('01h:59m:59s');
|
||||
expect(formattedValueToString(str)).toBe('1h:59m:59s');
|
||||
});
|
||||
});
|
||||
describe('size greater than or equal 1 day', () => {
|
||||
@ -320,6 +320,24 @@ describe('clock', () => {
|
||||
expect(formattedValueToString(str)).toBe('24h:59m:59s');
|
||||
});
|
||||
});
|
||||
describe('size greater than or equal 100 hours', () => {
|
||||
it('default', () => {
|
||||
const str = toClock(363599999);
|
||||
expect(formattedValueToString(str)).toBe('100h:59m:59s:999ms');
|
||||
});
|
||||
it('decimals equals 0', () => {
|
||||
const str = toClock(363599999, 0);
|
||||
expect(formattedValueToString(str)).toBe('100h');
|
||||
});
|
||||
it('decimals equals 1', () => {
|
||||
const str = toClock(363599999, 1);
|
||||
expect(formattedValueToString(str)).toBe('100h:59m');
|
||||
});
|
||||
it('decimals equals 2', () => {
|
||||
const str = toClock(363599999, 2);
|
||||
expect(formattedValueToString(str)).toBe('100h:59m:59s');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('to nanoseconds', () => {
|
||||
|
@ -275,7 +275,7 @@ export function toClock(size: number, decimals?: DecimalCount): FormattedValue {
|
||||
|
||||
let format = 'mm\\m:ss\\s:SSS\\m\\s';
|
||||
|
||||
const hours = `${('0' + Math.floor(duration(size, 'milliseconds').asHours())).slice(-2)}h`;
|
||||
const hours = `${Math.floor(duration(size, 'milliseconds').asHours())}h`;
|
||||
|
||||
if (decimals === 0) {
|
||||
format = '';
|
||||
|
Loading…
Reference in New Issue
Block a user