RemoteBolusHistoryEntry.swift 789 B

12345678910111213141516171819202122232425262728
  1. // LoopFollow
  2. // RemoteBolusHistoryEntry.swift
  3. import Foundation
  4. /// A record of a remotely-sent bolus, stored locally for pattern-based suggestions.
  5. struct RemoteBolusHistoryEntry: Codable, Equatable {
  6. /// Bolus amount in international units
  7. let units: Double
  8. /// When the bolus was sent
  9. let date: Date
  10. /// Day of week: 1=Sunday ... 7=Saturday (Calendar.component(.weekday))
  11. let dayOfWeek: Int
  12. /// Minute of day: 0...1439 (hour * 60 + minute)
  13. let minuteOfDay: Int
  14. init(units: Double, date: Date) {
  15. self.units = units
  16. self.date = date
  17. let cal = Calendar.current
  18. dayOfWeek = cal.component(.weekday, from: date)
  19. minuteOfDay = cal.component(.hour, from: date) * 60 + cal.component(.minute, from: date)
  20. }
  21. }