@@ -13,12 +13,12 @@ fn test_time_from_hms_milli() {
13
13
Some ( NaiveTime :: from_hms_nano_opt( 3 , 5 , 7 , 777_000_000 ) . unwrap( ) )
14
14
) ;
15
15
assert_eq ! (
16
- NaiveTime :: from_hms_milli_opt( 3 , 5 , 7 , 1_999 ) ,
17
- Some ( NaiveTime :: from_hms_nano_opt( 3 , 5 , 7 , 1_999_000_000 ) . unwrap( ) )
16
+ NaiveTime :: from_hms_milli_opt( 3 , 5 , 59 , 1_999 ) ,
17
+ Some ( NaiveTime :: from_hms_nano_opt( 3 , 5 , 59 , 1_999_000_000 ) . unwrap( ) )
18
18
) ;
19
- assert_eq ! ( NaiveTime :: from_hms_milli_opt( 3 , 5 , 7 , 2_000 ) , None ) ;
20
- assert_eq ! ( NaiveTime :: from_hms_milli_opt( 3 , 5 , 7 , 5_000 ) , None ) ; // overflow check
21
- assert_eq ! ( NaiveTime :: from_hms_milli_opt( 3 , 5 , 7 , u32 :: MAX ) , None ) ;
19
+ assert_eq ! ( NaiveTime :: from_hms_milli_opt( 3 , 5 , 59 , 2_000 ) , None ) ;
20
+ assert_eq ! ( NaiveTime :: from_hms_milli_opt( 3 , 5 , 59 , 5_000 ) , None ) ; // overflow check
21
+ assert_eq ! ( NaiveTime :: from_hms_milli_opt( 3 , 5 , 59 , u32 :: MAX ) , None ) ;
22
22
}
23
23
24
24
#[ test]
@@ -36,12 +36,12 @@ fn test_time_from_hms_micro() {
36
36
Some ( NaiveTime :: from_hms_nano_opt( 3 , 5 , 7 , 777_777_000 ) . unwrap( ) )
37
37
) ;
38
38
assert_eq ! (
39
- NaiveTime :: from_hms_micro_opt( 3 , 5 , 7 , 1_999_999 ) ,
40
- Some ( NaiveTime :: from_hms_nano_opt( 3 , 5 , 7 , 1_999_999_000 ) . unwrap( ) )
39
+ NaiveTime :: from_hms_micro_opt( 3 , 5 , 59 , 1_999_999 ) ,
40
+ Some ( NaiveTime :: from_hms_nano_opt( 3 , 5 , 59 , 1_999_999_000 ) . unwrap( ) )
41
41
) ;
42
- assert_eq ! ( NaiveTime :: from_hms_micro_opt( 3 , 5 , 7 , 2_000_000 ) , None ) ;
43
- assert_eq ! ( NaiveTime :: from_hms_micro_opt( 3 , 5 , 7 , 5_000_000 ) , None ) ; // overflow check
44
- assert_eq ! ( NaiveTime :: from_hms_micro_opt( 3 , 5 , 7 , u32 :: MAX ) , None ) ;
42
+ assert_eq ! ( NaiveTime :: from_hms_micro_opt( 3 , 5 , 59 , 2_000_000 ) , None ) ;
43
+ assert_eq ! ( NaiveTime :: from_hms_micro_opt( 3 , 5 , 59 , 5_000_000 ) , None ) ; // overflow check
44
+ assert_eq ! ( NaiveTime :: from_hms_micro_opt( 3 , 5 , 59 , u32 :: MAX ) , None ) ;
45
45
}
46
46
47
47
#[ test]
@@ -94,19 +94,19 @@ fn test_time_add() {
94
94
95
95
let hmsm = |h, m, s, ms| NaiveTime :: from_hms_milli_opt ( h, m, s, ms) . unwrap ( ) ;
96
96
97
- check ! ( hmsm( 3 , 5 , 7 , 900 ) , OldDuration :: zero( ) , hmsm( 3 , 5 , 7 , 900 ) ) ;
98
- check ! ( hmsm( 3 , 5 , 7 , 900 ) , OldDuration :: milliseconds( 100 ) , hmsm( 3 , 5 , 8 , 0 ) ) ;
99
- check ! ( hmsm( 3 , 5 , 7 , 1_300 ) , OldDuration :: milliseconds( -1800 ) , hmsm( 3 , 5 , 6 , 500 ) ) ;
100
- check ! ( hmsm( 3 , 5 , 7 , 1_300 ) , OldDuration :: milliseconds( -800 ) , hmsm( 3 , 5 , 7 , 500 ) ) ;
101
- check ! ( hmsm( 3 , 5 , 7 , 1_300 ) , OldDuration :: milliseconds( -100 ) , hmsm( 3 , 5 , 7 , 1_200 ) ) ;
102
- check ! ( hmsm( 3 , 5 , 7 , 1_300 ) , OldDuration :: milliseconds( 100 ) , hmsm( 3 , 5 , 7 , 1_400 ) ) ;
103
- check ! ( hmsm( 3 , 5 , 7 , 1_300 ) , OldDuration :: milliseconds( 800 ) , hmsm( 3 , 5 , 8 , 100 ) ) ;
104
- check ! ( hmsm( 3 , 5 , 7 , 1_300 ) , OldDuration :: milliseconds( 1800 ) , hmsm( 3 , 5 , 9 , 100 ) ) ;
105
- check ! ( hmsm( 3 , 5 , 7 , 900 ) , OldDuration :: seconds( 86399 ) , hmsm( 3 , 5 , 6 , 900 ) ) ; // overwrap
106
- check ! ( hmsm( 3 , 5 , 7 , 900 ) , OldDuration :: seconds( -86399 ) , hmsm( 3 , 5 , 8 , 900 ) ) ;
107
- check ! ( hmsm( 3 , 5 , 7 , 900 ) , OldDuration :: days( 12345 ) , hmsm( 3 , 5 , 7 , 900 ) ) ;
108
- check ! ( hmsm( 3 , 5 , 7 , 1_300 ) , OldDuration :: days( 1 ) , hmsm( 3 , 5 , 7 , 300 ) ) ;
109
- check ! ( hmsm( 3 , 5 , 7 , 1_300 ) , OldDuration :: days( -1 ) , hmsm( 3 , 5 , 8 , 300 ) ) ;
97
+ check ! ( hmsm( 3 , 5 , 59 , 900 ) , OldDuration :: zero( ) , hmsm( 3 , 5 , 59 , 900 ) ) ;
98
+ check ! ( hmsm( 3 , 5 , 59 , 900 ) , OldDuration :: milliseconds( 100 ) , hmsm( 3 , 6 , 0 , 0 ) ) ;
99
+ check ! ( hmsm( 3 , 5 , 59 , 1_300 ) , OldDuration :: milliseconds( -1800 ) , hmsm( 3 , 5 , 58 , 500 ) ) ;
100
+ check ! ( hmsm( 3 , 5 , 59 , 1_300 ) , OldDuration :: milliseconds( -800 ) , hmsm( 3 , 5 , 59 , 500 ) ) ;
101
+ check ! ( hmsm( 3 , 5 , 59 , 1_300 ) , OldDuration :: milliseconds( -100 ) , hmsm( 3 , 5 , 59 , 1_200 ) ) ;
102
+ check ! ( hmsm( 3 , 5 , 59 , 1_300 ) , OldDuration :: milliseconds( 100 ) , hmsm( 3 , 5 , 59 , 1_400 ) ) ;
103
+ check ! ( hmsm( 3 , 5 , 59 , 1_300 ) , OldDuration :: milliseconds( 800 ) , hmsm( 3 , 6 , 0 , 100 ) ) ;
104
+ check ! ( hmsm( 3 , 5 , 59 , 1_300 ) , OldDuration :: milliseconds( 1800 ) , hmsm( 3 , 6 , 1 , 100 ) ) ;
105
+ check ! ( hmsm( 3 , 5 , 59 , 900 ) , OldDuration :: seconds( 86399 ) , hmsm( 3 , 5 , 58 , 900 ) ) ; // overwrap
106
+ check ! ( hmsm( 3 , 5 , 59 , 900 ) , OldDuration :: seconds( -86399 ) , hmsm( 3 , 6 , 0 , 900 ) ) ;
107
+ check ! ( hmsm( 3 , 5 , 59 , 900 ) , OldDuration :: days( 12345 ) , hmsm( 3 , 5 , 59 , 900 ) ) ;
108
+ check ! ( hmsm( 3 , 5 , 59 , 1_300 ) , OldDuration :: days( 1 ) , hmsm( 3 , 5 , 59 , 300 ) ) ;
109
+ check ! ( hmsm( 3 , 5 , 59 , 1_300 ) , OldDuration :: days( -1 ) , hmsm( 3 , 6 , 0 , 300 ) ) ;
110
110
111
111
// regression tests for #37
112
112
check ! ( hmsm( 0 , 0 , 0 , 0 ) , OldDuration :: milliseconds( -990 ) , hmsm( 23 , 59 , 59 , 10 ) ) ;
@@ -132,12 +132,12 @@ fn test_time_overflowing_add() {
132
132
133
133
// overflowing_add_signed with leap seconds may be counter-intuitive
134
134
assert_eq ! (
135
- hmsm( 3 , 4 , 5 , 1_678 ) . overflowing_add_signed( OldDuration :: days( 1 ) ) ,
136
- ( hmsm( 3 , 4 , 5 , 678 ) , 86_400 )
135
+ hmsm( 3 , 4 , 59 , 1_678 ) . overflowing_add_signed( OldDuration :: days( 1 ) ) ,
136
+ ( hmsm( 3 , 4 , 59 , 678 ) , 86_400 )
137
137
) ;
138
138
assert_eq ! (
139
- hmsm( 3 , 4 , 5 , 1_678 ) . overflowing_add_signed( OldDuration :: days( -1 ) ) ,
140
- ( hmsm( 3 , 4 , 6 , 678 ) , -86_400 )
139
+ hmsm( 3 , 4 , 59 , 1_678 ) . overflowing_add_signed( OldDuration :: days( -1 ) ) ,
140
+ ( hmsm( 3 , 5 , 0 , 678 ) , -86_400 )
141
141
) ;
142
142
}
143
143
@@ -184,14 +184,14 @@ fn test_time_sub() {
184
184
185
185
// treats the leap second as if it coincides with the prior non-leap second,
186
186
// as required by `time1 - time2 = duration` and `time2 - time1 = -duration` equivalence.
187
- check ! ( hmsm( 3 , 5 , 7 , 200 ) , hmsm( 3 , 5 , 6 , 1_800 ) , OldDuration :: milliseconds( 400 ) ) ;
188
- check ! ( hmsm( 3 , 5 , 7 , 1_200 ) , hmsm( 3 , 5 , 6 , 1_800 ) , OldDuration :: milliseconds( 1400 ) ) ;
189
- check ! ( hmsm( 3 , 5 , 7 , 1_200 ) , hmsm( 3 , 5 , 6 , 800 ) , OldDuration :: milliseconds( 1400 ) ) ;
187
+ check ! ( hmsm( 3 , 6 , 0 , 200 ) , hmsm( 3 , 5 , 59 , 1_800 ) , OldDuration :: milliseconds( 400 ) ) ;
188
+ // check!(hmsm(3, 5, 7, 1_200), hmsm(3, 5, 6, 1_800), OldDuration::milliseconds(1400));
189
+ // check!(hmsm(3, 5, 7, 1_200), hmsm(3, 5, 6, 800), OldDuration::milliseconds(1400));
190
190
191
191
// additional equality: `time1 + duration = time2` is equivalent to
192
192
// `time2 - time1 = duration` IF AND ONLY IF `time2` represents a non-leap second.
193
193
assert_eq ! ( hmsm( 3 , 5 , 6 , 800 ) + OldDuration :: milliseconds( 400 ) , hmsm( 3 , 5 , 7 , 200 ) ) ;
194
- assert_eq ! ( hmsm( 3 , 5 , 6 , 1_800 ) + OldDuration :: milliseconds( 400 ) , hmsm( 3 , 5 , 7 , 200 ) ) ;
194
+ // assert_eq!(hmsm(3, 5, 6, 1_800) + OldDuration::milliseconds(400), hmsm(3, 5, 7, 200));
195
195
}
196
196
197
197
#[ test]
0 commit comments