@@ -22,10 +22,16 @@ import {
22
22
SetSlot
23
23
} from './slots' ;
24
24
import type { Temporal } from '..' ;
25
- import type { BuiltinCalendarId , CalendarParams as Params , CalendarReturn as Return } from './internaltypes' ;
25
+ import type {
26
+ BuiltinCalendarId ,
27
+ CalendarParams as Params ,
28
+ CalendarReturn as Return ,
29
+ AnyTemporalKey
30
+ } from './internaltypes' ;
26
31
27
32
const ArrayIncludes = Array . prototype . includes ;
28
33
const ArrayPrototypePush = Array . prototype . push ;
34
+ const ArrayPrototypeSort = Array . prototype . sort ;
29
35
const IntlDateTimeFormat = globalThis . Intl . DateTimeFormat ;
30
36
const ArraySort = Array . prototype . sort ;
31
37
const MathAbs = Math . abs ;
@@ -2283,12 +2289,9 @@ class NonIsoCalendar implements CalendarImpl {
2283
2289
) : Temporal . PlainDate {
2284
2290
const overflow = ES . ToTemporalOverflow ( options ) ;
2285
2291
const cache = new OneObjectCache ( ) ;
2286
- // Intentionally alphabetical
2287
- const fields = ES . PrepareTemporalFields (
2288
- fieldsParam ,
2289
- [ 'day' , 'era' , 'eraYear' , 'month' , 'monthCode' , 'year' ] ,
2290
- [ 'day' ]
2291
- ) ;
2292
+ const fieldNames = this . fields ( [ 'day' , 'month' , 'monthCode' , 'year' ] ) as readonly AnyTemporalKey [ ] ;
2293
+ ArrayPrototypeSort . call ( fieldNames ) ;
2294
+ const fields = ES . PrepareTemporalFields ( fieldsParam , fieldNames , [ ] ) ;
2292
2295
const { year, month, day } = this . helper . calendarToIsoDate ( fields , overflow , cache ) ;
2293
2296
const result = ES . CreateTemporalDate ( year , month , day , calendar ) ;
2294
2297
cache . setObject ( result ) ;
@@ -2301,8 +2304,9 @@ class NonIsoCalendar implements CalendarImpl {
2301
2304
) : Temporal . PlainYearMonth {
2302
2305
const overflow = ES . ToTemporalOverflow ( options ) ;
2303
2306
const cache = new OneObjectCache ( ) ;
2304
- // Intentionally alphabetical
2305
- const fields = ES . PrepareTemporalFields ( fieldsParam , [ 'era' , 'eraYear' , 'month' , 'monthCode' , 'year' ] , [ ] ) ;
2307
+ const fieldNames = this . fields ( [ 'month' , 'monthCode' , 'year' ] ) as readonly AnyTemporalKey [ ] ;
2308
+ ArrayPrototypeSort . call ( fieldNames ) ;
2309
+ const fields = ES . PrepareTemporalFields ( fieldsParam , fieldNames , [ ] ) ;
2306
2310
const { year, month, day } = this . helper . calendarToIsoDate ( { ...fields , day : 1 } , overflow , cache ) ;
2307
2311
const result = ES . CreateTemporalYearMonth ( year , month , calendar , /* referenceISODay = */ day ) ;
2308
2312
cache . setObject ( result ) ;
@@ -2314,16 +2318,12 @@ class NonIsoCalendar implements CalendarImpl {
2314
2318
calendar : Temporal . Calendar
2315
2319
) : Temporal . PlainMonthDay {
2316
2320
const overflow = ES . ToTemporalOverflow ( options ) ;
2317
- // All built-in calendars require `day`, but some allow other fields to be
2318
- // substituted for `month`. And for lunisolar calendars, either `monthCode`
2319
- // or `year` must be provided because `month` is ambiguous without a year or
2320
- // a code.
2321
2321
const cache = new OneObjectCache ( ) ;
2322
- const fields = ES . PrepareTemporalFields (
2323
- fieldsParam ,
2324
- [ 'day' , 'era' , 'eraYear' , ' month', 'monthCode' , 'year' ] ,
2325
- [ 'day' ]
2326
- ) ;
2322
+ // For lunisolar calendars, either `monthCode` or `year` must be provided
2323
+ // because `month` is ambiguous without a year or a code.
2324
+ const fieldNames = this . fields ( [ 'day' , 'month' , 'monthCode' , 'year' ] ) as readonly AnyTemporalKey [ ] ;
2325
+ ArrayPrototypeSort . call ( fieldNames ) ;
2326
+ const fields = ES . PrepareTemporalFields ( fieldsParam , fieldNames , [ ] ) ;
2327
2327
const { year, month, day } = this . helper . monthDayFromFields ( fields , overflow , cache ) ;
2328
2328
// `year` is a reference year where this month/day exists in this calendar
2329
2329
const result = ES . CreateTemporalMonthDay ( month , day , calendar , /* referenceISOYear = */ year ) ;
0 commit comments