2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
4
using System ;
5
+ using System . Collections . Generic ;
5
6
using System . Globalization ;
7
+ using System . Linq ;
8
+ using System . Threading . Tasks ;
6
9
using Xunit ;
7
10
8
11
public static unsafe class DateTimeTests
@@ -291,6 +294,68 @@ public static void TestTryParseExactA()
291
294
Assert . Equal ( s , actual ) ;
292
295
}
293
296
297
+ [ Fact ]
298
+ [ ActiveIssue ( 846 , PlatformID . AnyUnix ) ]
299
+ public static void TestGetDateTimeFormats ( )
300
+ {
301
+ // Running in the new thread so that we do not interfere with the Main thread's culture
302
+ Task . Run ( ( ) =>
303
+ {
304
+ CultureInfo . CurrentCulture = new CultureInfo ( "en-US" ) ;
305
+ DateTime july28 = new DateTime ( 2009 , 7 , 28 , 5 , 23 , 15 ) ;
306
+
307
+ List < string > actualJuly28Formats = july28 . GetDateTimeFormats ( ) . ToList ( ) ;
308
+
309
+ Assert . Equal ( expectedJuly28Formats . OrderBy ( t => t ) , actualJuly28Formats . OrderBy ( t => t ) ) ;
310
+ } ) . Wait ( ) ;
311
+ }
312
+
313
+ [ Fact ]
314
+ [ ActiveIssue ( 846 , PlatformID . AnyUnix ) ]
315
+ public static void TestGetDateTimeFormats_FormatSpecifier ( )
316
+ {
317
+ // Running in the new thread so that we do not interfere with the Main thread's culture
318
+ Task . Run ( ( ) =>
319
+ {
320
+ char [ ] allStandardFormats =
321
+ {
322
+ 'd' , 'D' , 'f' , 'F' , 'g' , 'G' ,
323
+ 'm' , 'M' , 'o' , 'O' , 'r' , 'R' ,
324
+ 's' , 't' , 'T' , 'u' , 'U' , 'y' , 'Y' ,
325
+ } ;
326
+
327
+ CultureInfo . CurrentCulture = new CultureInfo ( "en-US" ) ;
328
+ DateTime july28 = new DateTime ( 2009 , 7 , 28 , 5 , 23 , 15 ) ;
329
+
330
+ List < string > actualJuly28Formats = new List < string > ( ) ;
331
+ foreach ( char format in allStandardFormats )
332
+ {
333
+ actualJuly28Formats . AddRange ( july28 . GetDateTimeFormats ( format ) ) ;
334
+ }
335
+
336
+ Assert . Equal ( expectedJuly28Formats . OrderBy ( t => t ) , actualJuly28Formats . OrderBy ( t => t ) ) ;
337
+ } ) . Wait ( ) ;
338
+ }
339
+
340
+ [ Fact ]
341
+ public static void TestGetDateTimeFormats_FormatSpecifier_InvalidFormat ( )
342
+ {
343
+ DateTime july28 = new DateTime ( 2009 , 7 , 28 , 5 , 23 , 15 ) ;
344
+
345
+ Assert . Throws < FormatException > ( ( ) => july28 . GetDateTimeFormats ( 'x' ) ) ;
346
+ }
347
+
348
+ [ Fact ]
349
+ [ ActiveIssue ( 846 , PlatformID . AnyUnix ) ]
350
+ public static void TestGetDateTimeFormats_FormatProvider ( )
351
+ {
352
+ DateTime july28 = new DateTime ( 2009 , 7 , 28 , 5 , 23 , 15 ) ;
353
+
354
+ List < string > actualJuly28Formats = july28 . GetDateTimeFormats ( new CultureInfo ( "en-US" ) ) . ToList ( ) ;
355
+
356
+ Assert . Equal ( expectedJuly28Formats . OrderBy ( t => t ) , actualJuly28Formats . OrderBy ( t => t ) ) ;
357
+ }
358
+
294
359
internal static void ValidateYearMonthDay ( DateTime dt , int year , int month , int day )
295
360
{
296
361
Assert . Equal ( dt . Year , year ) ;
@@ -311,5 +376,143 @@ internal static void ValidateYearMonthDay(DateTime dt, int year, int month, int
311
376
ValidateYearMonthDay ( dt , year , month , day , hour , minute , second ) ;
312
377
Assert . Equal ( dt . Millisecond , millisecond ) ;
313
378
}
379
+
380
+
381
+ private static List < string > expectedJuly28Formats = new List < string >
382
+ {
383
+ "7/28/2009" ,
384
+ "7/28/09" ,
385
+ "07/28/09" ,
386
+ "07/28/2009" ,
387
+ "09/07/28" ,
388
+ "2009-07-28" ,
389
+ "28-Jul-09" ,
390
+ "Tuesday, July 28, 2009" ,
391
+ "July 28, 2009" ,
392
+ "Tuesday, 28 July, 2009" ,
393
+ "28 July, 2009" ,
394
+ "Tuesday, July 28, 2009 5:23 AM" ,
395
+ "Tuesday, July 28, 2009 05:23 AM" ,
396
+ "Tuesday, July 28, 2009 5:23" ,
397
+ "Tuesday, July 28, 2009 05:23" ,
398
+ "July 28, 2009 5:23 AM" ,
399
+ "July 28, 2009 05:23 AM" ,
400
+ "July 28, 2009 5:23" ,
401
+ "July 28, 2009 05:23" ,
402
+ "Tuesday, 28 July, 2009 5:23 AM" ,
403
+ "Tuesday, 28 July, 2009 05:23 AM" ,
404
+ "Tuesday, 28 July, 2009 5:23" ,
405
+ "Tuesday, 28 July, 2009 05:23" ,
406
+ "28 July, 2009 5:23 AM" ,
407
+ "28 July, 2009 05:23 AM" ,
408
+ "28 July, 2009 5:23" ,
409
+ "28 July, 2009 05:23" ,
410
+ "Tuesday, July 28, 2009 5:23:15 AM" ,
411
+ "Tuesday, July 28, 2009 05:23:15 AM" ,
412
+ "Tuesday, July 28, 2009 5:23:15" ,
413
+ "Tuesday, July 28, 2009 05:23:15" ,
414
+ "July 28, 2009 5:23:15 AM" ,
415
+ "July 28, 2009 05:23:15 AM" ,
416
+ "July 28, 2009 5:23:15" ,
417
+ "July 28, 2009 05:23:15" ,
418
+ "Tuesday, 28 July, 2009 5:23:15 AM" ,
419
+ "Tuesday, 28 July, 2009 05:23:15 AM" ,
420
+ "Tuesday, 28 July, 2009 5:23:15" ,
421
+ "Tuesday, 28 July, 2009 05:23:15" ,
422
+ "28 July, 2009 5:23:15 AM" ,
423
+ "28 July, 2009 05:23:15 AM" ,
424
+ "28 July, 2009 5:23:15" ,
425
+ "28 July, 2009 05:23:15" ,
426
+ "7/28/2009 5:23 AM" ,
427
+ "7/28/2009 05:23 AM" ,
428
+ "7/28/2009 5:23" ,
429
+ "7/28/2009 05:23" ,
430
+ "7/28/09 5:23 AM" ,
431
+ "7/28/09 05:23 AM" ,
432
+ "7/28/09 5:23" ,
433
+ "7/28/09 05:23" ,
434
+ "07/28/09 5:23 AM" ,
435
+ "07/28/09 05:23 AM" ,
436
+ "07/28/09 5:23" ,
437
+ "07/28/09 05:23" ,
438
+ "07/28/2009 5:23 AM" ,
439
+ "07/28/2009 05:23 AM" ,
440
+ "07/28/2009 5:23" ,
441
+ "07/28/2009 05:23" ,
442
+ "09/07/28 5:23 AM" ,
443
+ "09/07/28 05:23 AM" ,
444
+ "09/07/28 5:23" ,
445
+ "09/07/28 05:23" ,
446
+ "2009-07-28 5:23 AM" ,
447
+ "2009-07-28 05:23 AM" ,
448
+ "2009-07-28 5:23" ,
449
+ "2009-07-28 05:23" ,
450
+ "28-Jul-09 5:23 AM" ,
451
+ "28-Jul-09 05:23 AM" ,
452
+ "28-Jul-09 5:23" ,
453
+ "28-Jul-09 05:23" ,
454
+ "7/28/2009 5:23:15 AM" ,
455
+ "7/28/2009 05:23:15 AM" ,
456
+ "7/28/2009 5:23:15" ,
457
+ "7/28/2009 05:23:15" ,
458
+ "7/28/09 5:23:15 AM" ,
459
+ "7/28/09 05:23:15 AM" ,
460
+ "7/28/09 5:23:15" ,
461
+ "7/28/09 05:23:15" ,
462
+ "07/28/09 5:23:15 AM" ,
463
+ "07/28/09 05:23:15 AM" ,
464
+ "07/28/09 5:23:15" ,
465
+ "07/28/09 05:23:15" ,
466
+ "07/28/2009 5:23:15 AM" ,
467
+ "07/28/2009 05:23:15 AM" ,
468
+ "07/28/2009 5:23:15" ,
469
+ "07/28/2009 05:23:15" ,
470
+ "09/07/28 5:23:15 AM" ,
471
+ "09/07/28 05:23:15 AM" ,
472
+ "09/07/28 5:23:15" ,
473
+ "09/07/28 05:23:15" ,
474
+ "2009-07-28 5:23:15 AM" ,
475
+ "2009-07-28 05:23:15 AM" ,
476
+ "2009-07-28 5:23:15" ,
477
+ "2009-07-28 05:23:15" ,
478
+ "28-Jul-09 5:23:15 AM" ,
479
+ "28-Jul-09 05:23:15 AM" ,
480
+ "28-Jul-09 5:23:15" ,
481
+ "28-Jul-09 05:23:15" ,
482
+ "July 28" ,
483
+ "July 28" ,
484
+ "2009-07-28T05:23:15.0000000" ,
485
+ "2009-07-28T05:23:15.0000000" ,
486
+ "Tue, 28 Jul 2009 05:23:15 GMT" ,
487
+ "Tue, 28 Jul 2009 05:23:15 GMT" ,
488
+ "2009-07-28T05:23:15" ,
489
+ "5:23 AM" ,
490
+ "05:23 AM" ,
491
+ "5:23" ,
492
+ "05:23" ,
493
+ "5:23:15 AM" ,
494
+ "05:23:15 AM" ,
495
+ "5:23:15" ,
496
+ "05:23:15" ,
497
+ "2009-07-28 05:23:15Z" ,
498
+ "Tuesday, July 28, 2009 12:23:15 PM" ,
499
+ "Tuesday, July 28, 2009 12:23:15 PM" ,
500
+ "Tuesday, July 28, 2009 12:23:15" ,
501
+ "Tuesday, July 28, 2009 12:23:15" ,
502
+ "July 28, 2009 12:23:15 PM" ,
503
+ "July 28, 2009 12:23:15 PM" ,
504
+ "July 28, 2009 12:23:15" ,
505
+ "July 28, 2009 12:23:15" ,
506
+ "Tuesday, 28 July, 2009 12:23:15 PM" ,
507
+ "Tuesday, 28 July, 2009 12:23:15 PM" ,
508
+ "Tuesday, 28 July, 2009 12:23:15" ,
509
+ "Tuesday, 28 July, 2009 12:23:15" ,
510
+ "28 July, 2009 12:23:15 PM" ,
511
+ "28 July, 2009 12:23:15 PM" ,
512
+ "28 July, 2009 12:23:15" ,
513
+ "28 July, 2009 12:23:15" ,
514
+ "July 2009" ,
515
+ "July 2009" ,
516
+ } ;
314
517
}
315
518
0 commit comments