Skip to content

Commit 3781e2e

Browse files
authored
G7SensorKit: Update expiration timer (LoopKit#11)
* Update expiration timer moved expiration timer to DateComponentsFormatter to allow more granular control over date units displayed * Fix localization of date and time in sensor time displays Set locale and use setLocalizedDateFormatFromTemplate in date formatter for sensor date displays * Moved sessionLengthFormatter out of view Moved sessionLengthFormatter out of view Removed original durationFormatter
1 parent 8371785 commit 3781e2e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

G7SensorKitUI/Views/G7SettingsView.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import G7SensorKit
1212
import LoopKitUI
1313

1414
struct G7SettingsView: View {
15-
16-
private var durationFormatter: RelativeDateTimeFormatter = {
17-
let formatter = RelativeDateTimeFormatter()
15+
16+
private var sessionLengthFormatter: DateComponentsFormatter = {
17+
let formatter = DateComponentsFormatter()
18+
formatter.allowedUnits = [.day, .hour, .minute]
1819
formatter.unitsStyle = .full
20+
formatter.maximumUnitCount = 2
1921
return formatter
2022
}()
21-
23+
2224
@Environment(\.guidanceColors) private var guidanceColors
2325
@Environment(\.glucoseTintColor) private var glucoseTintColor
2426

@@ -39,6 +41,8 @@ struct G7SettingsView: View {
3941

4042
formatter.dateStyle = .short
4143
formatter.timeStyle = .short
44+
formatter.locale = Locale.current
45+
formatter.setLocalizedDateFormatFromTemplate("E, MMM d, hh:mm")
4246

4347
return formatter
4448
}()
@@ -174,7 +178,7 @@ struct G7SettingsView: View {
174178

175179
Spacer()
176180
if let referenceDate = viewModel.progressReferenceDate {
177-
Text(durationFormatter.localizedString(for: referenceDate, relativeTo: Date()))
181+
Text(sessionLengthFormatter.string(from: referenceDate.timeIntervalSince(Date())) ?? "")
178182
.foregroundColor(.secondary)
179183
}
180184
}

0 commit comments

Comments
 (0)