forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateRelativeBolusEntry.swift
More file actions
27 lines (23 loc) · 946 Bytes
/
DateRelativeBolusEntry.swift
File metadata and controls
27 lines (23 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//
// DateRelativeBolusEntry.swift
// LoopTestingKit
//
// Created by Michael Pangburn on 4/20/19.
// Copyright © 2019 LoopKit Authors. All rights reserved.
//
import LoopKit
import Foundation
struct DateRelativeBolusEntry: DateRelativeQuantity, Codable {
var unitsValue: Double
var dateOffset: TimeInterval
var deliveryDuration: TimeInterval
func doseEntry(relativeTo referenceDate: Date) -> DoseEntry {
let startDate = referenceDate.addingTimeInterval(dateOffset)
let endDate = startDate.addingTimeInterval(deliveryDuration)
return DoseEntry(type: .bolus, startDate: startDate, endDate: endDate, value: unitsValue, unit: .units)
}
func newPumpEvent(relativeTo referenceDate: Date) -> NewPumpEvent {
let dose = doseEntry(relativeTo: referenceDate)
return NewPumpEvent(date: dose.startDate, dose: dose, raw: .newPumpEventIdentifier(), title: "Bolus", type: .bolus)
}
}