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

This commit is contained in:
Kenny 2020-09-04 11:12:54 -07:00 committed by GitHub
parent 444f2d5896
commit d16a1f2215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -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');
});
});

View File

@ -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');