import { formatReadableTimeDuration } from '../time'; describe('formatReadableTimeDuration', () => { const t = (v: string) => v; it.skip('abnormal input', () => { const second = 1000; const minute = 60 * second; const hour = minute * 60; const day = hour * 24; const start = Date.now(); const second1 = formatReadableTimeDuration({ start, end: start + second + 1, t, }); expect(second1).toBe('1 common.time.second'); const second2 = formatReadableTimeDuration({ start, end: start + second * 32 + 1, t, }); expect(second2).toBe('32 common.time.seconds'); const second3 = formatReadableTimeDuration({ start, end: start + second * 32 + 1, t, showSecondUnit: true, }); expect(second3).toBe('32common.time.seconds.short'); const minutes1 = formatReadableTimeDuration({ start, end: start + minute + 1, t, }); expect(minutes1).toBe('1 common.time.minute'); const minutes11 = formatReadableTimeDuration({ start, end: start + minute * 1 + 20 * second, t, showSecondUnit: true, }); expect(minutes11).toBe( '1common.time.minute.short20common.time.seconds.short', ); const minutes2 = formatReadableTimeDuration({ start, end: start + minute * 20 + 1, t, }); expect(minutes2).toBe('20 common.time.minutes'); const minutes3 = formatReadableTimeDuration({ start, end: start + minute * 20 + 1 * second, t, showSecondUnit: true, }); expect(minutes3).toBe( '20common.time.minutes.short1common.time.seconds.short', ); const minutes4 = formatReadableTimeDuration({ start, end: start + minute * 20 + 2 * second, t, showSecondUnit: true, }); expect(minutes4).toBe( '20common.time.minutes.short2common.time.seconds.short', ); const minutes5 = formatReadableTimeDuration({ start, end: start + minute * 20 + 0 * second, t, showSecondUnit: true, }); expect(minutes5).toBe( '20common.time.minutes.short0common.time.seconds.short', ); const hours1 = formatReadableTimeDuration({ start, end: start + hour + 1, t, }); expect(hours1).toBe('1 common.time.hour'); const hours2 = formatReadableTimeDuration({ start, end: start + hour * 20 + 30 * minute + 1, t, }); expect(hours2).toBe('20 common.time.hours'); const hours3 = formatReadableTimeDuration({ start, end: start + hour * 20 + 30 * minute + 1, t, showSecondUnit: true, }); expect(hours3).toBe('20common.time.hours30common.time.minutes'); const hours4 = formatReadableTimeDuration({ start, end: start + hour * 20 + 1 * minute + 60 * second, t, showSecondUnit: true, }); expect(hours4).toBe('20common.time.hours2common.time.minutes'); const days1 = formatReadableTimeDuration({ start, end: start + day + 1, t, }); expect(days1).toBe('1 common.time.day'); const days2 = formatReadableTimeDuration({ start, end: start + day * 20 + 20 * hour + 30 * minute + 1, t, }); expect(days2).toBe('20 common.time.days'); const days3 = formatReadableTimeDuration({ start, end: start + day * 20 + 20 * hour + 30 * minute + 1, t, showSecondUnit: true, }); expect(days3).toBe('20common.time.days20common.time.hours'); }); });