@@ -100,8 +100,10 @@ const dates = [
100100 new Date ( 'Mar 17, 2024' ) ,
101101 new Date ( 'AD 1' ) ,
102102 new Date ( 'AD 0, 13:00' ) ,
103+ //new Date('1066, December 16, 7:17'), // Expect Sunday
103104 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' ) ,
105107 new Date ( 'BCE 753, April 21' ) ,
106108 new Date ( '1969, July 16' ) ,
107109 new Date ( 0 ) ,
@@ -188,7 +190,7 @@ function optionsToSkeleton(options) {
188190 return skeleton_array . join ( '' ) ;
189191}
190192
191- function generateAll ( ) {
193+ function generateAll ( run_limit ) {
192194
193195 let test_obj = {
194196 'Test scenario' : 'datetime_fmt' ,
@@ -256,7 +258,7 @@ function generateAll() {
256258 try {
257259 formatter = new Intl . DateTimeFormat ( locale , all_options ) ;
258260 } catch ( error ) {
259- console . log ( error , ' with locale ' ,
261+ console . error ( error , ' with locale ' ,
260262 locale , ' and options: ' , all_options ) ;
261263 continue ;
262264 }
@@ -268,7 +270,7 @@ function generateAll() {
268270 const parts = formatter . formatToParts ( d ) ;
269271 result = parts . map ( ( x ) => x . value ) . join ( "" ) ;
270272 } catch ( error ) {
271- console . log ( 'FORMATTER CREATION FAILS! ' , error ) ;
273+ console . error ( 'FORMATTER CREATION FAILS! ' , error ) ;
272274 }
273275 // format this date
274276 // get the milliseconds
@@ -297,7 +299,7 @@ function generateAll() {
297299 }
298300
299301 if ( debug ) {
300- console . log ( "TEST CASE :" , test_case ) ;
302+ console . debug ( "TEST CASE :" , test_case ) ;
301303 }
302304 test_cases . push ( test_case ) ;
303305
@@ -309,7 +311,7 @@ function generateAll() {
309311 console . log ( ' expected = ' , result ) ;
310312 }
311313 } catch ( error ) {
312- console . log ( '!!! error ' , error , ' in label ' , label_num ,
314+ console . error ( '!!! error ' , error , ' in label ' , label_num ,
313315 ' for date = ' , d ) ;
314316 }
315317 label_num ++ ;
@@ -318,25 +320,52 @@ function generateAll() {
318320 }
319321 }
320322
321-
322- console . log ( 'Number of date/time tests generated for ' ,
323+ console . log ( 'Total date/time tests generated for ' ,
323324 process . versions . icu , ': ' , label_num ) ;
324325
325- test_obj [ 'tests' ] = test_cases ;
326+ test_obj [ 'tests' ] = sample_tests ( test_cases , run_limit ) ;
326327 try {
327328 fs . writeFileSync ( 'datetime_fmt_test.json' , JSON . stringify ( test_obj , null , 2 ) ) ;
328329 // file written successfully
329330 } catch ( err ) {
330331 console . error ( err ) ;
331332 }
332333
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 ) ;
334338 try {
335339 fs . writeFileSync ( 'datetime_fmt_verify.json' , JSON . stringify ( verify_obj , null , 2 ) ) ;
336340 // file written successfully
337341 } catch ( err ) {
338342 console . error ( err ) ;
339343 }
340344}
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+
341362/* 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