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() {
|
static private func initialize() {
|
||||||
dispatch_once(&once) {
|
dispatch_once(&once) {
|
||||||
let dateTimeFormatter = NSDateFormatter()
|
let formatters = [
|
||||||
dateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
|
"yyyy-MM-dd",
|
||||||
let dateFormatter = NSDateFormatter()
|
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
||||||
dateFormatter.dateFormat = "yyyy-MM-dd"
|
"yyyy-MM-dd'T'HH:mm:ss'Z'"
|
||||||
|
].map { (format: String) -> NSDateFormatter in
|
||||||
|
let formatter = NSDateFormatter()
|
||||||
|
formatter.dateFormat = format
|
||||||
|
return formatter
|
||||||
|
}
|
||||||
// Decoder for NSDate
|
// Decoder for NSDate
|
||||||
Decoders.addDecoder(clazz: NSDate.self) { (source: AnyObject) -> NSDate in
|
Decoders.addDecoder(clazz: NSDate.self) { (source: AnyObject) -> NSDate in
|
||||||
let sourceString = source as! String
|
let sourceString = source as! String
|
||||||
if count(sourceString) == 10 {
|
for formatter in formatters {
|
||||||
return dateFormatter.dateFromString(sourceString)!
|
if let date = formatter.dateFromString(sourceString) {
|
||||||
|
return date
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return dateTimeFormatter.dateFromString(sourceString)!
|
fatalError("formatter failed to parse \(sourceString)")
|
||||||
} {{#models}}{{#model}}
|
} {{#models}}{{#model}}
|
||||||
|
|
||||||
// Decoder for {{{classname}}}
|
// Decoder for {{{classname}}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user