Skip to content

Commit a129b72

Browse files
authored
Merge pull request #853 from DRosadoYew/update-calendar
2 parents 63fbd33 + 86d9dea commit a129b72

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

Foundation/Calendar.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,15 +1132,35 @@ public struct Calendar : Hashable, Equatable, ReferenceConvertible, _MutableBoxi
11321132
}
11331133

11341134
extension Calendar : CustomDebugStringConvertible, CustomStringConvertible, CustomReflectable {
1135+
private var _kindDescription : String {
1136+
if self == .autoupdatingCurrent {
1137+
return "autoupdatingCurrent"
1138+
} else if self == .current {
1139+
return "current"
1140+
} else {
1141+
return "fixed"
1142+
}
1143+
}
1144+
11351145
public var description: String {
1136-
return _handle.map { $0.description }
1146+
return "\(identifier) (\(_kindDescription))"
11371147
}
11381148

11391149
public var debugDescription: String {
1140-
return _handle.map { $0.debugDescription }
1150+
return "\(identifier) (\(_kindDescription))"
11411151
}
11421152

1143-
public var customMirror: Mirror { NSUnimplemented() }
1153+
public var customMirror: Mirror {
1154+
let children: [(label: String?, value: Any)] = [
1155+
(label: "identifier", value: identifier),
1156+
(label: "kind", value: _kindDescription),
1157+
(label: "locale", value: locale as Any),
1158+
(label: "timeZone", value: timeZone),
1159+
(label: "firstWeekDay", value: firstWeekday),
1160+
(label: "minimumDaysInFirstWeek", value: minimumDaysInFirstWeek)
1161+
]
1162+
return Mirror(self, children: children, displayStyle: Mirror.DisplayStyle.struct)
1163+
}
11441164
}
11451165

11461166
extension Calendar: _ObjectTypeBridgeable {

TestFoundation/TestNSCalendar.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class TestNSCalendar: XCTestCase {
2828
("test_copy",test_copy),
2929
("test_addingDates", test_addingDates),
3030
("test_datesNotOnWeekend", test_datesNotOnWeekend),
31-
("test_datesOnWeekend", test_datesOnWeekend)
31+
("test_datesOnWeekend", test_datesOnWeekend),
32+
("test_customMirror", test_customMirror)
3233
// Disabled because this fails on linux https://bugs.swift.org/browse/SR-320
3334
// ("test_currentCalendarRRstability", test_currentCalendarRRstability),
3435
]
@@ -175,6 +176,17 @@ class TestNSCalendar: XCTestCase {
175176

176177
XCTAssertTrue(calendar.isDateInWeekend(sundayInFebruary))
177178
}
179+
180+
func test_customMirror() {
181+
let calendar = Calendar(identifier: .gregorian)
182+
let calendarMirror = calendar.customMirror
183+
184+
XCTAssertEqual(calendar.identifier, calendarMirror.descendant("identifier") as? Calendar.Identifier)
185+
XCTAssertEqual(calendar.locale, calendarMirror.descendant("locale") as? Locale)
186+
XCTAssertEqual(calendar.timeZone, calendarMirror.descendant("timeZone") as? TimeZone)
187+
XCTAssertEqual(calendar.firstWeekday, calendarMirror.descendant("firstWeekDay") as? Int)
188+
XCTAssertEqual(calendar.minimumDaysInFirstWeek, calendarMirror.descendant("minimumDaysInFirstWeek") as? Int)
189+
}
178190
}
179191

180192
class TestNSDateComponents: XCTestCase {

0 commit comments

Comments
 (0)