BuildExpireCondition.swift 584 B

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