change expiration date to Date type in model

This commit is contained in:
Pavel Vilbik
2023-07-05 18:17:54 +03:00
parent 518f44ce11
commit 0da6663492
2 changed files with 8 additions and 4 deletions

View File

@@ -129,7 +129,11 @@ class Client {
URLSession.shared.dataTask(.promise, with: try makePostRequest(urlString: mainURL + "/active-subscriptions", parameters: [:]))
}.map { data, response -> [Subscription] in
try self.validateApiResponse(data: data, response: response)
var subscriptions = try JSONDecoder().decode([Subscription].self, from: data)
let decoder = JSONDecoder()
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.sss'Z'"
decoder.dateDecodingStrategy = .formatted(formatter)
var subscriptions = try decoder.decode([Subscription].self, from: data)
DDLogInfo("API RESULT: active-subscriptions: \(subscriptions)")
// sort subscriptions with highest tier at the top
subscriptions.sort(by: { (sub1: Subscription, sub2: Subscription) -> Bool in

View File

@@ -28,10 +28,10 @@ struct SubscriptionEvent: Codable {
struct Subscription: Codable {
let planType: PlanType
let receiptId: String
let expirationDate: String
let expirationDate: Date
let expirationDateString: String
let expirationDateMs: Int
let cancellationDate: String?
let cancellationDate: Date?
let cancellationDateString: String?
let cancellationDateMs: Int?
@@ -45,7 +45,7 @@ struct Subscription: Codable {
static let anonymousMonthly = PlanType(rawValue: "ios-monthly")
static let anonymousAnnual = PlanType(rawValue: "ios-annual")
static let universalMonthly = PlanType(rawValue: "all-monthly")
static let universalAnnual = PlanType(rawValue: "all-annual")
static let universalAnnual = PlanType(rawValue: "all-annual")
}
}