Skip to content

Cherry-pick important fixes for 3.0.1 (#668) #670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Foundation/DateComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public struct DateComponents : ReferenceConvertible, Hashable, Equatable, _Mutab

/// Set to true if these components represent a leap month.
public var isLeapMonth: Bool? {
get { return _handle.map { $0.isLeapMonth } }
get { return _handle.map { $0.leapMonthSet ? $0.isLeapMonth : nil } }
set {
_applyMutation {
// Technically, the underlying class does not support setting isLeapMonth to nil, but it could - so we leave the API consistent.
Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ open class NSCalendar : NSObject, NSCopying, NSSecureCoding {
_convert(comps.weekday, type: "E", vector: &vector, compDesc: &compDesc)
_convert(comps.weekdayOrdinal, type: "F", vector: &vector, compDesc: &compDesc)
_convert(comps.month, type: "M", vector: &vector, compDesc: &compDesc)
_convert(comps.isLeapMonth, type: "L", vector: &vector, compDesc: &compDesc)
_convert(comps.isLeapMonth, type: "l", vector: &vector, compDesc: &compDesc)
_convert(comps.day, type: "d", vector: &vector, compDesc: &compDesc)
_convert(comps.hour, type: "H", vector: &vector, compDesc: &compDesc)
_convert(comps.minute, type: "m", vector: &vector, compDesc: &compDesc)
Expand Down Expand Up @@ -581,7 +581,7 @@ open class NSCalendar : NSObject, NSCopying, NSSecureCoding {

open func date(byAdding comps: DateComponents, to date: Date, options opts: Options = []) -> Date? {
var (vector, compDesc) = _convert(comps)
var at: CFAbsoluteTime = 0.0
var at: CFAbsoluteTime = date.timeIntervalSinceReferenceDate

let res: Bool = withUnsafeMutablePointer(to: &at) { t in
return vector.withUnsafeMutableBufferPointer { (vectorBuffer: inout UnsafeMutableBufferPointer<Int32>) in
Expand Down
13 changes: 13 additions & 0 deletions TestFoundation/TestNSCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class TestNSCalendar: XCTestCase {
("test_gettingDatesOnHebrewCalendar", test_gettingDatesOnHebrewCalendar ),
("test_gettingDatesOnChineseCalendar", test_gettingDatesOnChineseCalendar),
("test_copy",test_copy),
("test_addingDates", test_addingDates)
// Disabled because this fails on linux https://bugs.swift.org/browse/SR-320
// ("test_currentCalendarRRstability", test_currentCalendarRRstability),
]
Expand Down Expand Up @@ -89,4 +90,16 @@ class TestNSCalendar: XCTestCase {
XCTAssertEqual(copy.firstWeekday, 2)
XCTAssertEqual(copy.minimumDaysInFirstWeek, 2)
}

func test_addingDates() {
let calendar = Calendar(identifier: .gregorian)
let thisDay = calendar.date(from: DateComponents(year: 2016, month: 10, day: 4))!
let diffComponents = DateComponents(day: 1)
let dayAfter = calendar.date(byAdding: diffComponents, to: thisDay)

let dayAfterComponents = calendar.dateComponents([.year, .month, .day], from: dayAfter!)
XCTAssertEqual(dayAfterComponents.year, 2016)
XCTAssertEqual(dayAfterComponents.month, 10)
XCTAssertEqual(dayAfterComponents.day, 5)
}
}