Skip to content

Commit

Permalink
Merge pull request #356 from MikePlante1/mmol_entry
Browse files Browse the repository at this point in the history
Fix manual glucose entry for mmol/L
  • Loading branch information
dnzxy authored Jul 27, 2024
2 parents 6c88cee + 95cd752 commit 03ef229
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ extension DataTable {
return formatter
}

private var glucoseEntryFormatter: NumberFormatter {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.maximumFractionDigits = 0
if state.units == .mmolL {
formatter.minimumFractionDigits = 0
formatter.maximumFractionDigits = 1
}
formatter.roundingMode = .down
return formatter
}

private var dateFormatter: DateFormatter {
let formatter = DateFormatter()
formatter.timeStyle = .short
Expand Down Expand Up @@ -144,16 +156,16 @@ extension DataTable {
text: $state.manualGlucose,
placeholder: " ... ",
shouldBecomeFirstResponder: true,
numberFormatter: glucoseFormatter
numberFormatter: glucoseEntryFormatter
)
Text(state.units.rawValue).foregroundStyle(.secondary)
}
}

Section {
HStack {
let limitLow: Decimal = state.units == .mmolL ? 0.8 : 40
let limitHigh: Decimal = state.units == .mmolL ? 14 : 720
let limitLow: Decimal = state.units == .mmolL ? 0.8 : 14
let limitHigh: Decimal = state.units == .mmolL ? 40 : 720

Button {
state.logManualGlucose()
Expand Down

0 comments on commit 03ef229

Please sign in to comment.