@@ -65,8 +65,24 @@ describe("formatAgo", () => {
6565} ) ;
6666
6767describe ( "localized durations" , ( ) => {
68+ it . each ( [ undefined , null , Number . NaN , Number . POSITIVE_INFINITY , Number . NEGATIVE_INFINITY , - 1 ] ) (
69+ "preserves invalid duration fallbacks for %s" ,
70+ ( durationMs ) => {
71+ expect ( formatDurationCompact ( durationMs ) ) . toBeUndefined ( ) ;
72+ expect ( formatDurationHuman ( durationMs , "unavailable" ) ) . toBe ( "unavailable" ) ;
73+ } ,
74+ ) ;
75+
76+ it ( "keeps zero distinct from a positive duration rounded to zero" , ( ) => {
77+ expect ( formatDurationCompact ( 0 ) ) . toBeUndefined ( ) ;
78+ expect ( formatDurationCompact ( 0.1 ) ) . toBe ( "0ms" ) ;
79+ expect ( formatDurationHuman ( 0 ) ) . toBe ( "0ms" ) ;
80+ } ) ;
81+
6882 it . each ( [
83+ { durationMs : 999.5 , expected : "1s" } ,
6984 { durationMs : 59_000 , expected : "59s" } ,
85+ { durationMs : 59_500 , expected : "1m" } ,
7086 { durationMs : 92_000 , expected : "1m 32s" } ,
7187 { durationMs : 3_660_000 , expected : "1h 1m" } ,
7288 { durationMs : 49 * 60 * 60 * 1000 , expected : "2d 1h" } ,
@@ -77,6 +93,22 @@ describe("localized durations", () => {
7793 it ( "switches human durations to days at 24 hours" , ( ) => {
7894 expect ( formatDurationHuman ( 36 * 60 * 60 * 1000 ) ) . toBe ( "2d" ) ;
7995 } ) ;
96+
97+ it ( "uses the active locale for both duration formats" , async ( ) => {
98+ await i18n . setLocale ( "fr" ) ;
99+ try {
100+ const minute = new Intl . NumberFormat ( "fr" , {
101+ style : "unit" ,
102+ unit : "minute" ,
103+ unitDisplay : "narrow" ,
104+ maximumFractionDigits : 0 ,
105+ } ) . format ( 1 ) ;
106+ expect ( formatDurationCompact ( 60_000 ) ) . toBe ( minute ) ;
107+ expect ( formatDurationHuman ( 60_000 ) ) . toBe ( minute ) ;
108+ } finally {
109+ await i18n . setLocale ( "en" ) ;
110+ }
111+ } ) ;
80112} ) ;
81113
82114describe ( "formatTimeAgo" , ( ) => {
0 commit comments