Manos Chorianopoulos

add active coupons sortin by expiration date

......@@ -206,7 +206,8 @@ import SwiftEventBus
if (dfyCoupons.count > 0) {
if (dfyCoupons.count == 1) {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
// dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
// sort dfyCoupons by date
dfyCoupons.sort(by: {
......
......@@ -644,7 +644,22 @@ public class swiftApi {
// SwiftEventBus.post("coupons_fetched")
let activeCoupons = tempCoupons.filter({ return $0.status == 1 })
var activeCoupons = tempCoupons.filter({ return $0.status == 1 })
// sort activeCoupons by expiration date
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy"
activeCoupons.sort(by: {
let date1 = dateFormatter.date(from: $0.expiration ?? "")
let date2 = dateFormatter.date(from: $1.expiration ?? "")
if ((date1 != nil) && (date2 != nil)) {
return date1!.compare(date2!) == .orderedAscending
} else {
return false
}
})
getCouponsCallback(activeCoupons)
}
......@@ -3781,9 +3796,25 @@ public class swiftApi {
public func setCouponList(_ coupons: Array<CouponItemModel>) {
// let filteredCoupons = coupons.filter { CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: $0.discount ?? "")) }
let activeCoupons = coupons.filter({ return $0.status == 1 })
var activeCoupons = coupons.filter({ return $0.status == 1 })
let oldCoupons = coupons.filter({ return $0.status == 0 })
// sort activeCoupons by expiration date
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy"
activeCoupons.sort(by: {
let date1 = dateFormatter.date(from: $0.expiration ?? "")
let date2 = dateFormatter.date(from: $1.expiration ?? "")
if ((date1 != nil) && (date2 != nil)) {
return date1!.compare(date2!) == .orderedAscending
} else {
return false
}
})
GlobalVariables.couponList = activeCoupons
let loyaltyBadge = LoyaltyBadgeModel()
......