Skip to content

Commit 2569d56

Browse files
Jason JiJason Ji
authored andcommitted
More fixes:
- DateComponent should only return isLeapMonth if the underlying leapMonthSet variable is true. Previously, DateComponent was setting isLeapMonth to false in situations where there is no concept of isLeapMonth. - _convert was using 'L' for isLeapMonth, when the corresponding UCalendarDateFields enum value for isLeapMonth is 'l'. This was causing _CFCalendarAddComponentsV to return error status.
1 parent cd026aa commit 2569d56

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Foundation/DateComponents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public struct DateComponents : ReferenceConvertible, Hashable, Equatable, _Mutab
189189

190190
/// Set to true if these components represent a leap month.
191191
public var isLeapMonth: Bool? {
192-
get { return _handle.map { $0.isLeapMonth } }
192+
get { return _handle.map { $0.leapMonthSet ? $0.isLeapMonth : nil } }
193193
set {
194194
_applyMutation {
195195
// Technically, the underlying class does not support setting isLeapMonth to nil, but it could - so we leave the API consistent.

Foundation/NSCalendar.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ open class NSCalendar : NSObject, NSCopying, NSSecureCoding {
461461
_convert(comps.weekday, type: "E", vector: &vector, compDesc: &compDesc)
462462
_convert(comps.weekdayOrdinal, type: "F", vector: &vector, compDesc: &compDesc)
463463
_convert(comps.month, type: "M", vector: &vector, compDesc: &compDesc)
464-
_convert(comps.isLeapMonth, type: "L", vector: &vector, compDesc: &compDesc)
464+
_convert(comps.isLeapMonth, type: "l", vector: &vector, compDesc: &compDesc)
465465
_convert(comps.day, type: "d", vector: &vector, compDesc: &compDesc)
466466
_convert(comps.hour, type: "H", vector: &vector, compDesc: &compDesc)
467467
_convert(comps.minute, type: "m", vector: &vector, compDesc: &compDesc)

TestFoundation/TestNSCalendar.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@ class TestNSCalendar: XCTestCase {
9292
}
9393

9494
func test_addingDates() {
95-
var calendar = Calendar.current
96-
let today = calendar.current.date(from: DateComponents(year: 2016, month: 10, day: 4))
95+
let calendar = Calendar.current
96+
let today = Date()
9797
let diffComponents = DateComponents(day: 1)
9898
let tomorrow = calendar.date(byAdding: diffComponents, to: today)
9999

100-
XCTAssertEqual(tomorrow.year, 2016)
101-
XCTAssertEqual(tomorrow.month, 10)
102-
XCTAssertEqual(tomorrow.day, 5)
100+
let tomorrowComponents = calendar.dateComponents([.year, .month, .day], from: tomorrow!)
101+
XCTAssertEqual(tomorrowComponents.year, 2016)
102+
XCTAssertEqual(tomorrowComponents.month, 10)
103+
XCTAssertEqual(tomorrowComponents.day, 5)
103104
}
104105
}
105106

0 commit comments

Comments
 (0)