DataLireCoder swift package
This commit is contained in:
24
Sources/DataLiteCoder/Protocols/DateFormatterProtocol.swift
Normal file
24
Sources/DataLiteCoder/Protocols/DateFormatterProtocol.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
import Foundation
|
||||
|
||||
/// A common interface for formatting and parsing `Date` values.
|
||||
///
|
||||
/// The `DateFormatterProtocol` abstracts the interface of date formatters, allowing
|
||||
/// interchangeable use of `DateFormatter` and `ISO8601DateFormatter` when encoding or decoding
|
||||
/// date values.
|
||||
public protocol DateFormatterProtocol {
|
||||
/// Returns a string representation of the specified date.
|
||||
///
|
||||
/// - Parameter date: The `Date` to format.
|
||||
/// - Returns: A string that represents the formatted date.
|
||||
func string(from date: Date) -> String
|
||||
|
||||
/// Converts the specified string into a `Date` object.
|
||||
///
|
||||
/// - Parameter string: The date string to parse.
|
||||
/// - Returns: A `Date` object if the string could be parsed, or `nil` otherwise.
|
||||
func date(from string: String) -> Date?
|
||||
}
|
||||
|
||||
extension ISO8601DateFormatter: DateFormatterProtocol {}
|
||||
|
||||
extension DateFormatter: DateFormatterProtocol {}
|
||||
Reference in New Issue
Block a user