Commit d16a1f22 by Kenny Committed by GitHub

Time format: 0 seconds is a number (#27376)

parent 444f2d58
......@@ -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');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment