ValueFormats: Fix formatting of 'clock' unit when duration is more than 100 hours (#92656)

This commit is contained in:
Dzmitry Skachkou 2024-09-02 14:50:54 +03:00 committed by GitHub
parent 2226446318
commit f0d100d17a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 5 deletions

View File

@ -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', () => {

View File

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