Skip to content

Commit 173cb18

Browse files
committed
Implement copy() in DateFormatter.
1 parent 61b78c9 commit 173cb18

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Sources/Foundation/DateFormatter.swift

+45
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,51 @@ open class DateFormatter : Formatter {
3636
super.init(coder: coder)
3737
}
3838

39+
open override func copy(with zone: NSZone? = nil) -> Any {
40+
let copied = DateFormatter()
41+
42+
func __copy<T>(_ keyPath: ReferenceWritableKeyPath<DateFormatter, T>) {
43+
copied[keyPath: keyPath] = self[keyPath: keyPath]
44+
}
45+
46+
__copy(\.formattingContext)
47+
__copy(\.dateStyle)
48+
__copy(\.timeStyle)
49+
__copy(\._locale)
50+
__copy(\.generatesCalendarDates)
51+
__copy(\._timeZone)
52+
__copy(\._calendar)
53+
__copy(\.isLenient)
54+
__copy(\._twoDigitStartDate)
55+
__copy(\._eraSymbols)
56+
__copy(\._monthSymbols)
57+
__copy(\._shortMonthSymbols)
58+
__copy(\._weekdaySymbols)
59+
__copy(\._shortWeekdaySymbols)
60+
__copy(\._amSymbol)
61+
__copy(\._pmSymbol)
62+
__copy(\._longEraSymbols)
63+
__copy(\._veryShortMonthSymbols)
64+
__copy(\._standaloneMonthSymbols)
65+
__copy(\._shortStandaloneMonthSymbols)
66+
__copy(\._veryShortStandaloneMonthSymbols)
67+
__copy(\._veryShortWeekdaySymbols)
68+
__copy(\._standaloneWeekdaySymbols)
69+
__copy(\._shortStandaloneWeekdaySymbols)
70+
__copy(\._veryShortStandaloneWeekdaySymbols)
71+
__copy(\._quarterSymbols)
72+
__copy(\._shortQuarterSymbols)
73+
__copy(\._standaloneQuarterSymbols)
74+
__copy(\._shortStandaloneQuarterSymbols)
75+
__copy(\._gregorianStartDate)
76+
__copy(\.doesRelativeDateFormatting)
77+
78+
// The last is `_dateFormat` because setting `dateStyle` and `timeStyle` make it `nil`.
79+
__copy(\._dateFormat)
80+
81+
return copied
82+
}
83+
3984
open var formattingContext: Context = .unknown // default is NSFormattingContextUnknown
4085

4186
@available(*, unavailable, renamed: "date(from:)")

0 commit comments

Comments
 (0)