@@ -515,25 +515,36 @@ end
515
515
end
516
516
517
517
@testset " AM/PM" begin
518
- for (t12,t24) in ((" 12:00am" ," 00:00" ), (" 12:07am" ," 00:07" ), (" 01:24AM" ," 01:24" ),
519
- (" 12:00pm" ," 12:00" ), (" 12:15pm" ," 12:15" ), (" 11:59PM" ," 23:59" ))
520
- d = DateTime (" 2018-01-01T$t24 :00" )
521
- t = Time (" $t24 :00" )
522
- for HH in (" HH" ," II" )
523
- @test DateTime (" 2018-01-01 $t12 " ," yyyy-mm-dd $HH :MMp" ) == d
524
- @test Time (" $t12 " ," $HH :MMp" ) == t
518
+ # get the current locale
519
+ LC_TIME = 2
520
+ time_locale = ccall (:setlocale , Cstring, (Cint, Cstring), LC_TIME, C_NULL )
521
+ try
522
+ # set the locale
523
+ ccall (:setlocale , Cstring, (Cint, Cstring), LC_TIME, " C" )
524
+
525
+ for (t12,t24) in ((" 12:00am" ," 00:00" ), (" 12:07am" ," 00:07" ), (" 01:24AM" ," 01:24" ),
526
+ (" 12:00pm" ," 12:00" ), (" 12:15pm" ," 12:15" ), (" 11:59PM" ," 23:59" ))
527
+ d = DateTime (" 2018-01-01T$t24 :00" )
528
+ t = Time (" $t24 :00" )
529
+ for HH in (" HH" ," II" )
530
+ @test DateTime (" 2018-01-01 $t12 " ," yyyy-mm-dd $HH :MMp" ) == d
531
+ @test Time (" $t12 " ," $HH :MMp" ) == t
532
+ end
533
+ tmstruct = Libc. strptime (" %I:%M%p" , t12)
534
+ @test Time (tmstruct) == t
535
+ @test uppercase (t12) == Dates. format (t, " II:MMp" ) ==
536
+ Dates. format (d, " II:MMp" ) ==
537
+ Libc. strftime (" %I:%M%p" , tmstruct)
525
538
end
526
- tmstruct = Libc . strptime ( " %I:%M%p " , t12 )
527
- @test Time (tmstruct) == t
528
- @test uppercase (t12) == Dates . format (t, " II:MMp " ) ==
529
- Dates . format (d, " II:MMp " ) ==
530
- Libc . strftime ( " %I:%M%p " , tmstruct )
531
- end
532
- for bad in ( " 00:24am " , " 00:24pm " , " 13:24pm " , " 2pm " , " 12:24p.m. " , " 12:24 pm " , " 12:24pµ " )
533
- @eval @test_throws ArgumentError Time ( $ bad, " II:MMp " )
539
+ for bad in ( " 00:24am " , " 00:24pm " , " 13:24pm " , " 2pm " , " 12:24p.m. " , " 12:24 pm " , " 12:24pµ " )
540
+ @eval @test_throws ArgumentError Time ($ bad, " II:MMp " )
541
+ end
542
+ # if am/pm is missing, defaults to 24-hour clock
543
+ @eval Time ( " 13:24 " , " II:MMp " ) == Time ( " 13:24 " , " HH:MM " )
544
+ finally
545
+ # recover the locale
546
+ ccall ( :setlocale , Cstring, (Cint, Cstring), LC_TIME, time_locale )
534
547
end
535
- # if am/pm is missing, defaults to 24-hour clock
536
- @eval Time (" 13:24" , " II:MMp" ) == Time (" 13:24" , " HH:MM" )
537
548
end
538
549
539
550
end
0 commit comments