diff --git a/static/app/utils/duration/getExactDuration.spec.tsx b/static/app/utils/duration/getExactDuration.spec.tsx index 966bff71381d05..fdf169df2362c4 100644 --- a/static/app/utils/duration/getExactDuration.spec.tsx +++ b/static/app/utils/duration/getExactDuration.spec.tsx @@ -29,6 +29,7 @@ describe('getExactDuration', () => { it('should abbreviate label', () => { expect(getExactDuration(234235435, true)).toBe('387wk 2d 1hr 23min 55s'); + expect(getExactDuration(61, true, 'minutes')).toBe('1min'); }); it('should pin/truncate to the min suffix precision if provided', () => { @@ -41,5 +42,6 @@ describe('getExactDuration', () => { expect(getExactDuration(234235435.2, false, 'seconds')).toBe( '387 weeks 2 days 1 hour 23 minutes 55 seconds' ); + expect(getExactDuration(61, false, 'minutes')).toBe('1 minute'); }); }); diff --git a/static/app/utils/duration/getExactDuration.tsx b/static/app/utils/duration/getExactDuration.tsx index da11773f96e832..fd2baec203e5c8 100644 --- a/static/app/utils/duration/getExactDuration.tsx +++ b/static/app/utils/duration/getExactDuration.tsx @@ -43,31 +43,31 @@ export function getExactDuration( const {quotient, remainder} = divideBy(WEEK); const suffix = abbr ? t('wk') : ` ${tn('week', 'weeks', quotient)}`; - return `${quotient}${suffix} ${minSuffix === suffix ? '' : convertDuration(remainder / 1000, abbr)}`; + return `${quotient}${suffix} ${precision === 'weeks' ? '' : convertDuration(remainder / 1000, abbr)}`; } if (value >= DAY || (value && minSuffix === ' days')) { const {quotient, remainder} = divideBy(DAY); const suffix = abbr ? t('d') : ` ${tn('day', 'days', quotient)}`; - return `${quotient}${suffix} ${minSuffix === suffix ? '' : convertDuration(remainder / 1000, abbr)}`; + return `${quotient}${suffix} ${precision === 'days' ? '' : convertDuration(remainder / 1000, abbr)}`; } if (value >= HOUR || (value && minSuffix === ' hours')) { const {quotient, remainder} = divideBy(HOUR); const suffix = abbr ? t('hr') : ` ${tn('hour', 'hours', quotient)}`; - return `${quotient}${suffix} ${minSuffix === suffix ? '' : convertDuration(remainder / 1000, abbr)}`; + return `${quotient}${suffix} ${precision === 'hours' ? '' : convertDuration(remainder / 1000, abbr)}`; } if (value >= MINUTE || (value && minSuffix === ' minutes')) { const {quotient, remainder} = divideBy(MINUTE); const suffix = abbr ? t('min') : ` ${tn('minute', 'minutes', quotient)}`; - return `${quotient}${suffix} ${minSuffix === suffix ? '' : convertDuration(remainder / 1000, abbr)}`; + return `${quotient}${suffix} ${precision === 'minutes' ? '' : convertDuration(remainder / 1000, abbr)}`; } if (value >= SECOND || (value && minSuffix === ' seconds')) { const {quotient, remainder} = divideBy(SECOND); const suffix = abbr ? t('s') : ` ${tn('second', 'seconds', quotient)}`; - return `${quotient}${suffix} ${minSuffix === suffix ? '' : convertDuration(remainder / 1000, abbr)}`; + return `${quotient}${suffix} ${precision === 'seconds' ? '' : convertDuration(remainder / 1000, abbr)}`; } if (value === 0) {