Merge pull request #296 from TouchInstinct/feature/date_formatting_fixes
fix: Try parse date in ISO8601 format appending `.withFractionalSeconds` if `.withInternetDateTime` fails
This commit is contained in:
commit
f01096dfb7
|
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
### 1.12.3
|
||||
|
||||
- **Fix**: Try parse date in ISO8601 format appending `.withFractionalSeconds` if `.withInternetDateTime` fails
|
||||
|
||||
### 1.12.2
|
||||
|
||||
- **Fix**: HeaderParameterEncoding encodes array correctly
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = "LeadKit"
|
||||
s.version = "1.12.2"
|
||||
s.version = "1.12.3"
|
||||
s.summary = "iOS framework with a bunch of tools for rapid development"
|
||||
s.homepage = "https://github.com/TouchInstinct/LeadKit"
|
||||
s.license = "Apache License, Version 2.0"
|
||||
|
|
|
|||
|
|
@ -44,15 +44,49 @@ public extension KeyedDecodingContainer {
|
|||
using: dateFormatter)
|
||||
}
|
||||
|
||||
func decodeDate(forKey key: Key,
|
||||
using dateFormatter: ISO8601DateFormatter) throws -> Date {
|
||||
func decodeDate(from string: String,
|
||||
forKey key: Key,
|
||||
userInfo: [CodingUserInfoKey: Any],
|
||||
options formatOptions: ISO8601DateFormatter.Options) throws -> Date {
|
||||
|
||||
try date(from: try decode(String.self, forKey: key),
|
||||
forKey: key,
|
||||
using: dateFormatter)
|
||||
let dateFormatter = try userInfo.iso8601DateFormatter(for: formatOptions)
|
||||
|
||||
do {
|
||||
return try date(from: string,
|
||||
forKey: key,
|
||||
using: dateFormatter)
|
||||
} catch DecodingError.dataCorrupted where formatOptions == .withInternetDateTime {
|
||||
let fractionSecondsOptions = formatOptions.union(.withFractionalSeconds)
|
||||
|
||||
do {
|
||||
let fractionalSecondsDateFormatter = try userInfo.iso8601DateFormatter(for: fractionSecondsOptions)
|
||||
|
||||
return try date(from: string,
|
||||
forKey: key,
|
||||
using: fractionalSecondsDateFormatter)
|
||||
} catch {
|
||||
let failureReason = "Unable to decode date from \(string). Tried ISO8601 options: \(dateFormatter.formatOptions), \(fractionSecondsOptions)"
|
||||
|
||||
throw DecodingError.dataCorruptedError(forKey: key,
|
||||
in: self,
|
||||
debugDescription: failureReason)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func decodeDate(forKey key: Key,
|
||||
userInfo: [CodingUserInfoKey: Any],
|
||||
options formatOptions: ISO8601DateFormatter.Options) throws -> Date {
|
||||
|
||||
try decodeDate(from: try decode(String.self, forKey: key),
|
||||
forKey: key,
|
||||
userInfo: userInfo,
|
||||
options: formatOptions)
|
||||
}
|
||||
|
||||
func decodeDate(forKey key: Key,
|
||||
userInfo: [CodingUserInfoKey: Any],
|
||||
options formatOptions: ISO8601DateFormatter.Options,
|
||||
using dateFormatter: ISO8601DateFormatter,
|
||||
required: Bool) throws -> Date? {
|
||||
|
||||
|
|
@ -60,9 +94,10 @@ public extension KeyedDecodingContainer {
|
|||
return nil
|
||||
}
|
||||
|
||||
return try date(from: stringDate,
|
||||
forKey: key,
|
||||
using: dateFormatter)
|
||||
return try decodeDate(from: stringDate,
|
||||
forKey: key,
|
||||
userInfo: userInfo,
|
||||
options: formatOptions)
|
||||
}
|
||||
|
||||
private func date(from string: String,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIFoundationUtils'
|
||||
s.version = '1.12.2'
|
||||
s.version = '1.12.3'
|
||||
s.summary = 'Set of helpers for Foundation framework classes.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIKeychainUtils'
|
||||
s.version = '1.12.2'
|
||||
s.version = '1.12.3'
|
||||
s.summary = 'Set of helpers for Keychain classes.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -22,13 +22,18 @@
|
|||
|
||||
import Moya
|
||||
import TISwiftUtils
|
||||
import TIFoundationUtils
|
||||
|
||||
public extension Cancellable {
|
||||
static func nonCancellable() -> Cancellable {
|
||||
public struct Cancellables {
|
||||
public static func nonCancellable() -> Cancellable {
|
||||
NonCancellable()
|
||||
}
|
||||
|
||||
static func scoped(scopeCancellableClosure: ScopeCancellable.ScopeCancellableClosure) -> Cancellable {
|
||||
public static func scoped(scopeCancellableClosure: ScopeCancellable.ScopeCancellableClosure) -> Cancellable {
|
||||
ScopeCancellable(scopeCancellableClosure: scopeCancellableClosure)
|
||||
}
|
||||
|
||||
public static func nonCancellableTask() -> CancellableTask {
|
||||
NonCancellable()
|
||||
}
|
||||
}
|
||||
|
|
@ -25,6 +25,7 @@ import Alamofire
|
|||
import Moya
|
||||
import TISwiftUtils
|
||||
import Foundation
|
||||
import TIFoundationUtils
|
||||
|
||||
open class DefaultJsonNetworkService {
|
||||
public var session: Session
|
||||
|
|
@ -43,13 +44,12 @@ open class DefaultJsonNetworkService {
|
|||
public var plugins: [PluginType] = []
|
||||
|
||||
public init(session: Session,
|
||||
jsonDecoder: JSONDecoder,
|
||||
jsonEncoder: JSONEncoder,
|
||||
jsonCodingConfigurator: JsonCodingConfigurator,
|
||||
defaultServer: Server) {
|
||||
|
||||
self.session = session
|
||||
self.jsonDecoder = jsonDecoder
|
||||
self.jsonEncoder = jsonEncoder
|
||||
self.jsonDecoder = jsonCodingConfigurator.jsonDecoder
|
||||
self.jsonEncoder = jsonCodingConfigurator.jsonEncoder
|
||||
self.defaultServer = defaultServer
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIMoyaNetworking'
|
||||
s.version = '1.12.2'
|
||||
s.version = '1.12.3'
|
||||
s.summary = 'Moya + Swagger network service.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TINetworking'
|
||||
s.version = '1.12.2'
|
||||
s.version = '1.12.3'
|
||||
s.summary = 'Swagger-frendly networking layer helpers.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TISwiftUtils'
|
||||
s.version = '1.12.2'
|
||||
s.version = '1.12.3'
|
||||
s.summary = 'Bunch of useful helpers for Swift development.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TITableKitUtils'
|
||||
s.version = '1.12.2'
|
||||
s.version = '1.12.3'
|
||||
s.summary = 'Set of helpers for TableKit classes.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TITransitions'
|
||||
s.version = '1.12.2'
|
||||
s.version = '1.12.3'
|
||||
s.summary = 'Set of custom transitions to present controller. '
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIUIElements'
|
||||
s.version = '1.12.2'
|
||||
s.version = '1.12.3'
|
||||
s.summary = 'Bunch of useful protocols and views.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'TIUIKitCore'
|
||||
s.version = '1.12.2'
|
||||
s.version = '1.12.3'
|
||||
s.summary = 'Core UI elements: protocols, views and helpers.'
|
||||
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
|
|
|
|||
Loading…
Reference in New Issue