Repository: vapor/vapor
File: Sources/Vapor/URLEncodedForm/URLEncodedFormDecoder.swift (Swift)

Code before:
        
        func decodeNil(forKey key: Key) throws -> Bool {
            return self.data.children[key.stringValue] == nil
        }
        
        func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable {
            //If we are trying to decode a required array, we might not have decoded a child, but we should still try to decode an empty array
            let child = self.data.children[key.stringValue] ?? []
            if let convertible = T.self as? URLQueryFragmentConvertible.Type {
                guard let value = child.values.last else {
                    if self.configuration.boolFlags {
                        //If no values found see if we are decoding a boolean
                        if let _ = T.self as? Bool.Type {
                            return self.data.values.contains(.urlDecoded(key.stringValue)) as! T
                        }
                    }
                    throw DecodingError.valueNotFound(T.self, at: self.codingPath + [key])
                }
                if let result = convertible.init(urlQueryFragmentValue: value) {
                    return result as! T
                } else {
                    throw DecodingError.typeMismatch(T.self, at: self.codingPath + [key])
                }
            } else {
                let decoder = _Decoder(data: child, codingPath: self.codingPath + [key], configuration: configuration)
                if type == Date.self {
                    return Date(timeIntervalSince1970: try TimeInterval(from: decoder)) as! T
                } else {
                    return try T(from: decoder)
                }
            }
        }
        
        func nestedContainer<NestedKey>(
            keyedBy type: NestedKey.Type,
            forKey key: Key
        ) throws -> KeyedDecodingContainer<NestedKey>
            where NestedKey: CodingKey
        {
            guard let child = self.data.children[key.stringValue] else {
                throw DecodingError.valueNotFound([String: Any].self, at: self.codingPath + [key])
            }
            return KeyedDecodingContainer(KeyedContainer<NestedKey>(data: child, codingPath: self.codingPath + [key], configuration: configuration))
        }
        
        func nestedUnkeyedContainer(forKey key: Key) throws -> UnkeyedDecodingContainer {
            guard let child = self.data.children[key.stringValue] else {
                throw DecodingError.valueNotFound([Any].self, at: self.codingPath + [key])
            }
            return try UnkeyedContainer(
                data: child,

Review comment (suggestion):
This can be achieved by conforming `Date` to `URLQueryFragmentConvertible` without any changes to the encoder / decoder. 

Code after:
        
        func decodeNil(forKey key: Key) throws -> Bool {
            return self.data.children[key.stringValue] == nil
        }
        
        func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable {
            //If we are trying to decode a required array, we might not have decoded a child, but we should still try to decode an empty array
            let child = self.data.children[key.stringValue] ?? []
            if let convertible = T.self as? URLQueryFragmentConvertible.Type {
                guard let value = child.values.last else {
                    if self.configuration.boolFlags {
                        //If no values found see if we are decoding a boolean
                        if let _ = T.self as? Bool.Type {
                            return self.data.values.contains(.urlDecoded(key.stringValue)) as! T
                        }
                    }
                    throw DecodingError.valueNotFound(T.self, at: self.codingPath + [key])
                }
                if let result = convertible.init(urlQueryFragmentValue: value) {
                    return result as! T
                } else {
                    throw DecodingError.typeMismatch(T.self, at: self.codingPath + [key])
                }
            } else {
                let decoder = _Decoder(data: child, codingPath: self.codingPath + [key], configuration: configuration)
                return try T(from: decoder)
            }
        }
        
        func nestedContainer<NestedKey>(
            keyedBy type: NestedKey.Type,
            forKey key: Key
        ) throws -> KeyedDecodingContainer<NestedKey>
            where NestedKey: CodingKey
        {
            guard let child = self.data.children[key.stringValue] else {
                throw DecodingError.valueNotFound([String: Any].self, at: self.codingPath + [key])
            }
            return KeyedDecodingContainer(KeyedContainer<NestedKey>(data: child, codingPath: self.codingPath + [key], configuration: configuration))
        }
        
        func nestedUnkeyedContainer(forKey key: Key) throws -> UnkeyedDecodingContainer {
            guard let child = self.data.children[key.stringValue] else {
                throw DecodingError.valueNotFound([Any].self, at: self.codingPath + [key])
            }
            return try UnkeyedContainer(
                data: child,
                codingPath: self.codingPath + [key],
                configuration: configuration
            )
        }