Skip to content

Commit

Permalink
Merge pull request melvitax#40 from vittoriom/sameMonthAsDate
Browse files Browse the repository at this point in the history
Adds an implementation for isSameMonthAsDate
  • Loading branch information
melvitax committed May 26, 2016
2 parents 471ddeb + a99405c commit d84ea41
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
15 changes: 14 additions & 1 deletion AFDateHelper/AFDateExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,22 @@ public extension NSDate {
{
let comp1 = NSDate.components(fromDate: self)
let comp2 = NSDate.components(fromDate: date)
return (comp1.year == comp2.year)
return comp1.year == comp2.year
}

/**
Returns true if dates are in the same month
- Parameter date: The date to compare
*/
func isSameMonthAsDate(date: NSDate) -> Bool
{
let comp1 = NSDate.components(fromDate: self)
let comp2 = NSDate.components(fromDate: date)

return comp1.year == comp2.year && comp1.month == comp2.month
}

/**
Returns true if date is this year.
*/
Expand Down
8 changes: 6 additions & 2 deletions Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ class ViewController: UITableViewController {

// MARK: isSameWeekAsDate
equality = now.isSameWeekAsDate(date) ? "is same week as" : "is not same week as"
sectionItems.append(TableItem(title: "Same Week", description: "\(date.toString()) \(equality) \(date.toString())"))

sectionItems.append(TableItem(title: "Same Week", description: "\(now.toString()) \(equality) \(date.toString())"))

// MARK: isSameMonthAsDate
equality = now.isSameMonthAsDate(date) ? "is same month as" : "is not same month as"
sectionItems.append(TableItem(title: "Same Month", description: "\(now.toString()) \(equality) \(date.toString())"))

// MARK: isThisWeek
equality = date.isThisWeek() ? "is this week" : "is not this week"
sectionItems.append(TableItem(title: "This Week", description: "\(date.toString()) \(equality)"))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ date.isToday() -> Bool
date.isTomorrow()-> Bool
date.isYesterday() -> Bool
date.isSameWeekAsDate(date) -> Bool
date.isSameMonthAsDate(date) -> Bool
date.isThisWeek() -> Bool
date.isNextWeek() -> Bool
date.isLastWeek() -> Bool
Expand Down

0 comments on commit d84ea41

Please sign in to comment.