BuildExpireCondition.swift 616 B

123456789101112131415161718192021
  1. // LoopFollow
  2. // BuildExpireCondition.swift
  3. // Created by Jonas Björkert on 2025-04-26.
  4. import Foundation
  5. struct BuildExpireCondition: AlarmCondition {
  6. static let type: AlarmType = .buildExpire
  7. init() {}
  8. func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
  9. guard let expiry = data.expireDate else { return false }
  10. guard let thresholdDays = alarm.threshold else { return false }
  11. let thresholdSeconds = TimeInterval(thresholdDays) * TimeUnit.day.seconds
  12. let thresholdDate = expiry.addingTimeInterval(-thresholdSeconds)
  13. return Date() >= thresholdDate
  14. }
  15. }