@@ -415,4 +415,43 @@ describe('date-time', () => {
415415 test ( 'should not format duration' , ( ) => {
416416 expect ( dateTime . formatDuration ( new Date ( 2000 , 0 , 2 ) , new Date ( 2000 , 0 , 1 ) , 'en-US' ) ) . toStrictEqual ( '' ) ;
417417 } ) ;
418- } ) ;
418+
419+ describe ( 'formatDurationByOptions' , ( ) => {
420+ const baseDate = new Date ( '2024-01-01T00:00:00Z' ) ;
421+ const laterDate = new Date ( '2024-01-01T01:02:03Z' ) ;
422+
423+ test ( 'with default options' , ( ) => {
424+ const options : Intl . NumberFormatOptions = {
425+ unitDisplay : 'long' ,
426+ }
427+ expect ( dateTime . formatDurationByOptions ( options , baseDate , laterDate ) ) . toBe ( '1 hour 2 minutes 3 seconds' ) ;
428+ } ) ;
429+
430+ test ( 'with compact notation' , ( ) => {
431+ const options : Intl . NumberFormatOptions = {
432+ notation : 'compact' ,
433+ style : 'unit'
434+ } ;
435+ expect ( dateTime . formatDurationByOptions ( options , baseDate , laterDate ) ) . toBe ( '1 hr 2 min 3 sec' ) ;
436+ } ) ;
437+
438+ test ( 'with different unit style' , ( ) => {
439+ const options : Intl . NumberFormatOptions = {
440+ style : 'unit' ,
441+ unitDisplay : 'narrow'
442+ } ;
443+ expect ( dateTime . formatDurationByOptions ( options , baseDate , laterDate ) ) . toBe ( '1h 2m 3s' ) ;
444+ } ) ;
445+
446+ test ( 'with different locale' , ( ) => {
447+ const options : Intl . NumberFormatOptions = {
448+ unitDisplay : 'narrow' ,
449+ }
450+ expect ( dateTime . formatDurationByOptions ( options , baseDate , laterDate , 'en-US' ) ) . toBe ( '1h 2m 3s' ) ;
451+ expect ( dateTime . formatDurationByOptions ( options , baseDate , laterDate , 'zh-CN' ) ) . toBe ( '1小时 2分钟 3秒' ) ;
452+ expect ( dateTime . formatDurationByOptions ( options , baseDate , laterDate , 'ja-JP' ) ) . toBe ( '1h 2m 3s' ) ;
453+ expect ( dateTime . formatDurationByOptions ( options , baseDate , laterDate , 'ko-KR' ) ) . toBe ( '1시간 2분 3초' ) ;
454+ expect ( dateTime . formatDurationByOptions ( options , baseDate , laterDate , 'de-DE' ) ) . toBe ( '1 Std. 2 Min. 3 Sek.' ) ;
455+ } ) ;
456+ } ) ;
457+ } ) ;
0 commit comments