Created
October 21, 2015 17:13
-
-
Save calebhicks/4c173907948c8957c8bf to your computer and use it in GitHub Desktop.
Swift Date Helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSDate | |
{ | |
func isGreaterThanDate(dateToCompare : NSDate) -> Bool | |
{ | |
//Declare Variables | |
var isGreater = false | |
//Compare Values | |
if self.compare(dateToCompare) == NSComparisonResult.OrderedDescending | |
{ | |
isGreater = true | |
} | |
//Return Result | |
return isGreater | |
} | |
func isLessThanDate(dateToCompare : NSDate) -> Bool | |
{ | |
//Declare Variables | |
var isLess = false | |
//Compare Values | |
if self.compare(dateToCompare) == NSComparisonResult.OrderedAscending | |
{ | |
isLess = true | |
} | |
//Return Result | |
return isLess | |
} | |
func isEqualToDate(dateToCompare : NSDate) -> Bool | |
{ | |
//Declare Variables | |
var isEqualTo = false | |
//Compare Values | |
if self.compare(dateToCompare) == NSComparisonResult.OrderedSame | |
{ | |
isEqualTo = true | |
} | |
//Return Result | |
return isEqualTo | |
} | |
func addDays(daysToAdd : Int) -> NSDate | |
{ | |
var secondsInDays : NSTimeInterval = Double(daysToAdd) * 60 * 60 * 24 | |
var dateWithDaysAdded : NSDate = self.dateByAddingTimeInterval(secondsInDays) | |
//Return Result | |
return dateWithDaysAdded | |
} | |
func addHours(hoursToAdd : Int) -> NSDate | |
{ | |
var secondsInHours : NSTimeInterval = Double(hoursToAdd) * 60 * 60 | |
var dateWithHoursAdded : NSDate = self.dateByAddingTimeInterval(secondsInHours) | |
//Return Result | |
return dateWithHoursAdded | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment