@@ -360,45 +360,52 @@ mod tests {
360
360
361
361
#[ test]
362
362
fn leap_second ( ) {
363
- let ( date_2015, date_2022) = ( Utc . ymd ( 2015 , 6 , 30 ) , Utc . ymd ( 2022 , 6 , 30 ) ) ;
363
+ let ( date_2015, date_2022) = (
364
+ NaiveDate :: from_ymd_opt ( 2015 , 6 , 30 ) . unwrap ( ) ,
365
+ NaiveDate :: from_ymd_opt ( 2022 , 6 , 30 ) . unwrap ( ) ,
366
+ ) ;
364
367
365
- enum UtcKind {
368
+ enum Kind {
366
369
NonLeap ,
367
370
Leap ,
368
371
}
369
372
370
373
let datetimes = [
371
374
(
372
- UtcKind :: NonLeap ,
373
- date_2015. and_hms_nano ( 23 , 59 , 59 , 100_000_000 ) ,
375
+ Kind :: NonLeap ,
376
+ date_2015. and_hms_nano_opt ( 23 , 59 , 59 , 100_000_000 ) . unwrap ( ) ,
374
377
) ,
375
378
(
376
- UtcKind :: Leap ,
377
- date_2015. and_hms_nano ( 23 , 59 , 59 , 1_000_000_000 ) ,
379
+ Kind :: Leap ,
380
+ date_2015
381
+ . and_hms_nano_opt ( 23 , 59 , 59 , 1_000_000_000 )
382
+ . unwrap ( ) ,
378
383
) ,
379
384
(
380
- UtcKind :: Leap ,
381
- date_2015. and_hms_nano ( 23 , 59 , 59 , 1_100_000_000 ) ,
385
+ Kind :: Leap ,
386
+ date_2015
387
+ . and_hms_nano_opt ( 23 , 59 , 59 , 1_100_000_000 )
388
+ . unwrap ( ) ,
382
389
) ,
383
- ( UtcKind :: NonLeap , date_2022. and_hms ( 23 , 59 , 59 ) ) ,
390
+ ( Kind :: NonLeap , date_2022. and_hms_opt ( 23 , 59 , 59 ) . unwrap ( ) ) ,
384
391
(
385
- UtcKind :: NonLeap ,
386
- date_2022. and_hms_nano ( 23 , 59 , 59 , 100_000_000 ) ,
392
+ Kind :: NonLeap ,
393
+ date_2022. and_hms_nano_opt ( 23 , 59 , 59 , 100_000_000 ) . unwrap ( ) ,
387
394
) ,
388
395
] ;
389
396
390
397
let mut cacher = LocalTimeCacher :: new ( ) ;
391
398
392
399
for datetime in datetimes {
393
400
let leap = match datetime. 0 {
394
- UtcKind :: NonLeap => false ,
395
- UtcKind :: Leap => true ,
401
+ Kind :: NonLeap => false ,
402
+ Kind :: Leap => true ,
396
403
} ;
397
- let utc = datetime. 1 ;
404
+ let datetime = datetime. 1 ;
398
405
399
- println ! ( " => checking '{utc }'" ) ;
406
+ println ! ( " => checking '{datetime }'" ) ;
400
407
401
- let result = cacher. get_inner ( utc ) ;
408
+ let result = cacher. get_inner ( datetime . and_local_timezone ( Utc ) . unwrap ( ) ) ;
402
409
assert_eq ! ( result. cached. is_leap_second, leap) ;
403
410
assert_eq ! ( result. second( ) , if !leap { 59 } else { 60 } ) ;
404
411
}
0 commit comments