diff --git a/AFDateHelper/AFDateExtension.swift b/AFDateHelper/AFDateExtension.swift index 83efebd..dc56993 100644 --- a/AFDateHelper/AFDateExtension.swift +++ b/AFDateHelper/AFDateExtension.swift @@ -405,7 +405,7 @@ public extension NSDate { } /** - Returns a new NSDate object by a adding minutes. + Returns a new NSDate object by a substracting minutes. :param: days :Int Minutes to add. :returns: NSDate @@ -417,6 +417,32 @@ public extension NSDate { return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! } + /** + Returns a new NSDate object by a adding seconds. + + :param: Seconds Seconds to add. + :returns: NSDate + */ + func dateByAddingSeconds(seconds: Int) -> NSDate + { + let dateComp = NSDateComponents() + dateComp.second = seconds + return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + } + + /** + Returns a new NSDate object by a substracting seconds. + + :param: days :Int Seconds to substract. + :returns: NSDate + */ + func dateBySubtractingSeconds(seconds: Int) -> NSDate + { + let dateComp = NSDateComponents() + dateComp.second = (seconds * -1) + return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + } + /** Returns a new NSDate object from the start of the day. diff --git a/Demo/ViewController.swift b/Demo/ViewController.swift index 6cde69f..1fbe05b 100644 --- a/Demo/ViewController.swift +++ b/Demo/ViewController.swift @@ -181,6 +181,14 @@ class ViewController: UITableViewController { date = now.dateBySubtractingMinutes(4) sectionItems.append(TableItem(title: "Substracting Minutes", description: "- 4 Minutes: \(date.toString())")) + // MARK: dateByAddingSeconds + date = now.dateByAddingSeconds(90) + sectionItems.append(TableItem(title: "Adding Seconds", description: "+ 90 Seconds: \(date.toString())")) + + // MARK: dateBySubstractingSeconds + date = now.dateBySubtractingSeconds(90) + sectionItems.append(TableItem(title: "Substracting Seconds", description: "- 90 Minutes: \(date.toString())")) + // MARK: dateAtStartOfDay date = now.dateAtStartOfDay() sectionItems.append(TableItem(title: "Start of Day", description: "\(date.toString())"))