melvitax / DateHelper

A Swift Date extension helper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Day Suffix

Chazzman opened this issue · comments

Might be nice to add a day suffix to the library. Something like:

`extension Date {

static func getSuffix(forDate date: Date) -> String {
    if let day = date.component(.day) {
        let st: Set = [1, 21, 31]
        let nd: Set = [2, 22]
        let rd: Set = [3, 23]
        if st.contains(day) {
            return "st"
        }
        else if nd.contains(day) {
            return "nd"
        }
        else if rd.contains(day) {
            return "rd"
        }
        else {
            return "th"
        }
    } else {
        return ""
    }
}

}`

Thanks!

I just added it as a new style format:
now.toString(style: .ordinalDay)
should yield 27th i.e.

Awesome

Thanks

Any idea as to why the pod doesn't seem to work? Update pull 4.1.2 but the changes aren't there. Tried deleting and reinstalling. No errors but not new code either :(

Cocoapods fixed now

Ah yes, sorry I fixed the pod lint issue but forgot to push to cocoa pods trunk. It's updated now.