@@ -36,8 +36,7 @@ impl ResolvedCalendarFields {
36
36
) -> TemporalResult < Self > {
37
37
let era_year = EraYear :: try_from_partial_date ( partial_date) ?;
38
38
if partial_date. calendar . is_iso ( ) {
39
- let month_code =
40
- resolve_iso_month ( partial_date. month_code , partial_date. month , overflow) ?;
39
+ let month_code = resolve_iso_month ( partial_date, overflow) ?;
41
40
let day = resolve_day ( partial_date. day , resolve_type == ResolutionType :: YearMonth ) ?;
42
41
let day = if overflow == ArithmeticOverflow :: Constrain {
43
42
constrain_iso_day ( era_year. year , month_code. to_month_integer ( ) , day)
@@ -325,13 +324,12 @@ const fn ascii_digit_to_int(ascii_digit: u8) -> u8 {
325
324
}
326
325
327
326
fn resolve_iso_month (
328
- mc : Option < MonthCode > ,
329
- month : Option < u8 > ,
327
+ partial_date : & PartialDate ,
330
328
overflow : ArithmeticOverflow ,
331
329
) -> TemporalResult < MonthCode > {
332
- match ( mc , month) {
330
+ let month_code = match ( partial_date . month_code , partial_date . month ) {
333
331
( None , None ) => {
334
- Err ( TemporalError :: r#type ( ) . with_message ( "Month or monthCode must be provided." ) )
332
+ return Err ( TemporalError :: r#type ( ) . with_message ( "Month or monthCode must be provided." ) )
335
333
}
336
334
( None , Some ( month) ) => {
337
335
if overflow == ArithmeticOverflow :: Constrain {
@@ -342,20 +340,19 @@ fn resolve_iso_month(
342
340
TemporalError :: range ( ) . with_message ( "month value is not in a valid range." )
343
341
) ;
344
342
}
345
- month_to_month_code ( month)
343
+ month_to_month_code ( month) ?
346
344
}
347
- ( Some ( mc) , None ) => {
348
- // Check that monthCode is parsable.
349
- Ok ( mc)
350
- }
351
- ( Some ( mc) , Some ( month) ) => {
352
- if month != mc. to_month_integer ( ) {
345
+ ( Some ( month_code) , None ) => month_code,
346
+ ( Some ( month_code) , Some ( month) ) => {
347
+ if month != month_code. to_month_integer ( ) {
353
348
return Err ( TemporalError :: range ( )
354
349
. with_message ( "month and monthCode could not be resolved." ) ) ;
355
350
}
356
- Ok ( mc )
351
+ month_code
357
352
}
358
- }
353
+ } ;
354
+ month_code. validate ( & partial_date. calendar ) ?;
355
+ Ok ( month_code)
359
356
}
360
357
361
358
#[ cfg( test) ]
0 commit comments