mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Time format: 0 seconds is a number (#27376)
This commit is contained in:
parent
444f2d5896
commit
d16a1f2215
@ -12,6 +12,7 @@ import {
|
||||
toDurationInHoursMinutesSeconds,
|
||||
toDurationInDaysHoursMinutesSeconds,
|
||||
toNanoSeconds,
|
||||
toSeconds,
|
||||
} from './dateTimeFormatters';
|
||||
import { formattedValueToString } from './valueFormats';
|
||||
import { toUtc, dateTime } from '../datetime/moment_wrapper';
|
||||
@ -331,3 +332,11 @@ describe('to nanoseconds', () => {
|
||||
expect(tenDays.suffix).toBe(' day');
|
||||
});
|
||||
});
|
||||
|
||||
describe('seconds', () => {
|
||||
it('should show 0 as 0', () => {
|
||||
const zeroSeconds = toSeconds(0);
|
||||
expect(zeroSeconds.text).toBe('0');
|
||||
expect(zeroSeconds.suffix).toBe(' s');
|
||||
});
|
||||
});
|
||||
|
@ -103,6 +103,11 @@ export function toSeconds(size: number, decimals?: DecimalCount, scaledDecimals?
|
||||
return { text: '' };
|
||||
}
|
||||
|
||||
// If 0, use s unit instead of ns
|
||||
if (size === 0) {
|
||||
return { text: '0', suffix: ' s' };
|
||||
}
|
||||
|
||||
// Less than 1 µs, divide in ns
|
||||
if (Math.abs(size) < 0.000001) {
|
||||
return toFixedScaled(size * 1e9, decimals, trySubstract(scaledDecimals, decimals), -9, ' ns');
|
||||
|
Loading…
Reference in New Issue
Block a user