File tree 3 files changed +18
-6
lines changed
3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -216,12 +216,12 @@ macro_rules! cascade {
216
216
cascade!( @ordinal $ordinal) ;
217
217
cascade!( @year $year) ;
218
218
#[ allow( unused_assignments) ]
219
- if $ordinal > crate :: util:: days_in_year( $year) {
219
+ if $ordinal > crate :: util:: days_in_year( $year) as i16 {
220
+ $ordinal -= crate :: util:: days_in_year( $year) as i16 ;
220
221
$year += 1 ;
221
- $ordinal = 1 ;
222
- } else if $ordinal == 0 {
222
+ } else if $ordinal < 1 {
223
223
$year -= 1 ;
224
- $ordinal = crate :: util:: days_in_year( $year) ;
224
+ $ordinal + = crate :: util:: days_in_year( $year) as i16 ;
225
225
}
226
226
} ;
227
227
}
Original file line number Diff line number Diff line change @@ -152,7 +152,8 @@ impl OffsetDateTime {
152
152
let mut minute =
153
153
self . minute ( ) as i16 - from. minutes_past_hour ( ) as i16 + to. minutes_past_hour ( ) as i16 ;
154
154
let mut hour = self . hour ( ) as i8 - from. whole_hours ( ) + to. whole_hours ( ) ;
155
- let ( mut year, mut ordinal) = self . to_ordinal_date ( ) ;
155
+ let ( mut year, ordinal) = self . to_ordinal_date ( ) ;
156
+ let mut ordinal = ordinal as i16 ;
156
157
157
158
// Cascade the values twice. This is needed because the values are adjusted twice above.
158
159
cascade ! ( second in 0 ..60 => minute) ;
@@ -163,9 +164,12 @@ impl OffsetDateTime {
163
164
cascade ! ( hour in 0 ..24 => ordinal) ;
164
165
cascade ! ( ordinal => year) ;
165
166
167
+ debug_assert ! ( ordinal > 0 ) ;
168
+ debug_assert ! ( ordinal <= crate :: util:: days_in_year( year) as i16 ) ;
169
+
166
170
(
167
171
year,
168
- ordinal,
172
+ ordinal as _ ,
169
173
Time :: __from_hms_nanos_unchecked (
170
174
hour as _ ,
171
175
minute as _ ,
Original file line number Diff line number Diff line change @@ -55,6 +55,14 @@ fn to_offset_panic() {
55
55
assert_panic ! ( PrimitiveDateTime :: MIN . assume_utc( ) . to_offset( offset!( -1 ) ) ) ;
56
56
}
57
57
58
+ #[ test]
59
+ fn to_offset_invalid_regression ( ) {
60
+ assert_eq ! (
61
+ datetime!( 2019 -01 -01 0 : 00 +13 ) . to_offset( offset!( -13 ) ) ,
62
+ datetime!( 2018 -12 -30 22 : 00 : 00 -13 ) ,
63
+ ) ;
64
+ }
65
+
58
66
#[ test]
59
67
fn from_unix_timestamp ( ) {
60
68
assert_eq ! (
You can’t perform that action at this time.
0 commit comments