@@ -686,7 +686,8 @@ impl Add<StdDuration> for Time {
686686 /// ```
687687 #[ inline( always) ]
688688 fn add ( self , duration : StdDuration ) -> Self :: Output {
689- self + Duration :: seconds ( ( duration. as_secs ( ) % 86_400 ) as i64 )
689+ self + Duration :: try_from ( duration)
690+ . expect ( "overflow converting `core::time::Duration` to `time::Duration`" )
690691 }
691692}
692693
@@ -770,7 +771,8 @@ impl Sub<StdDuration> for Time {
770771 /// ```
771772 #[ inline( always) ]
772773 fn sub ( self , duration : StdDuration ) -> Self :: Output {
773- self - Duration :: seconds ( ( duration. as_secs ( ) % 86_400 ) as i64 )
774+ self - Duration :: try_from ( duration)
775+ . expect ( "overflow converting `core::time::Duration` to `time::Duration`" )
774776 }
775777}
776778
@@ -1234,6 +1236,10 @@ mod test {
12341236
12351237 #[ test]
12361238 fn add_std_duration ( ) -> crate :: Result < ( ) > {
1239+ assert_eq ! (
1240+ time!( 0 : 00 ) + 1 . std_milliseconds( ) ,
1241+ time!( 0 : 00 : 00 : 001_000_000 )
1242+ ) ;
12371243 assert_eq ! ( time!( 0 : 00 ) + 1 . std_seconds( ) , time!( 0 : 00 : 01 ) ) ;
12381244 assert_eq ! ( time!( 0 : 00 ) + 1 . std_minutes( ) , time!( 0 : 01 ) ) ;
12391245 assert_eq ! ( time!( 0 : 00 ) + 1 . std_hours( ) , time!( 1 : 00 ) ) ;
@@ -1264,6 +1270,10 @@ mod test {
12641270 assert_eq ! ( time!( 12 : 00 ) - 1 . std_hours( ) , time!( 11 : 00 ) ) ;
12651271
12661272 // Underflow
1273+ assert_eq ! (
1274+ time!( 0 : 00 ) - 1 . std_milliseconds( ) ,
1275+ time!( 23 : 59 : 59 : 999_000_000 )
1276+ ) ;
12671277 assert_eq ! ( time!( 0 : 00 ) - 1 . std_seconds( ) , time!( 23 : 59 : 59 ) ) ;
12681278 assert_eq ! ( time!( 0 : 00 ) - 1 . std_minutes( ) , time!( 23 : 59 ) ) ;
12691279 assert_eq ! ( time!( 0 : 00 ) - 1 . std_hours( ) , time!( 23 : 00 ) ) ;
0 commit comments