Skip to content

Commit a873d46

Browse files
committed
fix pill not bug
1 parent 50f6bcc commit a873d46

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 3.2.2
4+
5+
Fixed
6+
7+
- Issue where pill notifications would re-schedule correctly.
8+
39
## 3.2.1
410

511
Fixed

Sources/PatchData/PatchDataObjects/Pill.swift

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public class Pill: Swallowable {
124124
lastTaken = attributes.lastTaken ?? lastTaken
125125
expirationInterval = attributes.expirationInterval ?? expirationInterval
126126
pillData.attributes.times = attributes.times ?? pillData.attributes.times
127+
pillData.attributes.timesTakenToday = attributes.timesTakenToday
128+
?? pillData.attributes.timesTakenToday
127129
}
128130

129131
public func swallow() {

Sources/PatchDay/AppDelegate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import WidgetKit
3838
if let hormone = sdk.hormones[0] {
3939
notifications.requestExpiredHormoneNotification(for: hormone)
4040
}
41-
if let pill = sdk.pills[0] {
41+
for pill in sdk.pills.all where pill.name == "Notification Test" {
4242
notifications.requestDuePillNotification(pill)
4343
}
4444
}

Sources/PatchDay/Notifications/Notifications/DuePillNotification.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ public class DuePillNotification: Notification, PDNotificationProtocol {
3434

3535
public func request() {
3636
super.content.categoryIdentifier = DuePillNotification.categoryId
37-
if let interval = pill.due?.timeIntervalSince(Date()), interval > 0 {
38-
PDLog<DuePillNotification>().info("Pill notification in \(interval)")
39-
super.request(when: interval, requestId: pill.id.uuidString)
40-
}
37+
guard let dueDate = pill.due else { return }
38+
let interval = dueDate.timeIntervalSince(Date())
39+
guard interval > 0 else { return }
40+
let dueDateString = PDDateFormatter.formatDate(dueDate)
41+
let logMessage = "Pill notification in \(interval), due: \(dueDateString)"
42+
PDLog<DuePillNotification>().info(logMessage)
43+
super.request(when: interval, requestId: pill.id.uuidString)
4144
}
4245
}

0 commit comments

Comments
 (0)