50 lines
950 B
Swift
50 lines
950 B
Swift
|
//
|
||
|
// DateAdapter.swift
|
||
|
// Browse
|
||
|
//
|
||
|
// Created by Javier Cicchelli on 15/12/2022.
|
||
|
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
|
||
|
struct DateAdapter {
|
||
|
|
||
|
// MARK: Properties
|
||
|
|
||
|
private let dateFormatter: DateFormatter = .dateTimeFormatter
|
||
|
|
||
|
// MARK: Functions
|
||
|
|
||
|
func callAsFunction(value: Date?) -> String {
|
||
|
if let value {
|
||
|
return dateFormatter.string(from: value)
|
||
|
} else {
|
||
|
return .Constants.noValue
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// MARK: - DateFormatter+Formats
|
||
|
|
||
|
private extension DateFormatter {
|
||
|
static let dateTimeFormatter = {
|
||
|
let formatter = DateFormatter()
|
||
|
|
||
|
formatter.dateStyle = .long
|
||
|
formatter.timeStyle = .short
|
||
|
formatter.locale = .current
|
||
|
|
||
|
return formatter
|
||
|
}()
|
||
|
}
|
||
|
|
||
|
// MARK: - String+Constants
|
||
|
|
||
|
private extension String {
|
||
|
enum Constants {
|
||
|
static let noValue = "-"
|
||
|
}
|
||
|
}
|