[+] Make sure it repeats on that day

This commit is contained in:
Hykilpikonna
2021-01-17 14:26:17 -05:00
parent 7e17405858
commit 79202c71f3
+6
View File
@@ -56,6 +56,9 @@ struct Alarm: Codable
/// When should the alarm activate next /// When should the alarm activate next
var nextActivate: Date? var nextActivate: Date?
{ {
// Make sure it's repeating
guard (repeats.contains { $0 }) else { return nil }
// Get current date // Get current date
let now = Date() let now = Date()
let (y, m, d) = now.getYMD() let (y, m, d) = now.getYMD()
@@ -67,6 +70,9 @@ struct Alarm: Codable
// If it will activate tomorrow // If it will activate tomorrow
if nh > hour || (nh == hour && nm > minute) { date = date.added(.day, 1) } if nh > hour || (nh == hour && nm > minute) { date = date.added(.day, 1) }
// If the day is not one of the "repeat" days, keep adding 1 until it is
while !repeats[date.get(.weekday)] { date = date.added(.day, 1) }
return date return date
} }
} }