[AltWidget] Fixes incorrect days until expiration

Previously, we used Date() to calculate the number of days until apps expired. This meant all calculations were based on when the widget extension was run — not when it was actually displayed. As a result, this made it seem like the widget never updated since all timeline entries were calculated from the same date.

Now, we instead calculate remaining days from AppEntry.date. This means the widget’s remaining days are relative to the current timeline entry’s date, matching what is displayed in AltStore.
This commit is contained in:
Riley Testut
2021-10-04 16:54:18 -07:00
parent c3ca4fa8f3
commit b7caaeb788
2 changed files with 18 additions and 5 deletions

View File

@@ -11,15 +11,16 @@ import WidgetKit
struct Countdown: View
{
let startDate: Date?
let endDate: Date?
var startDate: Date?
var endDate: Date?
var currentDate: Date = Date()
@Environment(\.font) private var font
private var numberOfDays: Int {
guard let date = self.endDate else { return 0 }
let numberOfDays = date.numberOfCalendarDays(since: Date())
let numberOfDays = date.numberOfCalendarDays(since: self.currentDate)
return numberOfDays
}