@@ -88,92 +88,131 @@ public struct DateComponents : ReferenceConvertible, Hashable, Equatable, _Mutab
88
88
/// - note: This value is interpreted in the context of the calendar in which it is used.
89
89
public var era : Int ? {
90
90
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
+ }
92
95
}
93
96
94
97
/// A year or count of years.
95
98
/// - note: This value is interpreted in the context of the calendar in which it is used.
96
99
public var year : Int ? {
97
100
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
+ }
99
105
}
100
106
101
107
/// A month or count of months.
102
108
/// - note: This value is interpreted in the context of the calendar in which it is used.
103
109
public var month : Int ? {
104
110
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
+ }
106
115
}
107
116
108
117
/// A day or count of days.
109
118
/// - note: This value is interpreted in the context of the calendar in which it is used.
110
119
public var day : Int ? {
111
120
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
+ }
113
125
}
114
126
115
127
/// An hour or count of hours.
116
128
/// - note: This value is interpreted in the context of the calendar in which it is used.
117
129
public var hour : Int ? {
118
130
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
+ }
120
135
}
121
136
122
137
/// A minute or count of minutes.
123
138
/// - note: This value is interpreted in the context of the calendar in which it is used.
124
139
public var minute : Int ? {
125
140
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
+ }
127
145
}
128
146
129
147
/// A second or count of seconds.
130
148
/// - note: This value is interpreted in the context of the calendar in which it is used.
131
149
public var second : Int ? {
132
150
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
+ }
134
155
}
135
156
136
157
/// A nanosecond or count of nanoseconds.
137
158
/// - note: This value is interpreted in the context of the calendar in which it is used.
138
159
public var nanosecond : Int ? {
139
160
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
+ }
141
165
}
142
166
143
167
/// A weekday or count of weekdays.
144
168
/// - note: This value is interpreted in the context of the calendar in which it is used.
145
169
public var weekday : Int ? {
146
170
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
+ }
148
175
}
149
176
150
177
/// A weekday ordinal or count of weekday ordinals.
151
178
/// 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.///
152
179
/// - note: This value is interpreted in the context of the calendar in which it is used.
153
180
public var weekdayOrdinal : Int ? {
154
181
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
+ }
156
186
}
157
187
158
188
/// A quarter or count of quarters.
159
189
/// - note: This value is interpreted in the context of the calendar in which it is used.
160
190
public var quarter : Int ? {
161
191
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
+ }
163
196
}
164
197
165
198
/// A week of the month or a count of weeks of the month.
166
199
/// - note: This value is interpreted in the context of the calendar in which it is used.
167
200
public var weekOfMonth : Int ? {
168
201
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
+ }
170
206
}
171
207
172
208
/// A week of the year or count of the weeks of the year.
173
209
/// - note: This value is interpreted in the context of the calendar in which it is used.
174
210
public var weekOfYear : Int ? {
175
211
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
+ }
177
216
}
178
217
179
218
/// The ISO 8601 week-numbering year of the receiver.
@@ -184,7 +223,10 @@ public struct DateComponents : ReferenceConvertible, Hashable, Equatable, _Mutab
184
223
/// - note: This value is interpreted in the context of the calendar in which it is used.
185
224
public var yearForWeekOfYear : Int ? {
186
225
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
+ }
188
230
}
189
231
190
232
/// Set to true if these components represent a leap month.
@@ -217,8 +259,9 @@ public struct DateComponents : ReferenceConvertible, Hashable, Equatable, _Mutab
217
259
///
218
260
/// The calendar and timeZone and isLeapMonth properties cannot be set by this method.
219
261
public mutating func setValue( _ value: Int ? , for component: Calendar . Component ) {
262
+ let _value = _setter ( value)
220
263
_applyMutation {
221
- $0. setValue ( _setter ( value ) , forComponent: Calendar . _toCalendarUnit ( [ component] ) )
264
+ $0. setValue ( _value , forComponent: Calendar . _toCalendarUnit ( [ component] ) )
222
265
}
223
266
}
224
267
0 commit comments