@@ -45,7 +45,6 @@ function runTests({
4545}
4646
4747runTests ( {
48- title : "prettify milliseconds" ,
4948 cases : [
5049 [ 0 , "0ms" ] ,
5150 [ 0.1 , "1ms" ] ,
@@ -67,21 +66,21 @@ runTests({
6766 [ 120_000 , "2m" ] ,
6867 [ Number . MAX_SAFE_INTEGER , "285616y 151d 8h 59m 0.9s" ] ,
6968 ] ,
69+ title : "prettify milliseconds" ,
7070} ) ;
7171
7272runTests ( {
73- title : "have a compact option" ,
74- defaultOptions : { compact : true } ,
7573 cases : [
7674 [ 1000 + 4 , "1s" ] ,
7775 [ 1000 * 60 * 60 * 999 , "41d" ] ,
7876 [ 1000 * 60 * 60 * 24 * 465 , "1y" ] ,
7977 [ 1000 * 60 * 67 * 24 * 465 , "1y" ] ,
8078 ] ,
79+ defaultOptions : { compact : true } ,
80+ title : "have a compact option" ,
8181} ) ;
8282
8383runTests ( {
84- title : "have a unitCount option" ,
8584 cases : [
8685 [ 1000 * 60 , { unitCount : 0 } , "1m" ] ,
8786 [ 1000 * 60 , { unitCount : 1 } , "1m" ] ,
@@ -91,10 +90,10 @@ runTests({
9190 [ 1000 * 60 * 67 * 24 * 465 , { unitCount : 2 } , "1y 154d" ] ,
9291 [ 1000 * 60 * 67 * 24 * 465 , { unitCount : 3 } , "1y 154d 6h" ] ,
9392 ] ,
93+ title : "have a unitCount option" ,
9494} ) ;
9595
9696runTests ( {
97- title : "have a secondsDecimalDigits option" ,
9897 cases : [
9998 [ 10_000 , "10s" ] ,
10099 [ 33_333 , "33.3s" ] ,
@@ -105,29 +104,28 @@ runTests({
105104 [ 33_333 , { secondsDecimalDigits : 0 } , "33s" ] ,
106105 [ 33_333 , { secondsDecimalDigits : 4 } , "33.3330s" ] ,
107106 ] ,
107+ title : "have a secondsDecimalDigits option" ,
108108} ) ;
109109
110110runTests ( {
111- title : "have a millisecondsDecimalDigits option" ,
112111 cases : [
113112 [ 33.333 , "33ms" ] ,
114113 [ 33.333 , { millisecondsDecimalDigits : 0 } , "33ms" ] ,
115114 [ 33.333 , { millisecondsDecimalDigits : 4 } , "33.3330ms" ] ,
116115 ] ,
116+ title : "have a millisecondsDecimalDigits option" ,
117117} ) ;
118118
119119runTests ( {
120- title : "have a keepDecimalsOnWholeSeconds option" ,
121- defaultOptions : { keepDecimalsOnWholeSeconds : true } ,
122120 cases : [
123121 [ 1000 * 33 , { secondsDecimalDigits : 2 } , "33.00s" ] ,
124122 [ 1000 * 33.000_04 , { secondsDecimalDigits : 2 } , "33.00s" ] ,
125123 ] ,
124+ defaultOptions : { keepDecimalsOnWholeSeconds : true } ,
125+ title : "have a keepDecimalsOnWholeSeconds option" ,
126126} ) ;
127127
128128runTests ( {
129- title : "have a verbose option" ,
130- defaultOptions : { verbose : true } ,
131129 cases : [
132130 [ 0 , "0 milliseconds" ] ,
133131 [ 0.1 , "1 millisecond" ] ,
@@ -146,30 +144,30 @@ runTests({
146144 [ 1000 * 60 * 60 * 24 * 465 , "1 year 100 days" ] ,
147145 [ 1000 * 60 * 67 * 24 * 465 , "1 year 154 days 6 hours" ] ,
148146 ] ,
147+ defaultOptions : { verbose : true } ,
148+ title : "have a verbose option" ,
149149} ) ;
150150
151151runTests ( {
152- title : "have a separateMilliseconds option" ,
153152 cases : [
154153 [ 1100 , { separateMilliseconds : false } , "1.1s" ] ,
155154 [ 1100 , { separateMilliseconds : true } , "1s 100ms" ] ,
156155 ] ,
156+ title : "have a separateMilliseconds option" ,
157157} ) ;
158158
159159runTests ( {
160- title : "have a formatSubMilliseconds option" ,
161- defaultOptions : { formatSubMilliseconds : true } ,
162160 cases : [
163161 [ 0.4 , "400µs" ] ,
164162 [ 0.123_571 , "123µs 571ns" ] ,
165163 [ 0.123_456_789 , "123µs 456ns" ] ,
166164 [ 60 * 60 * 1000 + 23 * 1000 + 433 + 0.123_456 , "1h 23s 433ms 123µs 456ns" ] ,
167165 ] ,
166+ defaultOptions : { formatSubMilliseconds : true } ,
167+ title : "have a formatSubMilliseconds option" ,
168168} ) ;
169169
170170runTests ( {
171- title : "work with verbose and compact options" ,
172- defaultOptions : { verbose : true , compact : true } ,
173171 cases : [
174172 [ 1000 , "1 second" ] ,
175173 [ 1000 + 400 , "1 second" ] ,
@@ -185,11 +183,11 @@ runTests({
185183 [ 1000 * 60 * 60 * 24 * 465 , "1 year" ] ,
186184 [ 1000 * 60 * 67 * 24 * 750 , "2 years" ] ,
187185 ] ,
186+ defaultOptions : { compact : true , verbose : true } ,
187+ title : "work with verbose and compact options" ,
188188} ) ;
189189
190190runTests ( {
191- title : "work with verbose and unitCount options" ,
192- defaultOptions : { verbose : true } ,
193191 cases : [
194192 [ 1000 * 60 , { unitCount : 1 } , "1 minute" ] ,
195193 [ 1000 * 60 * 67 , { unitCount : 1 } , "1 hour" ] ,
@@ -198,60 +196,62 @@ runTests({
198196 [ 1000 * 60 * 67 * 24 * 465 , { unitCount : 2 } , "1 year 154 days" ] ,
199197 [ 1000 * 60 * 67 * 24 * 465 , { unitCount : 3 } , "1 year 154 days 6 hours" ] ,
200198 ] ,
199+ defaultOptions : { verbose : true } ,
200+ title : "work with verbose and unitCount options" ,
201201} ) ;
202202
203203runTests ( {
204- title : "work with verbose and secondsDecimalDigits options" ,
205- defaultOptions : { verbose : true , secondsDecimalDigits : 4 } ,
206204 cases : [
207205 [ 1000 , "1 second" ] ,
208206 [ 1000 + 400 , "1.4000 seconds" ] ,
209207 [ 1000 * 2 + 400 , "2.4000 seconds" ] ,
210208 [ 1000 * 5 + 254 , "5.2540 seconds" ] ,
211209 [ 33_333 , "33.3330 seconds" ] ,
212210 ] ,
211+ defaultOptions : { secondsDecimalDigits : 4 , verbose : true } ,
212+ title : "work with verbose and secondsDecimalDigits options" ,
213213} ) ;
214214
215215runTests ( {
216- title : "work with verbose and millisecondsDecimalDigits options" ,
217- defaultOptions : { verbose : true , millisecondsDecimalDigits : 4 } ,
218216 cases : [
219217 [ 1 , "1.0000 millisecond" ] ,
220218 [ 1 + 0.4 , "1.4000 milliseconds" ] ,
221219 [ 1 * 2 + 0.4 , "2.4000 milliseconds" ] ,
222220 [ 1 * 5 + 0.254 , "5.2540 milliseconds" ] ,
223221 [ 33.333 , "33.3330 milliseconds" ] ,
224222 ] ,
223+ defaultOptions : { millisecondsDecimalDigits : 4 , verbose : true } ,
224+ title : "work with verbose and millisecondsDecimalDigits options" ,
225225} ) ;
226226
227227runTests ( {
228- title : "work with verbose and formatSubMilliseconds options" ,
229- defaultOptions : { formatSubMilliseconds : true , verbose : true } ,
230228 cases : [
231229 [ 0.4 , "400 microseconds" ] ,
232230 [ 0.123_571 , "123 microseconds 571 nanoseconds" ] ,
233231 [ 0.123_456_789 , "123 microseconds 456 nanoseconds" ] ,
234232 [ 0.001 , "1 microsecond" ] ,
235233 ] ,
234+ defaultOptions : { formatSubMilliseconds : true , verbose : true } ,
235+ title : "work with verbose and formatSubMilliseconds options" ,
236236} ) ;
237237
238238runTests ( {
239- title : "compact option overrides unitCount option" ,
240- defaultOptions : { verbose : true , compact : true } ,
241239 cases : [
242240 [ 1000 * 60 * 67 * 24 * 465 , { unitCount : 1 } , "1 year" ] ,
243241 [ 1000 * 60 * 67 * 24 * 465 , { unitCount : 2 } , "1 year" ] ,
244242 [ 1000 * 60 * 67 * 24 * 465 , { unitCount : 3 } , "1 year" ] ,
245243 ] ,
244+ defaultOptions : { compact : true , verbose : true } ,
245+ title : "compact option overrides unitCount option" ,
246246} ) ;
247247
248248runTests ( {
249- title : "work with separateMilliseconds and formatSubMilliseconds options" ,
250- defaultOptions : { separateMilliseconds : true , formatSubMilliseconds : true } ,
251249 cases : [
252250 [ 1010.340_067 , "1s 10ms 340µs 67ns" ] ,
253251 [ 60 * 1000 + 34 + 0.000_005 , "1m 34ms 5ns" ] ,
254252 ] ,
253+ defaultOptions : { formatSubMilliseconds : true , separateMilliseconds : true } ,
254+ title : "work with separateMilliseconds and formatSubMilliseconds options" ,
255255} ) ;
256256
257257it ( "throw on invalid" , ( ) => {
@@ -269,8 +269,6 @@ it("throw on invalid", () => {
269269} ) ;
270270
271271runTests ( {
272- title : "properly rounds milliseconds with secondsDecimalDigits" ,
273- defaultOptions : { verbose : true , secondsDecimalDigits : 0 } ,
274272 cases : [
275273 [ 3 * 60 * 1000 , "3 minutes" ] ,
276274 [ 3 * 60 * 1000 - 1 , "2 minutes 59 seconds" ] ,
@@ -283,11 +281,11 @@ runTests({
283281 [ 2 * 3600 * 1e3 , "2 hours" ] ,
284282 [ 2 * 3600 * 1e3 - 1 , "1 hour 59 minutes 59 seconds" ] ,
285283 ] ,
284+ defaultOptions : { secondsDecimalDigits : 0 , verbose : true } ,
285+ title : "properly rounds milliseconds with secondsDecimalDigits" ,
286286} ) ;
287287
288288runTests ( {
289- title : "`colonNotation` option" ,
290- defaultOptions : { colonNotation : true } ,
291289 cases : [
292290 // Default formats
293291 [ 1000 , "0:01" ] ,
@@ -328,17 +326,17 @@ runTests({
328326 ] ,
329327
330328 // Together with `keepDecimalsOnWholeSeconds`
331- [ 999 , { secondsDecimalDigits : 0 , keepDecimalsOnWholeSeconds : true } , "0:00" ] ,
332- [ 999 , { secondsDecimalDigits : 1 , keepDecimalsOnWholeSeconds : true } , "0:00.9" ] ,
333- [ 999 , { secondsDecimalDigits : 2 , keepDecimalsOnWholeSeconds : true } , "0:00.99" ] ,
334- [ 999 , { secondsDecimalDigits : 3 , keepDecimalsOnWholeSeconds : true } , "0:00.999" ] ,
329+ [ 999 , { keepDecimalsOnWholeSeconds : true , secondsDecimalDigits : 0 } , "0:00" ] ,
330+ [ 999 , { keepDecimalsOnWholeSeconds : true , secondsDecimalDigits : 1 } , "0:00.9" ] ,
331+ [ 999 , { keepDecimalsOnWholeSeconds : true , secondsDecimalDigits : 2 } , "0:00.99" ] ,
332+ [ 999 , { keepDecimalsOnWholeSeconds : true , secondsDecimalDigits : 3 } , "0:00.999" ] ,
335333 [ 1000 , { keepDecimalsOnWholeSeconds : true } , "0:01.0" ] ,
336- [ 1000 , { secondsDecimalDigits : 0 , keepDecimalsOnWholeSeconds : true } , "0:01" ] ,
337- [ 1000 , { secondsDecimalDigits : 1 , keepDecimalsOnWholeSeconds : true } , "0:01.0" ] ,
338- [ 1000 , { secondsDecimalDigits : 3 , keepDecimalsOnWholeSeconds : true } , "0:01.000" ] ,
334+ [ 1000 , { keepDecimalsOnWholeSeconds : true , secondsDecimalDigits : 0 } , "0:01" ] ,
335+ [ 1000 , { keepDecimalsOnWholeSeconds : true , secondsDecimalDigits : 1 } , "0:01.0" ] ,
336+ [ 1000 , { keepDecimalsOnWholeSeconds : true , secondsDecimalDigits : 3 } , "0:01.000" ] ,
339337 [ 1000 * 90 , { keepDecimalsOnWholeSeconds : true } , "1:30.0" ] ,
340- [ 1000 * 90 , { secondsDecimalDigits : 3 , keepDecimalsOnWholeSeconds : true } , "1:30.000" ] ,
341- [ 1000 * 60 * 10 , { secondsDecimalDigits : 3 , keepDecimalsOnWholeSeconds : true } , "10:00.000" ] ,
338+ [ 1000 * 90 , { keepDecimalsOnWholeSeconds : true , secondsDecimalDigits : 3 } , "1:30.000" ] ,
339+ [ 1000 * 60 * 10 , { keepDecimalsOnWholeSeconds : true , secondsDecimalDigits : 3 } , "10:00.000" ] ,
342340
343341 // Together with `unitCount`
344342 [ 1000 * 90 , { secondsDecimalDigits : 0 , unitCount : 1 } , "1" ] ,
@@ -357,6 +355,8 @@ runTests({
357355 // Big numbers
358356 [ Number . MAX_SAFE_INTEGER , "285616:151:08:59:00.9" ] ,
359357 ] ,
358+ defaultOptions : { colonNotation : true } ,
359+ title : "`colonNotation` option" ,
360360} ) ;
361361
362362it ( "Big numbers" , ( ) => {
0 commit comments