Skip to content

Clarify where NSCalendar timezone is set and return values #33

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
merged 1 commit into from
Dec 5, 2015
Merged
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
14 changes: 3 additions & 11 deletions Foundation/NSCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,7 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
public func dateFromComponents(comps: NSDateComponents) -> NSDate? {
var (vector, compDesc) = _convert(comps)

let oldTz = timeZone
let tempTz = comps.timeZone
if let tz = tempTz {
timeZone = tz
}
self.timeZone = comps.timeZone ?? timeZone

var at: CFAbsoluteTime = 0.0
let res: Bool = withUnsafeMutablePointer(&at) { t in
Expand All @@ -378,15 +374,11 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
}
}

if tempTz != nil {
self.timeZone = oldTz
}

if res {
return NSDate(timeIntervalSinceReferenceDate: at)
} else {
return nil
}

return nil
}

private func _setup(unitFlags: NSCalendarUnit, field: NSCalendarUnit, type: String, inout compDesc: [Int8]) {
Expand Down