Implemented the StringAdapter and the DateAdapter adapters for the Profile module.
This commit is contained in:
parent
71871c6ae0
commit
d7ec5aad47
41
Modules/Sources/Profile/Logic/Adapters/DateAdapter.swift
Normal file
41
Modules/Sources/Profile/Logic/Adapters/DateAdapter.swift
Normal file
@ -0,0 +1,41 @@
|
||||
//
|
||||
// DateAdapter.swift
|
||||
// Profile
|
||||
//
|
||||
// Created by Javier Cicchelli on 12/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
|
||||
}()
|
||||
}
|
13
Modules/Sources/Profile/Logic/Adapters/StringAdapter.swift
Normal file
13
Modules/Sources/Profile/Logic/Adapters/StringAdapter.swift
Normal file
@ -0,0 +1,13 @@
|
||||
//
|
||||
// StringAdapter.swift
|
||||
// Profile
|
||||
//
|
||||
// Created by Javier Cicchelli on 12/12/2022.
|
||||
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||
//
|
||||
|
||||
struct StringAdapter {
|
||||
func callAsFunction(value: String?) -> String {
|
||||
value ?? .Constants.noValue
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
//
|
||||
// String+Constants.swift
|
||||
// Profile
|
||||
//
|
||||
// Created by Javier Cicchelli on 12/12/2022.
|
||||
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||
//
|
||||
|
||||
extension String {
|
||||
enum Constants {
|
||||
static let noValue = "-"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user