BuildExpireCondition.swift 679 B

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