@@ -2073,36 +2073,49 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
2073
2073
isLeapYear = false
2074
2074
}
2075
2075
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 }
2083
2098
if components. contains ( . era) {
2084
- let era : Int
2085
2099
if year < 1 {
2086
- era = 0
2100
+ dcEra = 0
2087
2101
} else {
2088
- era = 1
2102
+ dcEra = 1
2089
2103
}
2090
- dc. era = era
2091
2104
}
2092
2105
if components. contains ( . year) {
2093
2106
if year < 1 {
2094
2107
year = 1 - year
2095
2108
}
2096
- dc . year = year
2109
+ dcYear = year
2097
2110
}
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 }
2106
2119
if components. contains ( . quarter) {
2107
2120
let quarter = if !isLeapYear {
2108
2121
if dayOfYear < 90 { 1 }
@@ -2118,15 +2131,16 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
2118
2131
else { fatalError ( ) }
2119
2132
}
2120
2133
2121
- dc . quarter = quarter
2134
+ dcQuarter = quarter
2122
2135
}
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 }
2127
2140
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)
2130
2144
}
2131
2145
2132
2146
func dateComponents( _ components: Calendar . ComponentSet , from date: Date ) -> DateComponents {
0 commit comments