forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateRelativeBasalEntry.swift
More file actions
28 lines (23 loc) · 965 Bytes
/
DateRelativeBasalEntry.swift
File metadata and controls
28 lines (23 loc) · 965 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
28
//
// DateRelativeBasalEntry.swift
// LoopTestingKit
//
// Created by Michael Pangburn on 4/20/19.
// Copyright © 2019 LoopKit Authors. All rights reserved.
//
import Foundation
import LoopKit
struct DateRelativeBasalEntry: DateRelativeQuantity, Codable {
var unitsPerHourValue: Double
var dateOffset: TimeInterval
var duration: TimeInterval
func doseEntry(relativeTo referenceDate: Date) -> DoseEntry {
let startDate = referenceDate.addingTimeInterval(dateOffset)
let endDate = startDate.addingTimeInterval(duration)
return DoseEntry(type: .tempBasal, startDate: startDate, endDate: endDate, value: unitsPerHourValue, unit: .unitsPerHour)
}
func newPumpEvent(relativeTo referenceDate: Date) -> NewPumpEvent {
let dose = doseEntry(relativeTo: referenceDate)
return NewPumpEvent(date: dose.startDate, dose: dose, raw: .newPumpEventIdentifier(), title: "Temp Basal", type: .tempBasal)
}
}