Skip to content
This repository was archived by the owner on Mar 29, 2018. It is now read-only.

Commit 54d89b1

Browse files
committed
Merge pull request #107 from PGLongo/master
Fix hour and day order in iOS7 version of NSDate add
2 parents 662db55 + 68d9f46 commit 54d89b1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ExSwift/NSDate.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,34 @@ public extension NSDate {
2424
:param: years number of years to add
2525
:returns: the NSDate computed
2626
*/
27-
public func add(seconds: Int = 0, minutes: Int = 0, hours: Int = 0, days: Int = 0, weeks: Int = 0, months: Int = 0, years: Int = 0) -> NSDate {
27+
public func add(seconds: Int = 0, minutes: Int = 0, hours: Int = 0, days: Int = 0, weeks: Int = 0, months: Int = 0, years: Int = 0) -> NSDate {
2828
var calendar = NSCalendar.currentCalendar()
2929
let version = floor(NSFoundationVersionNumber)
3030
if ( version <= NSFoundationVersionNumber_iOS_7_1 || version <= NSFoundationVersionNumber10_9_2 ) {
3131
var component = NSDateComponents()
3232
component.setValue(seconds, forComponent: .CalendarUnitSecond)
33+
3334
var date : NSDate! = calendar.dateByAddingComponents(component, toDate: self, options: nil)!
3435
component = NSDateComponents()
3536
component.setValue(minutes, forComponent: .CalendarUnitMinute)
3637
date = calendar.dateByAddingComponents(component, toDate: date, options: nil)!
38+
3739
component = NSDateComponents()
38-
component.setValue(days, forComponent: .CalendarUnitDay)
40+
component.setValue(hours, forComponent: .CalendarUnitHour)
3941
date = calendar.dateByAddingComponents(component, toDate: date, options: nil)!
42+
4043
component = NSDateComponents()
41-
component.setValue(hours, forComponent: .CalendarUnitHour)
44+
component.setValue(days, forComponent: .CalendarUnitDay)
4245
date = calendar.dateByAddingComponents(component, toDate: date, options: nil)!
46+
47+
component = NSDateComponents()
4348
component.setValue(weeks, forComponent: .CalendarUnitWeekOfMonth)
4449
date = calendar.dateByAddingComponents(component, toDate: date, options: nil)!
50+
4551
component = NSDateComponents()
4652
component.setValue(months, forComponent: .CalendarUnitMonth)
4753
date = calendar.dateByAddingComponents(component, toDate: date, options: nil)!
54+
4855
component = NSDateComponents()
4956
component.setValue(years, forComponent: .CalendarUnitYear)
5057
date = calendar.dateByAddingComponents(component, toDate: date, options: nil)!

0 commit comments

Comments
 (0)