Repository: Alamofire/Alamofire
File: Source/ParameterEncoder.swift (Swift)

Code before:
            case .numeric: return value ? "1" : "0"
            case .literal: return value ? "true" : "false"
            }
        }
    }

    /// Configures how `Date` parameters are encoded.
    public enum DateEncoding {
        /// Encodes the date from `Date` structure.
        case deferredToDate
        /// Encodes the date as a UNIX timestamp.
        case secondsSince1970
        /// Encodes the date as UNIX millisecond timestamp.
        case millisecondsSince1970
        /// Encodes the date as an ISO-8601-formatted string (in RFC 3339 format).
        case iso8601
        /// Encodes the date as a string formatted by the given formatter.
        case formatted(DateFormatter)
        /// Encodes the date as a custom string formatted by the given closure.
        case custom((Date) -> String)

        /// Encodes the date according to the strategy.
        ///
        /// - Parameter string: The `Date` to encode.
        /// - Returns:          The encoded `String` or `nil` if the date should be encoded as `Encodable` structure.
        func encode(_ value: Date) -> String? {
            switch self {
            case .deferredToDate:
                return nil
            case .secondsSince1970:
                return String(value.timeIntervalSince1970)
            case .millisecondsSince1970:
                return String(value.timeIntervalSince1970 * 1000.0)
            case .iso8601:
                return ISO8601DateFormatter.string(from: value,
                                                   timeZone: TimeZone(secondsFromGMT: 0)!,
                                                   formatOptions: .withInternetDateTime)
            case let .formatted(formatter):
                return formatter.string(from: value)
            case let .custom(closure):
                return closure(value)
            }
        }
    }

    /// Configures how `Array` parameters are encoded.
    public enum ArrayEncoding {
        /// An empty set of square brackets ("[]") are sppended to the key for every value.
        case brackets
        /// No brackets are appended to the key and the key is encoded as is.
        case noBrackets

Review comment (suggestion):
`JSONEncoder` allows its `custom` case to produce throwing closures. Alamofire should likely do that same. This method should likely be `throws` so that custom closures can produce errors.

Code after:
            case .numeric: return value ? "1" : "0"
            case .literal: return value ? "true" : "false"
            }
        }
    }

    /// Configures how `Date` parameters are encoded.
    public enum DateEncoding {
        /// Defers encoding to the `Date` type.
        case deferredToDate
        /// Encodes dates as seconds since midnight UTC on January 1, 1970.
        case secondsSince1970
        /// Encodes dates as milliseconds since midnight UTC on January 1, 1970.
        case millisecondsSince1970
        /// Encodes dates according to the ISO 8601 and RFC3339 standards.
        case iso8601
        /// Encodes dates using the given `DateFormatter`.
        case formatted(DateFormatter)
        /// Encodes dates using the given closure.
        case custom((Date) throws -> String)

        private static let iso8601Formatter: ISO8601DateFormatter = {
            let formatter = ISO8601DateFormatter()
            formatter.formatOptions = .withInternetDateTime
            return formatter
        }()

        /// Encodes the date according to the strategy.
        ///
        /// - Parameter string: The `Date` to encode.
        /// - Returns:          The encoded `String` or `nil` if the date should be encoded as `Encodable` structure.
        func encode(_ value: Date) throws -> String? {
            switch self {
            case .deferredToDate:
                return nil
            case .secondsSince1970:
                return String(value.timeIntervalSince1970)
            case .millisecondsSince1970:
                return String(value.timeIntervalSince1970 * 1000.0)
            case .iso8601:
                return DateEncoding.iso8601Formatter.string(from: value)
            case let .formatted(formatter):
                return formatter.string(from: value)
            case let .custom(closure):
                return try closure(value)
            }
        }
    }

    /// Configures how `Array` parameters are encoded.
    public enum ArrayEncoding {