Fixes #510. If a keyboard.json has no timezone in the last modified date string, then it will still install

This commit is contained in:
Marc Durdin 2018-06-13 13:12:43 +07:00
parent bb47b29e16
commit 46efbbc5c8
2 changed files with 16 additions and 5 deletions

View file

@ -9,6 +9,12 @@
import Foundation
extension JSONDecoder.DateDecodingStrategy {
static var iso8601WithoutTimezone: JSONDecoder.DateDecodingStrategy {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
return .formatted(formatter)
}
static var ios8601WithFallback: JSONDecoder.DateDecodingStrategy {
if #available(iOS 10.0, *) {
return .iso8601

View file

@ -595,12 +595,17 @@ public class Manager: NSObject, HTTPDownloadDelegate, UIGestureRecognizerDelegat
if let keyboard = try? decoder.decode(KeyboardAPICall.self, from: data) {
downloadKeyboard(keyboard)
} else {
decoder.dateDecodingStrategy = .ios8601WithMilliseconds
do {
let keyboard = try decoder.decode(KeyboardAPICall.self, from: data)
decoder.dateDecodingStrategy = .iso8601WithoutTimezone
if let keyboard = try? decoder.decode(KeyboardAPICall.self, from: data) {
downloadKeyboard(keyboard)
} catch {
downloadFailed(forKeyboards: [], error: error)
} else {
decoder.dateDecodingStrategy = .ios8601WithMilliseconds
do {
let keyboard = try decoder.decode(KeyboardAPICall.self, from: data)
downloadKeyboard(keyboard)
} catch {
downloadFailed(forKeyboards: [], error: error)
}
}
}
}