Skip to content

Commit

Permalink
Added today & tomorrow class function and updated documentation and s…
Browse files Browse the repository at this point in the history
…ample project.

Fix melvitax#22
  • Loading branch information
melvitax committed Dec 4, 2015
1 parent 88689f6 commit 9433bf6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
22 changes: 21 additions & 1 deletion AFDateHelper/AFDateExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public extension NSDate {
/**
Creates a new date from the last day of the month
- Returns NSDate
- Returns A new date object.
*/
func dateAtTheEndOfMonth() -> NSDate {

Expand All @@ -511,6 +511,26 @@ public extension NSDate {

}

/**
Creates a new date based on tomorrow.
- Returns A new date object.
*/
class func tomorrow() -> NSDate
{
return NSDate().dateByAddingDays(1).dateAtStartOfDay()
}

/**
Creates a new date based on yesterdat.
- Returns A new date object.
*/
class func yesterday() -> NSDate
{
return NSDate().dateBySubtractingDays(1).dateAtStartOfDay()
}


// MARK: Retrieving Intervals

Expand Down
17 changes: 15 additions & 2 deletions Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ class ViewController: UITableViewController {

items.append(sectionItems)


// MARK: **** CREATING DATES ****
sectionItems = [TableItem]()
sections.append("Creating Dates")
sectionItems.append(TableItem(title: "Tomorrow", description: "\(NSDate.tomorrow())"))
sectionItems.append(TableItem(title: "Yesterday", description: "\(NSDate.yesterday())"))
items.append(sectionItems)

// MARK: **** COMPARING DATES ****
sections.append("Comparing Dates")
Expand Down Expand Up @@ -220,8 +225,16 @@ class ViewController: UITableViewController {
sections.append("Time Intervals")
sectionItems = [TableItem]()

// MARK: secondsAfterDate
var num = date.secondsAfterDate(now)
sectionItems.append(TableItem(title: "Seconds After", description: "Interval from \(date.toString()): \(num)"))

// MARK: secondsBeforeDate
num = date.secondsBeforeDate(now)
sectionItems.append(TableItem(title: "Seconds Before", description: "Interval from \(date.toString()): \(num)"))

// MARK: minutesAfterDate
var num = date.minutesAfterDate(now)
num = date.minutesAfterDate(now)
sectionItems.append(TableItem(title: "Minutes After", description: "Interval from \(date.toString()): \(num)"))

// MARK: minutesBeforeDate
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ An NSDate Extension for Swift 2.0

To run the example project, clone or download the repo, and run.

### Date from String
### Creating Date from String
```Swift
// Date from String with custom format
NSDate(fromString: "16 July 1972 6:12:00 ", format: .Custom("dd MMM yyyy HH:mm:ss")) -> NSDate
Expand All @@ -37,6 +37,12 @@ NSDate(fromString: "Fri, 09 Sep 2011 15:26:08 +0200", format: .RSS) -> NSDate
NSDate(fromString: "09 Sep 2011 15:26:08 +0200", format: .AltRSS) -> NSDate -> NSDate
```

### Creating Date
```Swift
NSDate.tomorrow() -> NSDate
NSDate.yesterday() -> NSDate
```

### Comparing Dates
```Swift
date.isEqualToDate(date) -> Bool
Expand Down Expand Up @@ -67,6 +73,8 @@ date.dateAtStartOfDay() -> NSDate
date.dateAtEndOfDay() -> NSDate
date.dateAtStartOfWeek() -> NSDate
date.dateAtEndOfWeek() -> NSDate
date.dateAtTheStartOfMonth() -> NSDate
date.dateAtTheEndOfMonth() -> NSDate
```

### Time Interval Between Dates
Expand Down

0 comments on commit 9433bf6

Please sign in to comment.