@@ -6,12 +6,12 @@ public struct CurrencyExchangeRate: Codable, Equatable {
66 public let toCurrencyCode : String
77 public let toCurrencyName : String
88 public let exchangeRate : Decimal
9- public let lastRefreshed : Date
10- public let timeZone : TimeZone
9+ public let lastRefreshed : String
10+ public let timeZone : String
1111 public let bidPrice : Decimal
1212 public let askPrice : Decimal
1313
14- init ( fromCurrencyCode: String , fromCurrencyName: String , toCurrencyCode: String , toCurrencyName: String , exchangeRate: Decimal , lastRefreshed: Date , timeZone: TimeZone , bidPrice: Decimal , askPrice: Decimal ) {
14+ init ( fromCurrencyCode: String , fromCurrencyName: String , toCurrencyCode: String , toCurrencyName: String , exchangeRate: Decimal , lastRefreshed: String , timeZone: String , bidPrice: Decimal , askPrice: Decimal ) {
1515 self . fromCurrencyCode = fromCurrencyCode
1616 self . fromCurrencyName = fromCurrencyName
1717 self . toCurrencyCode = toCurrencyCode
@@ -44,23 +44,7 @@ public struct CurrencyExchangeRate: Codable, Equatable {
4444 exchangeRate = try container. decodeUSDecimal ( forKey: . exchangeRate)
4545 bidPrice = try container. decodeUSDecimal ( forKey: . bidPrice)
4646 askPrice = try container. decodeUSDecimal ( forKey: . askPrice)
47-
48-
49- // Handling TimeZone
50- let timeZoneString = try container. decode ( String . self, forKey: . timeZone)
51- guard let timeZone = TimeZone ( identifier: timeZoneString) else {
52- throw DecodingError . dataCorruptedError ( forKey: . timeZone, in: container, debugDescription: " Time zone string is not a valid identifier. " )
53- }
54- self . timeZone = timeZone
55-
56- // Custom decoding for the Date
57- let dateFormatter = DateFormatter ( )
58- dateFormatter. timeZone = timeZone
59- dateFormatter. dateFormat = " yyyy-MM-dd HH:mm:ss "
60- let dateString = try container. decode ( String . self, forKey: . lastRefreshed)
61- guard let date = dateFormatter. date ( from: dateString) else {
62- throw DecodingError . dataCorruptedError ( forKey: . lastRefreshed, in: container, debugDescription: " Date string does not match format expected by formatter. " )
63- }
64- lastRefreshed = date
47+ timeZone = try container. decode ( String . self, forKey: . timeZone)
48+ lastRefreshed = try container. decode ( String . self, forKey: . lastRefreshed)
6549 }
6650}
0 commit comments