Showing
1 changed file
with
24 additions
and
1 deletions
... | @@ -605,6 +605,7 @@ public class swiftApi { | ... | @@ -605,6 +605,7 @@ public class swiftApi { |
605 | public let barcode: String? | 605 | public let barcode: String? |
606 | public let status: Int? | 606 | public let status: Int? |
607 | public let redeemed: String? | 607 | public let redeemed: String? |
608 | + public let redeemed_date: Date? | ||
608 | public var couponset_data: CouponSetItemModel? | 609 | public var couponset_data: CouponSetItemModel? |
609 | 610 | ||
610 | // Market Coupon | 611 | // Market Coupon |
... | @@ -669,15 +670,18 @@ public class swiftApi { | ... | @@ -669,15 +670,18 @@ public class swiftApi { |
669 | let dateFormatter3 = DateFormatter() | 670 | let dateFormatter3 = DateFormatter() |
670 | dateFormatter3.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSSSS" | 671 | dateFormatter3.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSSSS" |
671 | if let date = dateFormatter3.date(from: redeemedString ?? "") { | 672 | if let date = dateFormatter3.date(from: redeemedString ?? "") { |
673 | + self.redeemed_date = date | ||
672 | dateFormatter3.dateFormat = "dd/MM/yyyy" | 674 | dateFormatter3.dateFormat = "dd/MM/yyyy" |
673 | let resultString = dateFormatter3.string(from: date) | 675 | let resultString = dateFormatter3.string(from: date) |
674 | self.redeemed = resultString | 676 | self.redeemed = resultString |
675 | } else { | 677 | } else { |
676 | self.redeemed = "" | 678 | self.redeemed = "" |
679 | + self.redeemed_date = Date() | ||
677 | } | 680 | } |
678 | 681 | ||
679 | } else { | 682 | } else { |
680 | self.redeemed = "" | 683 | self.redeemed = "" |
684 | + self.redeemed_date = Date() | ||
681 | } | 685 | } |
682 | 686 | ||
683 | } | 687 | } |
... | @@ -4398,7 +4402,26 @@ public class swiftApi { | ... | @@ -4398,7 +4402,26 @@ public class swiftApi { |
4398 | 4402 | ||
4399 | public func setOldCouponList(_ coupons: Array<CouponItemModel>) { | 4403 | public func setOldCouponList(_ coupons: Array<CouponItemModel>) { |
4400 | // let filteredCoupons = coupons.filter { CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: $0.discount ?? "")) } | 4404 | // let filteredCoupons = coupons.filter { CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: $0.discount ?? "")) } |
4401 | - let oldCoupons = coupons.filter({ return $0.status == 0 }) | 4405 | + var oldCoupons = coupons.filter({ return $0.status == 0 }) |
4406 | + | ||
4407 | + // sort oldCoupons by redeemed date | ||
4408 | +// let dateFormatter = DateFormatter() | ||
4409 | +// dateFormatter.dateFormat = "dd/MM/yyyy" | ||
4410 | + | ||
4411 | + oldCoupons.sort(by: { | ||
4412 | +// let date1 = dateFormatter.date(from: $0.redeemed ?? "") | ||
4413 | +// let date2 = dateFormatter.date(from: $1.redeemed ?? "") | ||
4414 | + | ||
4415 | + let date1 = $0.redeemed_date | ||
4416 | + let date2 = $1.redeemed_date | ||
4417 | + | ||
4418 | + if ((date1 != nil) && (date2 != nil)) { | ||
4419 | + return date1!.compare(date2!) == .orderedDescending | ||
4420 | + } else { | ||
4421 | + return false | ||
4422 | + } | ||
4423 | + | ||
4424 | + }) | ||
4402 | 4425 | ||
4403 | GlobalVariables.oldCouponList = oldCoupons | 4426 | GlobalVariables.oldCouponList = oldCoupons |
4404 | } | 4427 | } | ... | ... |
-
Please register or login to post a comment