forked from loafle/openapi-generator-original
Add a dateTime formatter candidate
This commit is contained in:
parent
7be35bb02e
commit
d08acf7298
@ -97,17 +97,24 @@ class Decoders {
|
||||
|
||||
static private func initialize() {
|
||||
dispatch_once(&once) {
|
||||
let dateTimeFormatter = NSDateFormatter()
|
||||
dateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
|
||||
let dateFormatter = NSDateFormatter()
|
||||
dateFormatter.dateFormat = "yyyy-MM-dd"
|
||||
let formatters = [
|
||||
"yyyy-MM-dd",
|
||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
||||
"yyyy-MM-dd'T'HH:mm:ss'Z'"
|
||||
].map { (format: String) -> NSDateFormatter in
|
||||
let formatter = NSDateFormatter()
|
||||
formatter.dateFormat = format
|
||||
return formatter
|
||||
}
|
||||
// Decoder for NSDate
|
||||
Decoders.addDecoder(clazz: NSDate.self) { (source: AnyObject) -> NSDate in
|
||||
let sourceString = source as! String
|
||||
if count(sourceString) == 10 {
|
||||
return dateFormatter.dateFromString(sourceString)!
|
||||
for formatter in formatters {
|
||||
if let date = formatter.dateFromString(sourceString) {
|
||||
return date
|
||||
}
|
||||
}
|
||||
return dateTimeFormatter.dateFromString(sourceString)!
|
||||
fatalError("formatter failed to parse \(sourceString)")
|
||||
} {{#models}}{{#model}}
|
||||
|
||||
// Decoder for {{{classname}}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user