@@ -88,92 +88,131 @@ public struct DateComponents : ReferenceConvertible, Hashable, Equatable, _Mutab
8888 /// - note: This value is interpreted in the context of the calendar in which it is used.
8989 public var era : Int ? {
9090 get { return _handle. map { _getter ( $0. era) } }
91- set { _applyMutation { $0. era = _setter ( newValue) } }
91+ set {
92+ let value = _setter ( newValue)
93+ _applyMutation { $0. era = value }
94+ }
9295 }
9396
9497 /// A year or count of years.
9598 /// - note: This value is interpreted in the context of the calendar in which it is used.
9699 public var year : Int ? {
97100 get { return _handle. map { _getter ( $0. year) } }
98- set { _applyMutation { $0. year = _setter ( newValue) } }
101+ set {
102+ let value = _setter ( newValue)
103+ _applyMutation { $0. year = value }
104+ }
99105 }
100106
101107 /// A month or count of months.
102108 /// - note: This value is interpreted in the context of the calendar in which it is used.
103109 public var month : Int ? {
104110 get { return _handle. map { _getter ( $0. month) } }
105- set { _applyMutation { $0. month = _setter ( newValue) } }
111+ set {
112+ let value = _setter ( newValue)
113+ _applyMutation { $0. month = value }
114+ }
106115 }
107116
108117 /// A day or count of days.
109118 /// - note: This value is interpreted in the context of the calendar in which it is used.
110119 public var day : Int ? {
111120 get { return _handle. map { _getter ( $0. day) } }
112- set { _applyMutation { $0. day = _setter ( newValue) } }
121+ set {
122+ let value = _setter ( newValue)
123+ _applyMutation { $0. day = value }
124+ }
113125 }
114126
115127 /// An hour or count of hours.
116128 /// - note: This value is interpreted in the context of the calendar in which it is used.
117129 public var hour : Int ? {
118130 get { return _handle. map { _getter ( $0. hour) } }
119- set { _applyMutation { $0. hour = _setter ( newValue) } }
131+ set {
132+ let value = _setter ( newValue)
133+ _applyMutation { $0. hour = value }
134+ }
120135 }
121136
122137 /// A minute or count of minutes.
123138 /// - note: This value is interpreted in the context of the calendar in which it is used.
124139 public var minute : Int ? {
125140 get { return _handle. map { _getter ( $0. minute) } }
126- set { _applyMutation { $0. minute = _setter ( newValue) } }
141+ set {
142+ let value = _setter ( newValue)
143+ _applyMutation { $0. minute = value }
144+ }
127145 }
128146
129147 /// A second or count of seconds.
130148 /// - note: This value is interpreted in the context of the calendar in which it is used.
131149 public var second : Int ? {
132150 get { return _handle. map { _getter ( $0. second) } }
133- set { _applyMutation { $0. second = _setter ( newValue) } }
151+ set {
152+ let value = _setter ( newValue)
153+ _applyMutation { $0. second = value }
154+ }
134155 }
135156
136157 /// A nanosecond or count of nanoseconds.
137158 /// - note: This value is interpreted in the context of the calendar in which it is used.
138159 public var nanosecond : Int ? {
139160 get { return _handle. map { _getter ( $0. nanosecond) } }
140- set { _applyMutation { $0. nanosecond = _setter ( newValue) } }
161+ set {
162+ let value = _setter ( newValue)
163+ _applyMutation { $0. nanosecond = value }
164+ }
141165 }
142166
143167 /// A weekday or count of weekdays.
144168 /// - note: This value is interpreted in the context of the calendar in which it is used.
145169 public var weekday : Int ? {
146170 get { return _handle. map { _getter ( $0. weekday) } }
147- set { _applyMutation { $0. weekday = _setter ( newValue) } }
171+ set {
172+ let value = _setter ( newValue)
173+ _applyMutation { $0. weekday = value }
174+ }
148175 }
149176
150177 /// A weekday ordinal or count of weekday ordinals.
151178 /// Weekday ordinal units represent the position of the weekday within the next larger calendar unit, such as the month. For example, 2 is the weekday ordinal unit for the second Friday of the month.///
152179 /// - note: This value is interpreted in the context of the calendar in which it is used.
153180 public var weekdayOrdinal : Int ? {
154181 get { return _handle. map { _getter ( $0. weekdayOrdinal) } }
155- set { _applyMutation { $0. weekdayOrdinal = _setter ( newValue) } }
182+ set {
183+ let value = _setter ( newValue)
184+ _applyMutation { $0. weekdayOrdinal = value }
185+ }
156186 }
157187
158188 /// A quarter or count of quarters.
159189 /// - note: This value is interpreted in the context of the calendar in which it is used.
160190 public var quarter : Int ? {
161191 get { return _handle. map { _getter ( $0. quarter) } }
162- set { _applyMutation { $0. quarter = _setter ( newValue) } }
192+ set {
193+ let value = _setter ( newValue)
194+ _applyMutation { $0. quarter = value }
195+ }
163196 }
164197
165198 /// A week of the month or a count of weeks of the month.
166199 /// - note: This value is interpreted in the context of the calendar in which it is used.
167200 public var weekOfMonth : Int ? {
168201 get { return _handle. map { _getter ( $0. weekOfMonth) } }
169- set { _applyMutation { $0. weekOfMonth = _setter ( newValue) } }
202+ set {
203+ let value = _setter ( newValue)
204+ _applyMutation { $0. weekOfMonth = value }
205+ }
170206 }
171207
172208 /// A week of the year or count of the weeks of the year.
173209 /// - note: This value is interpreted in the context of the calendar in which it is used.
174210 public var weekOfYear : Int ? {
175211 get { return _handle. map { _getter ( $0. weekOfYear) } }
176- set { _applyMutation { $0. weekOfYear = _setter ( newValue) } }
212+ set {
213+ let value = _setter ( newValue)
214+ _applyMutation { $0. weekOfYear = value }
215+ }
177216 }
178217
179218 /// The ISO 8601 week-numbering year of the receiver.
@@ -184,7 +223,10 @@ public struct DateComponents : ReferenceConvertible, Hashable, Equatable, _Mutab
184223 /// - note: This value is interpreted in the context of the calendar in which it is used.
185224 public var yearForWeekOfYear : Int ? {
186225 get { return _handle. map { _getter ( $0. yearForWeekOfYear) } }
187- set { _applyMutation { $0. yearForWeekOfYear = _setter ( newValue) } }
226+ set {
227+ let value = _setter ( newValue)
228+ _applyMutation { $0. yearForWeekOfYear = value }
229+ }
188230 }
189231
190232 /// Set to true if these components represent a leap month.
@@ -217,8 +259,9 @@ public struct DateComponents : ReferenceConvertible, Hashable, Equatable, _Mutab
217259 ///
218260 /// The calendar and timeZone and isLeapMonth properties cannot be set by this method.
219261 public mutating func setValue( _ value: Int ? , for component: Calendar . Component ) {
262+ let _value = _setter ( value)
220263 _applyMutation {
221- $0. setValue ( _setter ( value ) , forComponent: Calendar . _toCalendarUnit ( [ component] ) )
264+ $0. setValue ( _value , forComponent: Calendar . _toCalendarUnit ( [ component] ) )
222265 }
223266 }
224267
0 commit comments