Manos Chorianopoulos

fix redeemed coupons sorting

......@@ -605,6 +605,7 @@ public class swiftApi {
public let barcode: String?
public let status: Int?
public let redeemed: String?
public let redeemed_date: Date?
public var couponset_data: CouponSetItemModel?
// Market Coupon
......@@ -669,15 +670,18 @@ public class swiftApi {
let dateFormatter3 = DateFormatter()
dateFormatter3.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSSSS"
if let date = dateFormatter3.date(from: redeemedString ?? "") {
self.redeemed_date = date
dateFormatter3.dateFormat = "dd/MM/yyyy"
let resultString = dateFormatter3.string(from: date)
self.redeemed = resultString
} else {
self.redeemed = ""
self.redeemed_date = Date()
}
} else {
self.redeemed = ""
self.redeemed_date = Date()
}
}
......@@ -4398,7 +4402,26 @@ public class swiftApi {
public func setOldCouponList(_ coupons: Array<CouponItemModel>) {
// let filteredCoupons = coupons.filter { CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: $0.discount ?? "")) }
let oldCoupons = coupons.filter({ return $0.status == 0 })
var oldCoupons = coupons.filter({ return $0.status == 0 })
// sort oldCoupons by redeemed date
// let dateFormatter = DateFormatter()
// dateFormatter.dateFormat = "dd/MM/yyyy"
oldCoupons.sort(by: {
// let date1 = dateFormatter.date(from: $0.redeemed ?? "")
// let date2 = dateFormatter.date(from: $1.redeemed ?? "")
let date1 = $0.redeemed_date
let date2 = $1.redeemed_date
if ((date1 != nil) && (date2 != nil)) {
return date1!.compare(date2!) == .orderedDescending
} else {
return false
}
})
GlobalVariables.oldCouponList = oldCoupons
}
......