Showing
4 changed files
with
30 additions
and
8 deletions
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
| ... | @@ -96,7 +96,7 @@ public class CouponSetItemModel { | ... | @@ -96,7 +96,7 @@ public class CouponSetItemModel { |
| 96 | /// Try multiple date formats and return the first successful parse | 96 | /// Try multiple date formats and return the first successful parse |
| 97 | /// - Parameter dateString: The date string to parse | 97 | /// - Parameter dateString: The date string to parse |
| 98 | /// - Returns: Parsed Date or nil if no format matched | 98 | /// - Returns: Parsed Date or nil if no format matched |
| 99 | - private static func parseDate(_ dateString: String) -> Date? { | 99 | + static func parseDate(_ dateString: String) -> Date? { |
| 100 | let formatter = DateFormatter() | 100 | let formatter = DateFormatter() |
| 101 | for format in supportedDateFormats { | 101 | for format in supportedDateFormats { |
| 102 | formatter.dateFormat = format | 102 | formatter.dateFormat = format |
| ... | @@ -411,7 +411,8 @@ public class CouponItemModel { | ... | @@ -411,7 +411,8 @@ public class CouponItemModel { |
| 411 | public let couponset_uuid: String? | 411 | public let couponset_uuid: String? |
| 412 | public let name: String? | 412 | public let name: String? |
| 413 | public let image: String? | 413 | public let image: String? |
| 414 | - public let expiration: String? | 414 | + public let expiration: String? // raw string from API e.g. "2026-06-30 11:59:00" |
| 415 | + public let expiration_formatted: String? // pre-formatted "dd/MM/yyyy" for display | ||
| 415 | public let created: String? | 416 | public let created: String? |
| 416 | public let description: String? | 417 | public let description: String? |
| 417 | public let discount: String? | 418 | public let discount: String? |
| ... | @@ -495,15 +496,16 @@ public class CouponItemModel { | ... | @@ -495,15 +496,16 @@ public class CouponItemModel { |
| 495 | } | 496 | } |
| 496 | // <== | 497 | // <== |
| 497 | 498 | ||
| 498 | - let expirationString = dictionary["expiration"] as? String? ?? "" | 499 | + let expirationString = dictionary["expiration"] as? String ?? "" |
| 500 | + self.expiration = expirationString | ||
| 501 | + | ||
| 499 | let dateFormatter = DateFormatter() | 502 | let dateFormatter = DateFormatter() |
| 500 | dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" | 503 | dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" |
| 501 | - if let date = dateFormatter.date(from: expirationString ?? "") { | 504 | + if let date = dateFormatter.date(from: expirationString) { |
| 502 | dateFormatter.dateFormat = "dd/MM/yyyy" | 505 | dateFormatter.dateFormat = "dd/MM/yyyy" |
| 503 | - let resultString = dateFormatter.string(from: date) | 506 | + self.expiration_formatted = dateFormatter.string(from: date) |
| 504 | - self.expiration = resultString | ||
| 505 | } else { | 507 | } else { |
| 506 | - self.expiration = "" | 508 | + self.expiration_formatted = "" |
| 507 | } | 509 | } |
| 508 | 510 | ||
| 509 | // Extract created date: try changes_dates.created first (universal coupons), then top-level created | 511 | // Extract created date: try changes_dates.created first (universal coupons), then top-level created |
| ... | @@ -558,6 +560,26 @@ public class CouponItemModel { | ... | @@ -558,6 +560,26 @@ public class CouponItemModel { |
| 558 | public func setCouponSetData(_ couponSet: CouponSetItemModel) { | 560 | public func setCouponSetData(_ couponSet: CouponSetItemModel) { |
| 559 | self.couponset_data = couponSet | 561 | self.couponset_data = couponSet |
| 560 | } | 562 | } |
| 563 | + | ||
| 564 | + /// Returns the expiration as a Date object for date comparisons (e.g. days-left calculation) | ||
| 565 | + public var expirationDate: Date? { | ||
| 566 | + guard let raw = self.expiration, !raw.isEmpty else { return nil } | ||
| 567 | + return CouponSetItemModel.parseDate(raw) | ||
| 568 | + } | ||
| 569 | + | ||
| 570 | + /// Format expiration date with a custom output format. | ||
| 571 | + /// Uses the same multi-format parser as CouponSetItemModel. | ||
| 572 | + /// - Parameter format: DateFormatter format string (e.g. "MMMM d, yyyy", "dd/MM/yyyy") | ||
| 573 | + /// - Returns: Formatted date string, or empty string if expiration is absent or unparseable | ||
| 574 | + public func formattedExpiration(format: String) -> String { | ||
| 575 | + guard let raw = self.expiration, !raw.isEmpty else { return "" } | ||
| 576 | + if let date = CouponSetItemModel.parseDate(raw) { | ||
| 577 | + let formatter = DateFormatter() | ||
| 578 | + formatter.dateFormat = format | ||
| 579 | + return formatter.string(from: date) | ||
| 580 | + } | ||
| 581 | + return "" | ||
| 582 | + } | ||
| 561 | } | 583 | } |
| 562 | 584 | ||
| 563 | public class RedeemedSMHistoryModel { | 585 | public class RedeemedSMHistoryModel { | ... | ... |
| ... | @@ -383,7 +383,7 @@ extension MyCouponsViewController: UITableViewDelegate, UITableViewDataSource { | ... | @@ -383,7 +383,7 @@ extension MyCouponsViewController: UITableViewDelegate, UITableViewDataSource { |
| 383 | } | 383 | } |
| 384 | 384 | ||
| 385 | public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | 385 | public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { |
| 386 | - if (indexPath.section <= 3) { | 386 | + if (indexPath.section <= 1) { |
| 387 | // Do nothing | 387 | // Do nothing |
| 388 | } else { | 388 | } else { |
| 389 | if let items = self.filteredOffersSection?.items, | 389 | if let items = self.filteredOffersSection?.items, | ... | ... |
-
Please register or login to post a comment