forked from loafle/openapi-generator-original
Merge pull request #2077 from spotby/swift-java-date
adding support for java dates
This commit is contained in:
commit
f50174e950
@ -109,13 +109,19 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
// 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
|
if let sourceString = source as? String {
|
||||||
for formatter in formatters {
|
for formatter in formatters {
|
||||||
if let date = formatter.dateFromString(sourceString) {
|
if let date = formatter.dateFromString(sourceString) {
|
||||||
return date
|
return date
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fatalError("formatter failed to parse \(sourceString)")
|
|
||||||
|
}
|
||||||
|
if let sourceInt = source as? Int {
|
||||||
|
// treat as a java date
|
||||||
|
return NSDate(timeIntervalSince1970: Double(sourceInt / 1000) )
|
||||||
|
}
|
||||||
|
fatalError("formatter failed to parse \(source)")
|
||||||
} {{#models}}{{#model}}
|
} {{#models}}{{#model}}
|
||||||
|
|
||||||
// Decoder for [{{{classname}}}]
|
// Decoder for [{{{classname}}}]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user