[+] Allow one-time alarms to bypass repeating date check
This commit is contained in:
@@ -48,7 +48,7 @@ struct Alarm: Codable
|
|||||||
var repeats: [Bool] = [false, true, true, true, true, true, false]
|
var repeats: [Bool] = [false, true, true, true, true, true, false]
|
||||||
|
|
||||||
/// Does it automatically disable after activating once
|
/// Does it automatically disable after activating once
|
||||||
var autoDisable = true
|
var oneTime = true
|
||||||
|
|
||||||
/// When is the last time that the alarm went off
|
/// When is the last time that the alarm went off
|
||||||
var lastActivate: Date? = nil
|
var lastActivate: Date? = nil
|
||||||
@@ -56,9 +56,6 @@ 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()
|
||||||
@@ -70,6 +67,12 @@ 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 it's one-time, don't have to check for repeating date
|
||||||
|
if oneTime { return date }
|
||||||
|
|
||||||
|
// Make sure it's repeating
|
||||||
|
guard (repeats.contains { $0 }) else { return nil }
|
||||||
|
|
||||||
// If the day is not one of the "repeat" days, keep adding 1 until it is
|
// 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) }
|
while !repeats[date.get(.weekday)] { date = date.added(.day, 1) }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user