@@ -10,82 +10,56 @@ info: |
10
10
3. Assert: calendar.[[Identifier]] is "iso8601".
11
11
4. If Type(fields) is not Object, throw a TypeError exception.
12
12
5. Set options to ? GetOptionsObject(options).
13
- 6. Let result be ? ISOMonthDayFromFields(fields, options).
14
- 7. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], calendar, result.[[ReferenceISOYear]]).
13
+ 6. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »).
14
+ 7. Let overflow be ? ToTemporalOverflow(options).
15
+ 8. Perform ? ISOResolveMonth(fields).
16
+ 9. Let result be ? ISOMonthDayFromFields(fields, overflow).
17
+ 10. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], "iso8601", result.[[ReferenceISOYear]]).
15
18
includes: [temporalHelpers.js]
16
19
features: [Temporal]
17
20
---*/
18
21
19
22
const cal = new Temporal . Calendar ( "iso8601" ) ;
20
23
const opt = { overflow : "constrain" } ;
21
24
22
- let result = cal . monthDayFromFields ( { year : 2021 , month : 1 , day : 133 } , opt ) ;
23
- TemporalHelpers . assertPlainMonthDay ( result , "M01" , 31 , "day is constrained to 31 in month 1" ) ;
24
- result = cal . monthDayFromFields ( { year : 2021 , month : 2 , day : 133 } , opt ) ;
25
- TemporalHelpers . assertPlainMonthDay ( result , "M02" , 28 , "day is constrained to 28 in month 2 (year 2021)" ) ;
26
- result = cal . monthDayFromFields ( { year : 2021 , month : 3 , day : 9033 } , opt ) ;
27
- TemporalHelpers . assertPlainMonthDay ( result , "M03" , 31 , "day is constrained to 31 in month 3" ) ;
28
- result = cal . monthDayFromFields ( { year : 2021 , month : 4 , day : 50 } , opt ) ;
29
- TemporalHelpers . assertPlainMonthDay ( result , "M04" , 30 , "day is constrained to 30 in month 4" ) ;
30
- result = cal . monthDayFromFields ( { year : 2021 , month : 5 , day : 77 } , opt ) ;
31
- TemporalHelpers . assertPlainMonthDay ( result , "M05" , 31 , "day is constrained to 31 in month 5" ) ;
32
- result = cal . monthDayFromFields ( { year : 2021 , month : 6 , day : 33 } , opt ) ;
33
- TemporalHelpers . assertPlainMonthDay ( result , "M06" , 30 , "day is constrained to 30 in month 6" ) ;
34
- result = cal . monthDayFromFields ( { year : 2021 , month : 7 , day : 33 } , opt ) ;
35
- TemporalHelpers . assertPlainMonthDay ( result , "M07" , 31 , "day is constrained to 31 in month 7" ) ;
36
- result = cal . monthDayFromFields ( { year : 2021 , month : 8 , day : 300 } , opt ) ;
37
- TemporalHelpers . assertPlainMonthDay ( result , "M08" , 31 , "day is constrained to 31 in month 8" ) ;
38
- result = cal . monthDayFromFields ( { year : 2021 , month : 9 , day : 400 } , opt ) ;
39
- TemporalHelpers . assertPlainMonthDay ( result , "M09" , 30 , "day is constrained to 30 in month 9" ) ;
40
- result = cal . monthDayFromFields ( { year : 2021 , month : 10 , day : 400 } , opt ) ;
41
- TemporalHelpers . assertPlainMonthDay ( result , "M10" , 31 , "day is constrained to 31 in month 10" ) ;
42
- result = cal . monthDayFromFields ( { year : 2021 , month : 11 , day : 400 } , opt ) ;
43
- TemporalHelpers . assertPlainMonthDay ( result , "M11" , 30 , "day is constrained to 30 in month 11" ) ;
44
- result = cal . monthDayFromFields ( { year : 2021 , month : 12 , day : 500 } , opt ) ;
45
- TemporalHelpers . assertPlainMonthDay ( result , "M12" , 31 , "day is constrained to 31 in month 12" ) ;
46
-
47
- assert . throws (
48
- RangeError ,
49
- ( ) => cal . monthDayFromFields ( { year : 2021 , month : - 99999 , day : 1 } , opt ) ,
50
- "negative month -99999 is out of range even with overflow constrain"
51
- )
52
- assert . throws (
53
- RangeError ,
54
- ( ) => cal . monthDayFromFields ( { year : 2021 , month : - 1 , day : 1 } , opt ) ,
55
- "negative month -1 is out of range even with overflow constrain"
56
- )
57
- assert . throws (
58
- RangeError ,
59
- ( ) => cal . monthDayFromFields ( { year : 2021 , month : 0 , day : 1 } , opt ) ,
60
- "month zero is out of range even with overflow constrain"
61
- )
62
-
63
- result = cal . monthDayFromFields ( { year : 2021 , month : 13 , day : 1 } , opt ) ;
25
+ let result = cal . monthDayFromFields ( { year : 2021 , month : 13 , day : 1 } , opt ) ;
64
26
TemporalHelpers . assertPlainMonthDay ( result , "M12" , 1 , "month 13 is constrained to 12" ) ;
27
+
65
28
result = cal . monthDayFromFields ( { year : 2021 , month : 999999 , day : 500 } , opt ) ;
66
- TemporalHelpers . assertPlainMonthDay ( result , "M12" , 31 , "month 999999 is constrained to 12 and day constrained to 31" ) ;
29
+ TemporalHelpers . assertPlainMonthDay ( result , "M12" , 31 , "month 999999 is constrained to 12 and day 500 is constrained to 31" ) ;
30
+
31
+ [ - 99999 , - 1 , 0 ] . forEach ( ( month ) => {
32
+ assert . throws (
33
+ RangeError ,
34
+ ( ) => cal . monthDayFromFields ( { year : 2021 , month, day : 1 } , opt ) ,
35
+ `Month ${ month } is out of range for 2021 even with overflow: constrain`
36
+ ) ;
37
+ } ) ;
38
+
39
+ TemporalHelpers . ISOMonths . forEach ( ( { month, monthCode, daysInMonth } ) => {
40
+ const day = daysInMonth + 1 ;
41
+
42
+ result = cal . monthDayFromFields ( { month, day } , opt ) ;
43
+ TemporalHelpers . assertPlainMonthDay ( result , monthCode , daysInMonth ,
44
+ `day is constrained from ${ day } to ${ daysInMonth } in month ${ month } ` ) ;
45
+
46
+ result = cal . monthDayFromFields ( { month, day : 9001 } , opt ) ;
47
+ TemporalHelpers . assertPlainMonthDay ( result , monthCode , daysInMonth ,
48
+ `day is constrained to ${ daysInMonth } in month ${ month } ` ) ;
49
+
50
+ result = cal . monthDayFromFields ( { monthCode, day } , opt ) ;
51
+ TemporalHelpers . assertPlainMonthDay ( result , monthCode , daysInMonth ,
52
+ `day is constrained from ${ day } to ${ daysInMonth } in monthCode ${ monthCode } ` ) ;
53
+
54
+ result = cal . monthDayFromFields ( { monthCode, day : 9001 } , opt ) ;
55
+ TemporalHelpers . assertPlainMonthDay ( result , monthCode , daysInMonth ,
56
+ `day is constrained to ${ daysInMonth } in monthCode ${ monthCode } ` ) ;
57
+ } ) ;
58
+
59
+ [ [ "month" , 2 ] , [ "monthCode" , "M02" ] ] . forEach ( ( [ name , value ] ) => {
60
+ result = cal . monthDayFromFields ( { year : 2020 , [ name ] : value , day : 30 } , opt ) ;
61
+ TemporalHelpers . assertPlainMonthDay ( result , "M02" , 29 , `${ name } ${ value } is constrained to 29 in leap year 2020` ) ;
67
62
68
- result = cal . monthDayFromFields ( { monthCode : "M01" , day : 133 } , opt ) ;
69
- TemporalHelpers . assertPlainMonthDay ( result , "M01" , 31 , "day is constrained to 31 in monthCode M01" ) ;
70
- result = cal . monthDayFromFields ( { monthCode : "M02" , day : 133 } , opt ) ;
71
- TemporalHelpers . assertPlainMonthDay ( result , "M02" , 29 , "day is constrained to 29 in monthCode M02" ) ;
72
- result = cal . monthDayFromFields ( { monthCode : "M03" , day : 9033 } , opt ) ;
73
- TemporalHelpers . assertPlainMonthDay ( result , "M03" , 31 , "day is constrained to 31 in monthCode M03" ) ;
74
- result = cal . monthDayFromFields ( { monthCode : "M04" , day : 50 } , opt ) ;
75
- TemporalHelpers . assertPlainMonthDay ( result , "M04" , 30 , "day is constrained to 30 in monthCode M04" ) ;
76
- result = cal . monthDayFromFields ( { monthCode : "M05" , day : 77 } , opt ) ;
77
- TemporalHelpers . assertPlainMonthDay ( result , "M05" , 31 , "day is constrained to 31 in monthCode M05" ) ;
78
- result = cal . monthDayFromFields ( { monthCode : "M06" , day : 33 } , opt ) ;
79
- TemporalHelpers . assertPlainMonthDay ( result , "M06" , 30 , "day is constrained to 30 in monthCode M06" ) ;
80
- result = cal . monthDayFromFields ( { monthCode : "M07" , day : 33 } , opt ) ;
81
- TemporalHelpers . assertPlainMonthDay ( result , "M07" , 31 , "day is constrained to 31 in monthCode M07" ) ;
82
- result = cal . monthDayFromFields ( { monthCode : "M08" , day : 300 } , opt ) ;
83
- TemporalHelpers . assertPlainMonthDay ( result , "M08" , 31 , "day is constrained to 31 in monthCode M08" ) ;
84
- result = cal . monthDayFromFields ( { monthCode : "M09" , day : 400 } , opt ) ;
85
- TemporalHelpers . assertPlainMonthDay ( result , "M09" , 30 , "day is constrained to 30 in monthCode M09" ) ;
86
- result = cal . monthDayFromFields ( { monthCode : "M10" , day : 400 } , opt ) ;
87
- TemporalHelpers . assertPlainMonthDay ( result , "M10" , 31 , "day is constrained to 31 in monthCode M10" ) ;
88
- result = cal . monthDayFromFields ( { monthCode : "M11" , day : 400 } , opt ) ;
89
- TemporalHelpers . assertPlainMonthDay ( result , "M11" , 30 , "day is constrained to 30 in monthCode M11" ) ;
90
- result = cal . monthDayFromFields ( { monthCode : "M12" , day : 500 } , opt ) ;
91
- TemporalHelpers . assertPlainMonthDay ( result , "M12" , 31 , "day is constrained to 31 in monthCode M12" ) ;
63
+ result = cal . monthDayFromFields ( { year : 2021 , [ name ] : value , day : 29 } , opt ) ;
64
+ TemporalHelpers . assertPlainMonthDay ( result , "M02" , 28 , `${ name } ${ value } is constrained to 28 in common year 2021` ) ;
65
+ } ) ;
0 commit comments