Esqarrouth/EZSwiftExtensions

Error on DateExtensions.swift

noriega9807 opened this issue · 2 comments

Hi, I was using the Date extension like this:

let format = "yyyy-MM-dd HH:mm:ss"
let fecha1 = Date(fromString: "2017-10-03 14:30:01", format: format)

And it was running fine on the simulator, however when running on a actual device it always returned nil so I modified DateExtensions.swift like this to get this working on a device:

public init?(fromString string: String, format: String) {
        let formatter = DateFormatter()
        formatter.timeZone = TimeZone.current
        formatter.locale = Locale(identifier: "en_US")
        formatter.dateFormat = format
        if let date = formatter.date(from: string) {
            self = date
        } else {
            return nil
        }
    }

I might be able to work this in. My only concern is en_US. I think i am gonna make that a default param (although feels kinda partial to US folks).

Let me know if this works for you ? #466.