@@ -2073,36 +2073,49 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
20732073 isLeapYear = false
20742074 }
20752075
2076- var dc = DateComponents ( )
2077- if components. contains ( . calendar) {
2078- var calendar = Calendar ( identifier: . gregorian)
2079- calendar. timeZone = timeZone
2080- dc. calendar = calendar
2081- }
2082- if components. contains ( . timeZone) { dc. timeZone = timeZone }
2076+ var dcCalendar : Calendar ?
2077+ var dcTimeZone : TimeZone ?
2078+ var dcEra : Int ?
2079+ var dcYear : Int ?
2080+ var dcMonth : Int ?
2081+ var dcDay : Int ?
2082+ var dcDayOfYear : Int ?
2083+ var dcHour : Int ?
2084+ var dcMinute : Int ?
2085+ var dcSecond : Int ?
2086+ var dcWeekday : Int ?
2087+ var dcWeekdayOrdinal : Int ?
2088+ var dcQuarter : Int ?
2089+ var dcWeekOfMonth : Int ?
2090+ var dcWeekOfYear : Int ?
2091+ var dcYearForWeekOfYear : Int ?
2092+ var dcNanosecond : Int ?
2093+ var dcIsLeapMonth : Bool ?
2094+
2095+ // DateComponents sets the time zone on the calendar if appropriate
2096+ if components. contains ( . calendar) { dcCalendar = Calendar ( identifier: identifier) }
2097+ if components. contains ( . timeZone) { dcTimeZone = timeZone }
20832098 if components. contains ( . era) {
2084- let era : Int
20852099 if year < 1 {
2086- era = 0
2100+ dcEra = 0
20872101 } else {
2088- era = 1
2102+ dcEra = 1
20892103 }
2090- dc. era = era
20912104 }
20922105 if components. contains ( . year) {
20932106 if year < 1 {
20942107 year = 1 - year
20952108 }
2096- dc . year = year
2109+ dcYear = year
20972110 }
2098- if components. contains ( . month) { dc . month = month }
2099- if components. contains ( . day) { dc . day = day }
2100- if components. contains ( . dayOfYear) { dc . dayOfYear = dayOfYear }
2101- if components. contains ( . hour) { dc . hour = hour }
2102- if components. contains ( . minute) { dc . minute = minute }
2103- if components. contains ( . second) { dc . second = second }
2104- if components. contains ( . weekday) { dc . weekday = weekday }
2105- if components. contains ( . weekdayOrdinal) { dc . weekdayOrdinal = weekdayOrdinal }
2111+ if components. contains ( . month) { dcMonth = month }
2112+ if components. contains ( . day) { dcDay = day }
2113+ if components. contains ( . dayOfYear) { dcDayOfYear = dayOfYear }
2114+ if components. contains ( . hour) { dcHour = hour }
2115+ if components. contains ( . minute) { dcMinute = minute }
2116+ if components. contains ( . second) { dcSecond = second }
2117+ if components. contains ( . weekday) { dcWeekday = weekday }
2118+ if components. contains ( . weekdayOrdinal) { dcWeekdayOrdinal = weekdayOrdinal }
21062119 if components. contains ( . quarter) {
21072120 let quarter = if !isLeapYear {
21082121 if dayOfYear < 90 { 1 }
@@ -2118,15 +2131,16 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
21182131 else { fatalError ( ) }
21192132 }
21202133
2121- dc . quarter = quarter
2134+ dcQuarter = quarter
21222135 }
2123- if components. contains ( . weekOfMonth) { dc . weekOfMonth = weekOfMonth }
2124- if components. contains ( . weekOfYear) { dc . weekOfYear = weekOfYear }
2125- if components. contains ( . yearForWeekOfYear) { dc . yearForWeekOfYear = yearForWeekOfYear }
2126- if components. contains ( . nanosecond) { dc . nanosecond = nanosecond }
2136+ if components. contains ( . weekOfMonth) { dcWeekOfMonth = weekOfMonth }
2137+ if components. contains ( . weekOfYear) { dcWeekOfYear = weekOfYear }
2138+ if components. contains ( . yearForWeekOfYear) { dcYearForWeekOfYear = yearForWeekOfYear }
2139+ if components. contains ( . nanosecond) { dcNanosecond = nanosecond }
21272140
2128- if components. contains ( . isLeapMonth) || components. contains ( . month) { dc. isLeapMonth = false }
2129- return dc
2141+ if components. contains ( . isLeapMonth) || components. contains ( . month) { dcIsLeapMonth = false }
2142+
2143+ return DateComponents ( calendar: dcCalendar, timeZone: dcTimeZone, rawEra: dcEra, rawYear: dcYear, rawMonth: dcMonth, rawDay: dcDay, rawHour: dcHour, rawMinute: dcMinute, rawSecond: dcSecond, rawNanosecond: dcNanosecond, rawWeekday: dcWeekday, rawWeekdayOrdinal: dcWeekdayOrdinal, rawQuarter: dcQuarter, rawWeekOfMonth: dcWeekOfMonth, rawWeekOfYear: dcWeekOfYear, rawYearForWeekOfYear: dcYearForWeekOfYear, rawDayOfYear: dcDayOfYear, isLeapMonth: dcIsLeapMonth)
21302144 }
21312145
21322146 func dateComponents( _ components: Calendar . ComponentSet , from date: Date ) -> DateComponents {
0 commit comments