123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import Foundation
- open class DateFormatterTransform: TransformType {
- public typealias Object = Date
- public typealias JSON = String
-
- public let dateFormatter: DateFormatter
-
- public init(dateFormatter: DateFormatter) {
- self.dateFormatter = dateFormatter
- }
-
- open func transformFromJSON(_ value: Any?) -> Date? {
- if let dateString = value as? String {
- return dateFormatter.date(from: dateString)
- }
- return nil
- }
-
- open func transformToJSON(_ value: Date?) -> String? {
- if let date = value {
- return dateFormatter.string(from: date)
- }
- return nil
- }
- }
|