@@ -100,8 +100,10 @@ const dates = [
100
100
new Date ( 'Mar 17, 2024' ) ,
101
101
new Date ( 'AD 1' ) ,
102
102
new Date ( 'AD 0, 13:00' ) ,
103
+ //new Date('1066, December 16, 7:17'), // Expect Sunday
103
104
new Date ( '1066, December 16, 7:17' ) ,
104
- new Date ( '1454, May 29, 16:47' ) ,
105
+ // new Date('1454, May 29, 16:47'), // Expect Monday
106
+ new Date ( '1754, May 29, 16:47' ) ,
105
107
new Date ( 'BCE 753, April 21' ) ,
106
108
new Date ( '1969, July 16' ) ,
107
109
new Date ( 0 ) ,
@@ -188,7 +190,7 @@ function optionsToSkeleton(options) {
188
190
return skeleton_array . join ( '' ) ;
189
191
}
190
192
191
- function generateAll ( ) {
193
+ function generateAll ( run_limit ) {
192
194
193
195
let test_obj = {
194
196
'Test scenario' : 'datetime_fmt' ,
@@ -256,7 +258,7 @@ function generateAll() {
256
258
try {
257
259
formatter = new Intl . DateTimeFormat ( locale , all_options ) ;
258
260
} catch ( error ) {
259
- console . log ( error , ' with locale ' ,
261
+ console . error ( error , ' with locale ' ,
260
262
locale , ' and options: ' , all_options ) ;
261
263
continue ;
262
264
}
@@ -268,7 +270,7 @@ function generateAll() {
268
270
const parts = formatter . formatToParts ( d ) ;
269
271
result = parts . map ( ( x ) => x . value ) . join ( "" ) ;
270
272
} catch ( error ) {
271
- console . log ( 'FORMATTER CREATION FAILS! ' , error ) ;
273
+ console . error ( 'FORMATTER CREATION FAILS! ' , error ) ;
272
274
}
273
275
// format this date
274
276
// get the milliseconds
@@ -297,7 +299,7 @@ function generateAll() {
297
299
}
298
300
299
301
if ( debug ) {
300
- console . log ( "TEST CASE :" , test_case ) ;
302
+ console . debug ( "TEST CASE :" , test_case ) ;
301
303
}
302
304
test_cases . push ( test_case ) ;
303
305
@@ -309,7 +311,7 @@ function generateAll() {
309
311
console . log ( ' expected = ' , result ) ;
310
312
}
311
313
} catch ( error ) {
312
- console . log ( '!!! error ' , error , ' in label ' , label_num ,
314
+ console . error ( '!!! error ' , error , ' in label ' , label_num ,
313
315
' for date = ' , d ) ;
314
316
}
315
317
label_num ++ ;
@@ -318,25 +320,52 @@ function generateAll() {
318
320
}
319
321
}
320
322
321
-
322
- console . log ( 'Number of date/time tests generated for ' ,
323
+ console . log ( 'Total date/time tests generated for ' ,
323
324
process . versions . icu , ': ' , label_num ) ;
324
325
325
- test_obj [ 'tests' ] = test_cases ;
326
+ test_obj [ 'tests' ] = sample_tests ( test_cases , run_limit ) ;
326
327
try {
327
328
fs . writeFileSync ( 'datetime_fmt_test.json' , JSON . stringify ( test_obj , null , 2 ) ) ;
328
329
// file written successfully
329
330
} catch ( err ) {
330
331
console . error ( err ) ;
331
332
}
332
333
333
- verify_obj [ 'verifications' ] = verify_cases ;
334
+ console . log ( 'Number of date/time sampled tests ' ,
335
+ process . versions . icu , ': ' , test_obj [ 'tests' ] . length ) ;
336
+
337
+ verify_obj [ 'verifications' ] = sample_tests ( verify_cases , run_limit ) ;
334
338
try {
335
339
fs . writeFileSync ( 'datetime_fmt_verify.json' , JSON . stringify ( verify_obj , null , 2 ) ) ;
336
340
// file written successfully
337
341
} catch ( err ) {
338
342
console . error ( err ) ;
339
343
}
340
344
}
345
+
346
+ function sample_tests ( all_tests , run_limit ) {
347
+ // Gets a sampling of the data based on total and the expected number.
348
+
349
+ if ( run_limit < 0 || all_tests . length <= run_limit ) {
350
+ return all_tests ;
351
+ }
352
+
353
+ let size_all = all_tests . length ;
354
+ let increment = Math . floor ( size_all / run_limit ) ;
355
+ let samples = [ ] ;
356
+ for ( let index = 0 ; index < size_all ; index += increment ) {
357
+ samples . push ( all_tests [ index ] ) ;
358
+ }
359
+ return samples ;
360
+ }
361
+
341
362
/* Call the generator */
342
- generateAll ( ) ;
363
+ let run_limit = - 1 ;
364
+ if ( process . argv . length >= 5 ) {
365
+ if ( process . argv [ 3 ] == '-run_limit' ) {
366
+ run_limit = Number ( process . argv [ 4 ] ) ;
367
+ }
368
+ }
369
+
370
+ // Call the generator
371
+ generateAll ( run_limit ) ;
0 commit comments