Last active
November 13, 2018 22:30
-
-
Save vikingosegundo/31ddb14920415ef444a9ab550411d4ff to your computer and use it in GitHub Desktop.
This file contains 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
import Foundation | |
extension Date { | |
func add(years: Int = 0, months: Int = 0, days: Int = 0, hours: Int = 0, minutes: Int = 0, seconds: Int = 0) -> Date? { | |
let comp = DateComponents(year: years, month: months, day: days, hour: hours, minute: minutes, second: seconds) | |
return Calendar.current.date(byAdding: comp, to: self) | |
} | |
func subtract(years: Int = 0, months: Int = 0, days: Int = 0, hours: Int = 0, minutes: Int = 0, seconds: Int = 0) -> Date? { | |
return add(years: -years, months: -months, days: -days, hours: -hours, minutes: -minutes, seconds: -seconds) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment