diff --git a/Modules/Sources/Profile/Logic/Adapters/DateAdapter.swift b/Modules/Sources/Profile/Logic/Adapters/DateAdapter.swift new file mode 100644 index 0000000..441030a --- /dev/null +++ b/Modules/Sources/Profile/Logic/Adapters/DateAdapter.swift @@ -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 + }() +} diff --git a/Modules/Sources/Profile/Logic/Adapters/StringAdapter.swift b/Modules/Sources/Profile/Logic/Adapters/StringAdapter.swift new file mode 100644 index 0000000..4cee887 --- /dev/null +++ b/Modules/Sources/Profile/Logic/Adapters/StringAdapter.swift @@ -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 + } +} diff --git a/Modules/Sources/Profile/Logic/Extensions/String+Constants.swift b/Modules/Sources/Profile/Logic/Extensions/String+Constants.swift new file mode 100644 index 0000000..ba0dca4 --- /dev/null +++ b/Modules/Sources/Profile/Logic/Extensions/String+Constants.swift @@ -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 = "-" + } +}