Skip to content

Commit 216ba17

Browse files
committed
feat: improve heart chart header to show date range with hour (rounded) and full day detection
1 parent 7f2b0fd commit 216ba17

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

InfiniLink/Core/Components/Charts/Heart/HeartChartView.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ struct HeartChartView: View {
164164
}
165165
}
166166

167+
// MARK: iOS 16- fixed chart
167168
var pagedChart: some View {
168169
VStack(spacing: 0) {
169170
HStack {
@@ -193,6 +194,7 @@ struct HeartChartView: View {
193194
}
194195
}
195196

197+
// MARK: iOS 17+ scrollable chart
196198
@available(iOS 17, *)
197199
var scrollableChart: some View {
198200
Chart {
@@ -246,9 +248,14 @@ struct HeartChartView: View {
246248
.font(.system(.title, design: .rounded))
247249
.foregroundColor(.primary)
248250
+ Text("BPM")
249-
Text(displayedDate.formatted(.dateTime.weekday(.abbreviated).month(.abbreviated).day().year()))
250-
.foregroundColor(.secondary)
251-
.font(.subheadline)
251+
let rounded = Date(timeIntervalSinceReferenceDate: (scrollPositionDate.timeIntervalSinceReferenceDate / 3600).rounded() * 3600)
252+
let end = Date(timeInterval: 86400, since: rounded)
253+
let isFullDay = Calendar.current.component(.hour, from: rounded) == 0
254+
Text(isFullDay
255+
? rounded.formatted(.dateTime.weekday(.abbreviated).month(.abbreviated).day().year())
256+
: "\(rounded.formatted(.dateTime.month(.abbreviated).day())), \(rounded.formatted(.dateTime.hour().minute()))\(end.formatted(.dateTime.month(.abbreviated).day())), \(end.formatted(.dateTime.hour().minute()))")
257+
.foregroundColor(.secondary)
258+
.font(.subheadline)
252259
}
253260
.fontWeight(.semibold)
254261
}

0 commit comments

Comments
 (0)