GlucoseChange.swift 692 B

12345678910111213141516171819202122232425262728
  1. //
  2. // GlucoseChange.swift
  3. // LoopKit
  4. //
  5. // Copyright © 2018 LoopKit Authors. All rights reserved.
  6. //
  7. import HealthKit
  8. public struct GlucoseChange: SampleValue, Equatable {
  9. public var startDate: Date
  10. public var endDate: Date
  11. public var quantity: HKQuantity
  12. }
  13. extension GlucoseChange {
  14. mutating public func append(_ effect: GlucoseEffect) {
  15. startDate = min(effect.startDate, startDate)
  16. endDate = max(effect.endDate, endDate)
  17. quantity = HKQuantity(
  18. unit: .milligramsPerDeciliter,
  19. doubleValue: quantity.doubleValue(for: .milligramsPerDeciliter) + effect.quantity.doubleValue(for: .milligramsPerDeciliter)
  20. )
  21. }
  22. }