[+] Make sure it repeats on that day
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user