commit 6d5697de2b9791c61056b0400e69a9089655086e
parent 07520aed55b8cae4874d2e91fbf386829b051789
Author: Michael Camilleri <[email protected]>
Date: Wed, 21 Oct 2026 06:34:48 +0900
Show reports by day in a calendar on the Charts tab
This commit adds a Calendar card to the Context section of the Charts
tab. The card shows the latest month as small squares, each day shaded
by how many reports were filed on it, with how many of the period's days
had one. It opens a month grid for each month the period touches, newest
first, and tapping a day with reports lists them in the same way as the
timeline.
Counts reload on returning from a day, so those changes show at once.
Shades are fixed rather than relative to the period — none, 1, 2–3, 4–5
and 6 or more. Days are determined by the device (the same as the
timeline).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat
| M | Notes/Design.md | | | 15 | ++++++++++++--- |
| M | Reportage.xcodeproj/project.pbxproj | | | 4 | ++++ |
| M | Reportage/Services/Charts/ContextSummary.swift | | | 61 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- |
| M | Reportage/Views/Charts/ContextCharts.swift | | | 23 | ++++++++++++++++++++--- |
| A | Reportage/Views/Charts/ReportCalendar.swift | | | 294 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | Reportage/Views/Home/HomeView.swift | | | 2 | +- |
| M | Tests/Unit/AnswerSummaryTests.swift | | | 24 | ++++++++++++++++++++++++ |
7 files changed, 415 insertions(+), 8 deletions(-)
diff --git a/Notes/Design.md b/Notes/Design.md
@@ -979,8 +979,16 @@ needs only one colour. Notes have no trend. Spans follow the period: days
for the past week or month, weeks for the past year, and months for all
time. Touching a chart shows a span's value.
-**Context.** After the questions, a Context section has Places, Steps and
-Temperature. Places shows the period's places on a small map and opens a
+**Context.** After the questions, a Context section has Calendar, Places,
+Steps and Temperature. Calendar shows the latest month as small squares,
+each day shaded by how many reports were filed on it (none, 1, 2–3, 4–5,
+6 or more, so a day of prompts with a wake and bedtime report reaches the
+darkest), and how many of the period's days had one. It opens a month grid
+for each month the period touches, newest first, with days outside the
+period unshaded; a day with reports opens them as the timeline shows them.
+Days are the device's, as in the timeline, so a day shows the same reports
+in both. The calendar starts on the period's first whole day, since the
+day it starts on is only partly in it. Places shows the period's places on a small map and opens a
full one: a circle for each place given as a location answer, from any
location question, sized by how many reports chose it (by area, so the
square root of the count), and tapping one names it. A merged place counts
@@ -1011,7 +1019,8 @@ the locale uses for weather. Sleep isn't charted.
[Weather](#weather)). Backfills are deferred (see
[Open Questions](#open-questions)).
6. **Visualisations.** The Charts tab, in steps: per-question summaries,
- then trends over time, a map of places, and a calendar and time of day.
+ then trends over time, a map of places, and a calendar of reports. Time
+ of day is deferred.
See [Charts](#charts).
7. **Synced schema.** Settle the [open questions](#open-questions) that change
synced data before the record formats are fixed: missed prompts, keeping
diff --git a/Reportage.xcodeproj/project.pbxproj b/Reportage.xcodeproj/project.pbxproj
@@ -58,6 +58,7 @@
89AC740ACEABE2AE5453E683 /* SurveyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844ABAD88442C143BA239374 /* SurveyModel.swift */; };
89AD9247DEBDB7017EC8E017 /* reporter-fixture.json in Resources */ = {isa = PBXBuildFile; fileRef = 60457C07EF790C11D6C47EDF /* reporter-fixture.json */; };
8ADBA81D5D9ECCDCD5BDA742 /* JSONSlicerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AFF3D49ED9E8AC69390925 /* JSONSlicerTests.swift */; };
+ 8AE517E5245B4F075672A040 /* ReportCalendar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FA891F300310E4E378EB09 /* ReportCalendar.swift */; };
8AF60BB296144ED9D11EA053 /* Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6024EA06BE24A189D4F7D0E4 /* Response.swift */; };
905D1185CF8B3426ECB91AFD /* HealthTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 695CB01E79016592A3823541 /* HealthTests.swift */; };
93B2DAAF451BBE42A539CB94 /* QuestionEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1458729667512D1B7E04D92F /* QuestionEditor.swift */; };
@@ -171,6 +172,7 @@
48ACB0E76C4E2271EA59B8E9 /* QuestionEditorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestionEditorTests.swift; sourceTree = "<group>"; };
48D44876FDE4293FA0460595 /* ReporterImporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReporterImporter.swift; sourceTree = "<group>"; };
4C40E7F6C3A90E317C8CB5B1 /* PlacePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlacePicker.swift; sourceTree = "<group>"; };
+ 50FA891F300310E4E378EB09 /* ReportCalendar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportCalendar.swift; sourceTree = "<group>"; };
5591E042089D038B59B26E9F /* ReportKind+Title.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ReportKind+Title.swift"; sourceTree = "<group>"; };
577EC17EF58F65207B7EA15D /* PlacePhrase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlacePhrase.swift; sourceTree = "<group>"; };
5BE7248E73E2859EFF232170 /* EntityMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntityMapping.swift; sourceTree = "<group>"; };
@@ -329,6 +331,7 @@
996F5818A958E305371F4BE3 /* ContextCharts.swift */,
AF6B203386F36F63252BAA9B /* PlacesMap.swift */,
F0A128C9CAF584114977A8D1 /* QuestionChartView.swift */,
+ 50FA891F300310E4E378EB09 /* ReportCalendar.swift */,
CD07F17AED0FDCF7B7D4C44B /* TrendChart.swift */,
);
path = Charts;
@@ -797,6 +800,7 @@
85A36A88AB170F0EAC0DAC03 /* QuestionPage.swift in Sources */,
9FEE3B78B770C6A3CF9C6610 /* QuestionsView.swift in Sources */,
06415D2A2EDA6E92ECAC96FA /* Report.swift in Sources */,
+ 8AE517E5245B4F075672A040 /* ReportCalendar.swift in Sources */,
A740B635075EB81AA70ED815 /* ReportDetailView.swift in Sources */,
34C3A453ABC838F73DC3E294 /* ReportDetails.swift in Sources */,
D7F95FB1236974113EBE93FA /* ReportKind+Title.swift in Sources */,
diff --git a/Reportage/Services/Charts/ContextSummary.swift b/Reportage/Services/Charts/ContextSummary.swift
@@ -88,12 +88,64 @@ struct PlacesSummary: Equatable, Sendable {
}
}
+/// How many reports were filed on each day of a period.
+struct CalendarSummary: Equatable, Sendable {
+ /// Each day's count, by the start of the day. Days without a report
+ /// are left out.
+ var counts: [Date: Int]
+ /// The start of the first day the period covers in full, and of today.
+ var first: Date
+ var last: Date
+ var reports: Int
+ /// How many days the period covers, today included.
+ var days: Int
+
+ /// The reports in `dates` from `first`'s day through `now`'s, by their
+ /// day in `calendar`, which, as in the timeline, is the device's rather
+ /// than each report's own, so a day here shows the same reports as
+ /// that day there.
+ static func summarise(
+ _ dates: [Date], from first: Date, through now: Date, calendar: Calendar = .current
+ ) -> CalendarSummary? {
+ let first = calendar.startOfDay(for: first)
+ let last = calendar.startOfDay(for: now)
+ guard first <= last else { return nil }
+ var counts: [Date: Int] = [:]
+ for date in dates {
+ let day = calendar.startOfDay(for: date)
+ guard day >= first, day <= last else { continue }
+ counts[day, default: 0] += 1
+ }
+ guard !counts.isEmpty else { return nil }
+ let days = (calendar.dateComponents([.day], from: first, to: last).day ?? 0) + 1
+ return CalendarSummary(
+ counts: counts, first: first, last: last, reports: counts.values.reduce(0, +), days: days)
+ }
+
+ /// How many days had a report.
+ var daysWithReports: Int { counts.count }
+
+ /// How dark a day with `count` reports is shaded, from 0 for none to 4
+ /// for six or more: a day of prompts with a wake and bedtime report
+ /// reaches the darkest.
+ static func level(of count: Int) -> Int {
+ switch count {
+ case ...0: 0
+ case 1: 1
+ case 2...3: 2
+ case 4...5: 3
+ default: 4
+ }
+ }
+}
+
struct ContextSummary: Equatable, Sendable {
+ var calendar: CalendarSummary?
var steps: StepsSummary?
var temperature: TemperatureSummary?
var places: PlacesSummary?
- var isEmpty: Bool { steps == nil && temperature == nil && places == nil }
+ var isEmpty: Bool { calendar == nil && steps == nil && temperature == nil && places == nil }
/// Trends are split into spans of `bucket` in `calendar`. A day's steps
/// are the highest count its reports captured, since each is the count
@@ -201,6 +253,13 @@ extension ReportStore {
})
let coordinates = try await tokenEntries(ids: Array(placeIDs)).compactMapValues(\.coordinate)
data.context.places = PlacesSummary.summarise(answerRows, lookup: lookup, tokenCoordinates: coordinates)
+ // The calendar starts with the first whole day: the day the period
+ // starts on is only partly in it.
+ let firstDay = start.flatMap { calendar.date(byAdding: .day, value: 1, to: $0) }
+ if let first = firstDay ?? contextRecords.map(\.date).min() {
+ data.context.calendar = CalendarSummary.summarise(
+ contextRecords.map(\.date), from: first, through: now, calendar: calendar)
+ }
if let first = start ?? contextRecords.map(\.date).min(), first <= now {
data.domain = calendar.start(of: period.bucket, for: first)...now
}
diff --git a/Reportage/Views/Charts/ContextCharts.swift b/Reportage/Views/Charts/ContextCharts.swift
@@ -6,13 +6,30 @@ enum ContextChart: Hashable {
case temperature
}
-/// A card for each kind of context captured in the period: the places
-/// chosen, opening their map, and steps and temperature, opening their
-/// trends.
+/// A card for each kind of context captured in the period: the days
+/// reports were filed, opening their calendar, the places chosen, opening
+/// their map, and steps and temperature, opening their trends.
struct ContextCards: View {
let model: ChartsModel
var body: some View {
+ if let calendar = model.data.context.calendar {
+ NavigationLink {
+ ReportCalendarView(model: model)
+ } label: {
+ ContextCard(title: "Calendar", footnote: Text("^[\(calendar.reports) report](inflect: true)")) {
+ VStack(alignment: .leading, spacing: Theme.itemGap) {
+ MonthGrid(
+ month: Calendar.current.start(of: .month, for: calendar.last), summary: calendar,
+ compact: true
+ )
+ .accessibilityHidden(true)
+ Text("Reports on \(calendar.daysWithReports) of ^[\(calendar.days) day](inflect: true)")
+ }
+ }
+ }
+ .settingsRow()
+ }
if let places = model.data.context.places, let top = places.places.first {
NavigationLink {
PlacesMapView(model: model)
diff --git a/Reportage/Views/Charts/ReportCalendar.swift b/Reportage/Views/Charts/ReportCalendar.swift
@@ -0,0 +1,294 @@
+import CoreData
+import SwiftUI
+
+/// A month of days, each shaded by how many reports were filed on it. Days
+/// outside the period are left unshaded. Compact, it's a small grid of
+/// squares without numbers, for a card.
+struct MonthGrid: View {
+ /// The start of the month.
+ let month: Date
+ let summary: CalendarSummary
+ var compact = false
+ /// Opens a day with reports. Without it, days can't be tapped.
+ var onOpen: ((Date) -> Void)?
+
+ var body: some View {
+ let calendar = Calendar.current
+ let days = Self.days(in: month, calendar: calendar)
+ let spacing: CGFloat = compact ? 3 : 4
+ let column = compact ? GridItem(.fixed(16), spacing: spacing) : GridItem(.flexible(), spacing: spacing)
+ LazyVGrid(columns: Array(repeating: column, count: 7), alignment: .leading, spacing: spacing) {
+ if !compact {
+ ForEach(Array(Self.weekdaySymbols(calendar).enumerated()), id: \.offset) { _, symbol in
+ Text(symbol)
+ .eyebrow()
+ .frame(maxWidth: .infinity)
+ .accessibilityHidden(true)
+ }
+ }
+ ForEach(days.indices, id: \.self) { index in
+ if let day = days[index] {
+ cell(for: day)
+ } else {
+ Color.clear.frame(height: compact ? 16 : 36)
+ }
+ }
+ }
+ }
+
+ @ViewBuilder
+ private func cell(for day: Date) -> some View {
+ let count = summary.counts[day] ?? 0
+ let isInPeriod = day >= summary.first && day <= summary.last
+ let cell = DayCell(
+ day: day, count: count, isInPeriod: isInPeriod, isFuture: day > summary.last, compact: compact)
+ if let onOpen, count > 0 {
+ Button {
+ onOpen(day)
+ } label: {
+ cell
+ }
+ .buttonStyle(.plain)
+ .accessibilityHint(Text("Shows this day's reports"))
+ } else {
+ cell
+ }
+ }
+
+ /// The month's days, starting on the calendar's first weekday, with
+ /// `nil` for the blanks before the first.
+ private static func days(in month: Date, calendar: Calendar) -> [Date?] {
+ guard let range = calendar.range(of: .day, in: .month, for: month) else { return [] }
+ let blanks = (calendar.component(.weekday, from: month) - calendar.firstWeekday + 7) % 7
+ let days = range.compactMap { day in calendar.date(byAdding: .day, value: day - 1, to: month) }
+ return Array(repeating: nil, count: blanks) + days
+ }
+
+ /// The weekdays' initials, starting on the calendar's first weekday.
+ private static func weekdaySymbols(_ calendar: Calendar) -> [String] {
+ let symbols = calendar.veryShortStandaloneWeekdaySymbols
+ let first = calendar.firstWeekday - 1
+ return Array(symbols[first...] + symbols[..<first])
+ }
+}
+
+/// One day of the calendar: a square shaded darker the more reports were
+/// filed, with the day's number when it isn't compact.
+private struct DayCell: View {
+ let day: Date
+ let count: Int
+ let isInPeriod: Bool
+ /// After today, which a compact grid leaves blank.
+ let isFuture: Bool
+ let compact: Bool
+
+ var body: some View {
+ let level = CalendarSummary.level(of: count)
+ RoundedRectangle(cornerRadius: compact ? 3 : 5)
+ .fill(isInPeriod ? CalendarShade.fill(level) : Color.clear)
+ .overlay {
+ if compact, !isInPeriod, !isFuture {
+ RoundedRectangle(cornerRadius: 3).strokeBorder(Theme.rule)
+ }
+ }
+ .frame(height: compact ? 16 : 36)
+ .overlay {
+ if !compact {
+ Text(day, format: .dateTime.day())
+ .font(.footnote.monospacedDigit())
+ .foregroundStyle(
+ !isInPeriod ? Theme.muted.opacity(0.5) : level >= 3 ? Theme.onAccent : Theme.ink)
+ }
+ }
+ .contentShape(.rect)
+ .accessibilityElement(children: .ignore)
+ .accessibilityLabel(Text(day, format: .dateTime.weekday(.wide).day().month(.wide).year()))
+ .accessibilityValue(isInPeriod ? Text("^[\(count) report](inflect: true)") : Text(""))
+ }
+}
+
+/// The shades of the calendar: the field colour for a day without a
+/// report, then the accent, deepening with the count.
+enum CalendarShade {
+ static func fill(_ level: Int) -> Color {
+ switch level {
+ case ...0: Theme.field
+ case 1: Theme.accent.opacity(0.3)
+ case 2: Theme.accent.opacity(0.55)
+ case 3: Theme.accent.opacity(0.8)
+ default: Theme.accent
+ }
+ }
+}
+
+/// What each shade stands for.
+private struct CalendarLegend: View {
+ private static let levels: [(level: Int, label: String)] = [
+ (0, "0"), (1, "1"), (2, "2–3"), (3, "4–5"), (4, "6+"),
+ ]
+
+ var body: some View {
+ HStack(spacing: Theme.itemGap) {
+ ForEach(Self.levels, id: \.level) { level, label in
+ HStack(spacing: 4) {
+ RoundedRectangle(cornerRadius: 3)
+ .fill(CalendarShade.fill(level))
+ .frame(width: 12, height: 12)
+ Text(label)
+ .monospacedDigit()
+ }
+ }
+ }
+ .font(.footnote)
+ .foregroundStyle(Theme.muted)
+ .accessibilityElement(children: .ignore)
+ .accessibilityLabel(Text("Darker days had more reports"))
+ }
+}
+
+/// Every month of the period, newest first, each day shaded by how many
+/// reports were filed. A day with reports opens them.
+struct ReportCalendarView: View {
+ let model: ChartsModel
+
+ @Environment(\.reportStore) private var store
+ @State private var day: Date?
+
+ var body: some View {
+ let summary = model.data.context.calendar
+ ScrollView {
+ LazyVStack(alignment: .leading, spacing: Theme.blockGap) {
+ VStack(alignment: .leading, spacing: Theme.itemGap) {
+ VStack(alignment: .leading, spacing: Theme.lineGap) {
+ Text("Calendar")
+ .font(Theme.serif(.title3, weight: .medium))
+ subtitle(for: summary)
+ .font(.footnote)
+ .foregroundStyle(Theme.muted)
+ }
+ CalendarLegend()
+ }
+ if let summary {
+ ForEach(Self.months(of: summary), id: \.self) { month in
+ VStack(alignment: .leading, spacing: Theme.itemGap) {
+ Text(month, format: .dateTime.month(.wide).year())
+ .eyebrow()
+ .accessibilityAddTraits(.isHeader)
+ MonthGrid(month: month, summary: summary) { day = $0 }
+ }
+ }
+ }
+ }
+ .padding(.horizontal, Theme.margin)
+ .padding(.vertical, Theme.itemGap)
+ }
+ .background(Theme.paper)
+ .foregroundStyle(Theme.ink)
+ .navigationBarTitleDisplayMode(.inline)
+ .navigationDestination(item: $day) { day in
+ DayReportsView(day: day)
+ }
+ // Back from a day, where reports may have been edited or deleted.
+ .onChange(of: day) { _, day in
+ guard day == nil else { return }
+ Task { await model.load(model.data.period, from: store) }
+ }
+ }
+
+ private func subtitle(for summary: CalendarSummary?) -> Text {
+ let period = model.data.period.title
+ guard let summary else { return Text(period) }
+ return Text(
+ "\(period) · ^[\(summary.reports) report](inflect: true) on \(summary.daysWithReports) of ^[\(summary.days) day](inflect: true)"
+ )
+ }
+
+ /// The start of each month the period touches, newest first.
+ private static func months(of summary: CalendarSummary) -> [Date] {
+ let calendar = Calendar.current
+ let first = calendar.start(of: .month, for: summary.first)
+ var month = calendar.start(of: .month, for: summary.last)
+ var months: [Date] = []
+ while month >= first {
+ months.append(month)
+ guard let earlier = calendar.date(byAdding: .month, value: -1, to: month) else { break }
+ month = earlier
+ }
+ return months
+ }
+}
+
+/// The reports filed on one day, as the timeline shows them, each opening
+/// in full.
+struct DayReportsView: View {
+ let day: Date
+
+ @Environment(\.reportStore) private var store
+ @State private var describer = ReportDescriber()
+ @State private var opened: ReportRoute?
+ @State private var survey: SurveyRequest?
+ @FetchRequest private var reports: FetchedResults<ReportEntity>
+
+ init(day: Date) {
+ self.day = day
+ let end = Calendar.current.date(byAdding: .day, value: 1, to: day) ?? day
+ let request = ReportEntity.fetchRequest()
+ request.predicate = NSPredicate(format: "date >= %@ AND date < %@", day as NSDate, end as NSDate)
+ request.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)]
+ request.relationshipKeyPathsForPrefetching = ["responses", "health"]
+ _reports = FetchRequest(fetchRequest: request)
+ }
+
+ var body: some View {
+ List {
+ Text(day, format: DayHeader.format(for: day))
+ .font(Theme.serif(.title3, weight: .medium))
+ .accessibilityAddTraits(.isHeader)
+ .settingsRow()
+ .listRowSeparator(.hidden)
+ ForEach(reports) { report in
+ row(for: report)
+ .listRowInsets(
+ EdgeInsets(
+ top: Theme.rowPadding, leading: Theme.margin, bottom: Theme.rowPadding,
+ trailing: Theme.margin)
+ )
+ .listRowBackground(Theme.paper)
+ .listRowSeparatorTint(Theme.rule)
+ }
+ if reports.isEmpty {
+ SettingsNote { Text("No reports were filed on this day.") }
+ }
+ }
+ .listStyle(.plain)
+ .scrollContentBackground(.hidden)
+ .background(Theme.paper)
+ .foregroundStyle(Theme.ink)
+ .navigationBarTitleDisplayMode(.inline)
+ .navigationDestination(item: $opened) { route in
+ ReportDetailView(id: route.id, describer: describer) { id, kind in
+ survey = .edit(id, kind: kind)
+ }
+ }
+ .sheet(item: $survey) { request in
+ SurveySheet(request: request)
+ }
+ .task { await describer.load(from: store) }
+ }
+
+ @ViewBuilder
+ private func row(for report: ReportEntity) -> some View {
+ if let id = report.id {
+ Button {
+ opened = ReportRoute(id: id)
+ } label: {
+ ReportRow(report: report, describer: describer)
+ .contentShape(.rect)
+ }
+ .buttonStyle(.plain)
+ .accessibilityHint(Text("Shows this report in full"))
+ } else {
+ ReportRow(report: report, describer: describer)
+ }
+ }
+}
diff --git a/Reportage/Views/Home/HomeView.swift b/Reportage/Views/Home/HomeView.swift
@@ -362,7 +362,7 @@ struct DayHeader: View {
extension DayHeader {
/// The year is only shown for days in another year.
- fileprivate static func format(for date: Date) -> Date.FormatStyle {
+ static func format(for date: Date) -> Date.FormatStyle {
let style = Date.FormatStyle().weekday(.wide).day().month(.wide)
let calendar = Calendar.current
return calendar.isDate(date, equalTo: Date(), toGranularity: .year) ? style : style.year()
diff --git a/Tests/Unit/AnswerSummaryTests.swift b/Tests/Unit/AnswerSummaryTests.swift
@@ -172,6 +172,28 @@ struct AnswerSummaryTests {
#expect(PlacesSummary.summarise([], lookup: lookup, tokenCoordinates: [:]) == nil)
}
+ @Test("The calendar counts reports by day from the first whole day through today")
+ func calendar() throws {
+ // 2001-09-09 01:46:40 UTC.
+ let now = Date(timeIntervalSince1970: 1_000_000_000)
+ let today = Self.gmt.startOfDay(for: now)
+ let day: TimeInterval = 86400
+ let dates = [
+ now, today.addingTimeInterval(60), today.addingTimeInterval(-60),
+ today.addingTimeInterval(-6 * day), today.addingTimeInterval(-7 * day),
+ ]
+ let summary = try #require(
+ CalendarSummary.summarise(dates, from: now.addingTimeInterval(-6 * day), through: now, calendar: Self.gmt))
+ #expect(summary.first == today.addingTimeInterval(-6 * day))
+ #expect(summary.last == today)
+ #expect(summary.days == 7)
+ #expect(summary.reports == 4)
+ #expect(summary.daysWithReports == 3)
+ #expect(summary.counts[today] == 2)
+ #expect(CalendarSummary.summarise([], from: now, through: now, calendar: Self.gmt) == nil)
+ #expect([0, 1, 2, 3, 4, 5, 6, 20].map(CalendarSummary.level(of:)) == [0, 1, 2, 2, 3, 3, 4, 4])
+ }
+
@Test("Periods end now and reach back a week, a month or a year")
func periods() {
var calendar = Calendar(identifier: .gregorian)
@@ -205,6 +227,8 @@ struct AnswerSummaryTests {
let now = Date(timeIntervalSince1970: 10 * 3600)
let data = try await store.chartData(for: .all, now: now, calendar: Self.gmt)
#expect(data.domain == Date(timeIntervalSince1970: 0)...now)
+ #expect(data.context.calendar?.reports == 3)
+ #expect(data.context.calendar?.days == 1)
#expect(data.summaries.isEmpty)
}
}