File tree Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,14 @@ Versioning].
77
88---
99
10- ## Unreleased
10+ ## 0.2.12 [ 2020-04-30]
11+
12+ ### Fixed
13+
14+ Subtracting ` Instant ` s can correctly result in a negative duration, rather than
15+ resulting in the absolute value of it.
16+
17+ ## 0.2.11 [ 2020-04-27]
1118
1219### Added
1320
Original file line number Diff line number Diff line change 11[package ]
22name = " time"
3- version = " 0.2.11 "
3+ version = " 0.2.12 "
44authors = [
" Jacob Pratt <[email protected] >" ]
55edition = " 2018"
66repository = " https://github.com/time-rs/time"
Original file line number Diff line number Diff line change @@ -154,8 +154,7 @@ impl Sub for Instant {
154154 Ordering :: Greater => ( self . inner - other. inner )
155155 . try_into ( )
156156 . expect ( "overflow converting `std::time::Duration` to `time::Duration`" ) ,
157- Ordering :: Less => ( other. inner - self . inner )
158- . try_into ( )
157+ Ordering :: Less => -Duration :: try_from ( other. inner - self . inner )
159158 . expect ( "overflow converting `std::time::Duration` to `time::Duration`" ) ,
160159 }
161160 }
@@ -496,4 +495,19 @@ mod test {
496495 let now_std = StdInstant :: from ( now_time) - 1 . seconds ( ) ;
497496 assert ! ( now_std < now_time) ;
498497 }
498+
499+ #[ test]
500+ fn sub_regression ( ) {
501+ let now = Instant :: now ( ) ;
502+ let future = now + Duration :: seconds ( 5 ) ;
503+ let past = now - Duration :: seconds ( 5 ) ;
504+
505+ assert_eq ! ( future - now, Duration :: seconds( 5 ) ) ;
506+ assert_eq ! ( now - past, Duration :: seconds( 5 ) ) ;
507+ assert_eq ! ( future - past, Duration :: seconds( 10 ) ) ;
508+
509+ assert_eq ! ( now - future, Duration :: seconds( -5 ) ) ;
510+ assert_eq ! ( past - now, Duration :: seconds( -5 ) ) ;
511+ assert_eq ! ( past - future, Duration :: seconds( -10 ) ) ;
512+ }
499513}
You can’t perform that action at this time.
0 commit comments