Skip to content

adding support for java dates #2077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions modules/swagger-codegen/src/main/resources/swift/Models.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,19 @@ class Decoders {
}
// Decoder for NSDate
Decoders.addDecoder(clazz: NSDate.self) { (source: AnyObject) -> NSDate in
let sourceString = source as! String
for formatter in formatters {
if let date = formatter.dateFromString(sourceString) {
return date
if let sourceString = source as? String {
for formatter in formatters {
if let date = formatter.dateFromString(sourceString) {
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}}

// Decoder for [{{{classname}}}]
Expand Down