Skip to content
This repository has been archived by the owner on Mar 29, 2018. It is now read-only.

Add getter and comparison to NSDate #61

Merged
merged 5 commits into from
Jan 11, 2015
Merged

Add getter and comparison to NSDate #61

merged 5 commits into from
Jan 11, 2015

Conversation

PGLongo
Copy link
Contributor

@PGLongo PGLongo commented Jan 10, 2015

Hi,

I have added getters to NSDate. Now you can do:

let date = NSDate()
let year = date.year

instead of

let date = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components(.CalendarUnitYear, fromDate: date)
let year = components.year

I have also added Comparison operator: <, <=, >, >=, == and updated the docs and README.md

@pNre
Copy link
Owner

pNre commented Jan 11, 2015

Hi, before merging, there's a bug in the > operator implementation you should fix.

public func >(lhs: NSDate, rhs: NSDate) -> Bool {
    return !(lhs < rhs)
}

If lhs == rhs the function returns true.

@PGLongo
Copy link
Contributor Author

PGLongo commented Jan 11, 2015

Thanks!

Fixed replacing

public func >(lhs: NSDate, rhs: NSDate) -> Bool {
    return !(lhs < rhs)
}

with

public func >(lhs: NSDate, rhs: NSDate) -> Bool {
    return !(lhs <= rhs)
}

I have also updated the test

pNre added a commit that referenced this pull request Jan 11, 2015
Add getter and comparison to NSDate
@pNre pNre merged commit 129ece7 into pNre:master Jan 11, 2015
@michaeleisel
Copy link
Contributor

You should only implement == and > (or maybe <, I forget, but just one of the two). Swift infers the other variants, e.g. >=, for you.

@michaeleisel
Copy link
Contributor

@PGLongo @pNre

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants