Skip to content

Commit decb4a8

Browse files
committed
Calendar fixes.
- Fix Calendar.customMirror() to match behaviour on Darwin native Foundation (10.13.3) for firstWeekDay. - Update NSCalendar._symbol() to cast the CFDateFormatterCopyProperty() to a NSString not a CFString to fix NSCalendar.{amSymbol,pmSymbol}. This also allows un-XFAILing test_currentCalendarRRstability() which was failing on Linux because of this cast, not a refcounting issue as mentioned in SR-320.
1 parent 5ecb86c commit decb4a8

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

Foundation/Calendar.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ extension Calendar : CustomDebugStringConvertible, CustomStringConvertible, Cust
11561156
(label: "kind", value: _kindDescription),
11571157
(label: "locale", value: locale as Any),
11581158
(label: "timeZone", value: timeZone),
1159-
(label: "firstWeekDay", value: firstWeekday),
1159+
(label: "firstWeekday", value: firstWeekday),
11601160
(label: "minimumDaysInFirstWeek", value: minimumDaysInFirstWeek)
11611161
]
11621162
return Mirror(self, children: children, displayStyle: Mirror.DisplayStyle.struct)

Foundation/NSCalendar.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ open class NSCalendar : NSObject, NSCopying, NSSecureCoding {
298298
private func _symbol(_ key: CFString) -> String {
299299
let dateFormatter = CFDateFormatterCreate(kCFAllocatorSystemDefault, locale?._bridgeToObjectiveC()._cfObject, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle)
300300
CFDateFormatterSetProperty(dateFormatter, kCFDateFormatterCalendarKey, self._cfObject)
301-
return (CFDateFormatterCopyProperty(dateFormatter, key) as! CFString)._swiftObject
301+
return (CFDateFormatterCopyProperty(dateFormatter, key) as! NSString)._swiftObject
302302
}
303303

304304
open var eraSymbols: [String] {

TestFoundation/TestCalendar.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class TestCalendar: XCTestCase {
2828
("test_addingDates", test_addingDates),
2929
("test_datesNotOnWeekend", test_datesNotOnWeekend),
3030
("test_datesOnWeekend", test_datesOnWeekend),
31-
("test_customMirror", test_customMirror)
32-
// Disabled because this fails on linux https://bugs.swift.org/browse/SR-320
33-
// ("test_currentCalendarRRstability", test_currentCalendarRRstability),
31+
("test_customMirror", test_customMirror),
32+
("test_ampmSymbols", test_ampmSymbols),
33+
("test_currentCalendarRRstability", test_currentCalendarRRstability),
3434
]
3535
}
3636

@@ -125,7 +125,13 @@ class TestCalendar: XCTestCase {
125125
XCTAssertEqual(components.isLeapMonth, true)
126126
}
127127

128-
func test_currentRRstability() {
128+
func test_ampmSymbols() {
129+
let calendar = Calendar(identifier: .gregorian)
130+
XCTAssertEqual(calendar.amSymbol, "AM")
131+
XCTAssertEqual(calendar.pmSymbol, "PM")
132+
}
133+
134+
func test_currentCalendarRRstability() {
129135
var AMSymbols = [String]()
130136
for _ in 1...10 {
131137
let cal = Calendar.current
@@ -191,7 +197,7 @@ class TestCalendar: XCTestCase {
191197
XCTAssertEqual(calendar.identifier, calendarMirror.descendant("identifier") as? Calendar.Identifier)
192198
XCTAssertEqual(calendar.locale, calendarMirror.descendant("locale") as? Locale)
193199
XCTAssertEqual(calendar.timeZone, calendarMirror.descendant("timeZone") as? TimeZone)
194-
XCTAssertEqual(calendar.firstWeekday, calendarMirror.descendant("firstWeekDay") as? Int)
200+
XCTAssertEqual(calendar.firstWeekday, calendarMirror.descendant("firstWeekday") as? Int)
195201
XCTAssertEqual(calendar.minimumDaysInFirstWeek, calendarMirror.descendant("minimumDaysInFirstWeek") as? Int)
196202
}
197203
}

0 commit comments

Comments
 (0)