NotLoopingCondition.swift 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. // LoopFollow
  2. // NotLoopingCondition.swift
  3. // Created by Jonas Björkert on 2025-05-14.
  4. import Foundation
  5. struct NotLoopingCondition: AlarmCondition {
  6. static let type: AlarmType = .notLooping
  7. init() {}
  8. func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
  9. // ────────────────────────────────
  10. // 0. sanity checks
  11. // ────────────────────────────────
  12. guard let thresholdMinutes = alarm.threshold,
  13. thresholdMinutes > 0 else { return false }
  14. // We need a valid timestamp (seconds-since-1970) of the last Loop run.
  15. guard let lastLoopTime = data.lastLoopTime,
  16. lastLoopTime > 0 else { return false }
  17. // ────────────────────────────────
  18. // 1. elapsed-time test
  19. // ────────────────────────────────
  20. let elapsedSecs = Date().timeIntervalSince1970 - lastLoopTime
  21. let limitSecs = thresholdMinutes * 60
  22. return elapsedSecs >= limitSecs
  23. }
  24. }