@@ -24,6 +24,7 @@ import {
2424 formatDuration ,
2525 formatDurationCaption ,
2626 formatSeconds ,
27+ formatCoarseDuration ,
2728 isSameDay ,
2829 isSameMonth ,
2930 isThisYear ,
@@ -316,6 +317,53 @@ describe('TimeUtil', () => {
316317 } ) ;
317318 } ) ;
318319
320+ describe ( '"formatCoarseDuration"' , ( ) => {
321+ it ( 'formats durations in days (singular & plural)' , ( ) => {
322+ expect ( formatCoarseDuration ( ONE_DAY_IN_MILLIS ) ) . toBe ( t ( 'initProgressDaysSingular' , { time : 1 } ) ) ;
323+
324+ // Floor should keep it at 1 day
325+ expect ( formatCoarseDuration ( ONE_DAY_IN_MILLIS + 11 * ONE_HOUR_IN_MILLIS ) ) . toBe (
326+ t ( 'initProgressDaysSingular' , { time : 1 } ) ,
327+ ) ;
328+
329+ expect ( formatCoarseDuration ( 2 * ONE_DAY_IN_MILLIS ) ) . toBe ( t ( 'initProgressDaysPlural' , { time : 2 } ) ) ;
330+ expect ( formatCoarseDuration ( 2 * ONE_DAY_IN_MILLIS + 5 * ONE_HOUR_IN_MILLIS ) ) . toBe (
331+ t ( 'initProgressDaysPlural' , { time : 2 } ) ,
332+ ) ;
333+ } ) ;
334+
335+ it ( 'formats durations in hours (singular & plural)' , ( ) => {
336+ expect ( formatCoarseDuration ( ONE_HOUR_IN_MILLIS ) ) . toBe ( t ( 'initProgressHoursSingular' , { time : 1 } ) ) ;
337+
338+ // Floor keeps it at 1 hour
339+ expect ( formatCoarseDuration ( ONE_HOUR_IN_MILLIS + 59 * ONE_MINUTE_IN_MILLIS ) ) . toBe (
340+ t ( 'initProgressHoursSingular' , { time : 1 } ) ,
341+ ) ;
342+
343+ expect ( formatCoarseDuration ( 2 * ONE_HOUR_IN_MILLIS ) ) . toBe ( t ( 'initProgressHoursPlural' , { time : 2 } ) ) ;
344+ expect ( formatCoarseDuration ( 2 * ONE_HOUR_IN_MILLIS + 30 * ONE_MINUTE_IN_MILLIS ) ) . toBe (
345+ t ( 'initProgressHoursPlural' , { time : 2 } ) ,
346+ ) ;
347+ } ) ;
348+
349+ it ( 'formats durations in minutes (singular & plural)' , ( ) => {
350+ expect ( formatCoarseDuration ( ONE_MINUTE_IN_MILLIS ) ) . toBe ( t ( 'initProgressMinutesSingular' , { time : 1 } ) ) ;
351+
352+ // Floor keeps it at 1 minute
353+ expect ( formatCoarseDuration ( ONE_MINUTE_IN_MILLIS + 59 * ONE_SECOND_IN_MILLIS ) ) . toBe (
354+ t ( 'initProgressMinutesSingular' , { time : 1 } ) ,
355+ ) ;
356+
357+ expect ( formatCoarseDuration ( 2 * ONE_MINUTE_IN_MILLIS ) ) . toBe ( t ( 'initProgressMinutesPlural' , { time : 2 } ) ) ;
358+
359+ // Sub-minute durations should be treated as 1 minute (singular)
360+ expect ( formatCoarseDuration ( 59 * ONE_SECOND_IN_MILLIS ) ) . toBe ( t ( 'initProgressMinutesSingular' , { time : 1 } ) ) ;
361+
362+ // Explicit 30s case
363+ expect ( formatCoarseDuration ( 30 * ONE_SECOND_IN_MILLIS ) ) . toBe ( t ( 'initProgressMinutesSingular' , { time : 1 } ) ) ;
364+ } ) ;
365+ } ) ;
366+
319367 describe ( '"formatSeconds"' , ( ) => {
320368 it ( 'formats seconds' , ( ) => {
321369 expect ( formatSeconds ( 50 ) ) . toBe ( '00:50' ) ;
0 commit comments