mperovic / ISO8601Formatter

NSFormatter subclass for ISO8601.
MIT License
23 stars 3 forks source link

Question #1

Open kas-kad opened 9 years ago

kas-kad commented 9 years ago

You may find my question kinda silly, but.. Why not just use standard NSDateFormatter? What is the purpose of the ISO8601Formatter?

        let df = NSDateFormatter()
        df.locale = NSLocale(localeIdentifier: "en_US_POSIX")
        df.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZ"
mperovic commented 9 years ago

Because I wanted to support multiple date/time formats (check enums: ISO8601DateStyle, ISO8601TimeStyle, ISO8601TimeZoneStyle, ISO8601FractionSeparator)

kas-kad commented 9 years ago

ok, why not this:

        let df = NSDateFormatter()
        df.locale = NSLocale(localeIdentifier: "en_US_POSIX")
        var dayDateFormat: String!
        switch dateStyle {
        case .CalendarLongStyle:
            dayDateFormat = "YYYY-MM-DD"
        case .CalendarShortStyle:
            dayDateFormat = "YYYYMMDD"
            ...
        }

        var timeFormat: String!
        switch timeStyle {
        case .LongStyle:
            timeFormat = "hh:mm:ss"
            ...
        }

        df.dateFormat = dayDateFormat +"T"+ timeFormat

I just don't understand why reinvent NSDateFormatter? Just give the case when NSDateFormatter lose the battle. Sorry if I'm busily.