RemoteMealHistoryEntry.swift 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // LoopFollow
  2. // RemoteMealHistoryEntry.swift
  3. import Foundation
  4. /// A record of a remotely-sent meal, stored locally for pattern-based common meals.
  5. struct RemoteMealHistoryEntry: Codable, Equatable {
  6. /// Carbs in grams
  7. let carbs: Double
  8. /// Fat in grams (0 if not applicable)
  9. let fat: Double
  10. /// Protein in grams (0 if not applicable)
  11. let protein: Double
  12. /// Bolus in units (0 if no bolus with meal)
  13. let bolus: Double
  14. /// When the meal was sent
  15. let date: Date
  16. /// Day of week: 1=Sunday ... 7=Saturday (Calendar.component(.weekday))
  17. let dayOfWeek: Int
  18. /// Minute of day: 0...1439 (hour * 60 + minute)
  19. let minuteOfDay: Int
  20. init(carbs: Double, fat: Double = 0, protein: Double = 0, bolus: Double = 0, date: Date = Date()) {
  21. self.carbs = carbs
  22. self.fat = fat
  23. self.protein = protein
  24. self.bolus = bolus
  25. self.date = date
  26. let cal = Calendar.current
  27. dayOfWeek = cal.component(.weekday, from: date)
  28. minuteOfDay = cal.component(.hour, from: date) * 60 + cal.component(.minute, from: date)
  29. }
  30. }