Skip to content

Commit d7838cc

Browse files
committed
Clarify where timezone is set and return values
Fixed whitespacing issues Merge timeZone assignment into more clear single operation
1 parent df08be3 commit d7838cc

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

Foundation/NSCalendar.swift

+3-11
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,7 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
365365
public func dateFromComponents(comps: NSDateComponents) -> NSDate? {
366366
var (vector, compDesc) = _convert(comps)
367367

368-
let oldTz = timeZone
369-
let tempTz = comps.timeZone
370-
if let tz = tempTz {
371-
timeZone = tz
372-
}
368+
self.timeZone = comps.timeZone ?? timeZone
373369

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

381-
if tempTz != nil {
382-
self.timeZone = oldTz
383-
}
384-
385377
if res {
386378
return NSDate(timeIntervalSinceReferenceDate: at)
379+
} else {
380+
return nil
387381
}
388-
389-
return nil
390382
}
391383

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

0 commit comments

Comments
 (0)