Skip to content

Commit 40ffaa1

Browse files
shaheinmclaude
andcommitted
Fix edit sheet bottom time to use computed value and write override
The edit sheet's Bottom Time field was initialized from the raw DB column (which held total runtime for imported dives) and wrote to bottomTimeSec which stats computation ignores. Now: - Initializes from computed stats when available (e.g. 27 min, not 73) - When changed, writes to bottomEndTOverrideSec so the override flows through stats recomputation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8ebdda9 commit 40ffaa1

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

Profundum/Profundum/Views/DiveDetailView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ struct DiveDetailView: View {
214214
editingDive: dive,
215215
editingTags: tags,
216216
editingTeammateIds: loadedTeammateIds,
217-
editingEquipmentIds: loadedEquipmentIds
217+
editingEquipmentIds: loadedEquipmentIds,
218+
computedBottomTimeSec: stats?.bottomTimeSec
218219
)
219220
}
220221
.alert("Error", isPresented: Binding(get: { errorMessage != nil }, set: { if !$0 { errorMessage = nil } })) {

Profundum/Profundum/Views/NewDiveSheet.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct NewDiveSheet: View {
1313
@State private var maxDepthText = "30.0"
1414
@State private var avgDepthText = "18.0"
1515
@State private var bottomTimeMinutes = 50
16+
@State private var initialBottomTimeMinutes = 50
1617

1718
@State private var isCCR = false
1819
@State private var decoRequired = false
@@ -53,6 +54,7 @@ struct NewDiveSheet: View {
5354
var editingTags: [String] = []
5455
var editingTeammateIds: [String] = []
5556
var editingEquipmentIds: [String] = []
57+
var computedBottomTimeSec: Int32?
5658

5759
private var sheetTitle: String {
5860
editingDive != nil ? "Edit Dive" : "New Dive"
@@ -122,7 +124,8 @@ struct NewDiveSheet: View {
122124
let displayAvgDepth = UnitFormatter.depth(dive.avgDepthM, unit: appState.depthUnit)
123125
maxDepthText = String(format: "%.1f", displayMaxDepth)
124126
avgDepthText = String(format: "%.1f", displayAvgDepth)
125-
bottomTimeMinutes = Int(dive.bottomTimeSec / 60)
127+
bottomTimeMinutes = Int((computedBottomTimeSec ?? dive.bottomTimeSec) / 60)
128+
initialBottomTimeMinutes = bottomTimeMinutes
126129
isCCR = dive.isCcr
127130
decoRequired = dive.decoRequired
128131
cnsPercentText = String(format: "%.0f", dive.cnsPercent)
@@ -700,7 +703,9 @@ struct NewDiveSheet: View {
700703
computerDiveNumber: editingDive?.computerDiveNumber,
701704
fingerprint: editingDive?.fingerprint,
702705
timezoneOffsetSec: savedTimezoneOffset,
703-
bottomEndTOverrideSec: editingDive?.bottomEndTOverrideSec
706+
bottomEndTOverrideSec: bottomTimeMinutes != initialBottomTimeMinutes
707+
? Int32(bottomTimeMinutes * 60)
708+
: editingDive?.bottomEndTOverrideSec
704709
)
705710

706711
var allTags = [selectedDiveTypeTag.rawValue]

0 commit comments

Comments
 (0)