Commit 3f9cb33052
3f9cb330527c344316081db3269dfc33aed649b7
parent: 82594f0cde
Verified · cmc
cmc <hello@cleberg.net> · 2026-10-08 03:53 UTC
Describe the clock report neutrally and title its column Heading
The middle column holds heading titles.
Layout: unified · split
Sources/OrgCore/Commands/ClockReport.swift
+3 −4
| @@ -70,9 +70,8 @@ public enum ClockReport { |
| 70 | return String(format: "%04d-W%02d", Days.date(thursday).year, Days.isoWeek(day)) |
70 | return String(format: "%04d-W%02d", Days.date(thursday).year, Days.isoWeek(day)) |
| 71 | } |
71 | } |
| 72 | |
72 | |
| 73 | /// The time report your Doom configuration writes (`tr/generate-report`): minutes per |
73 | /// An Org table of clocked time per date and heading between `start` and `end` |
| 74 | /// date and heading between `start` and `end` (inclusive, `YYYY-MM-DD`), with a total |
74 | /// (inclusive, `YYYY-MM-DD`), with a total after each ISO week. |
| 75 | /// after each ISO week. |
| |
| 76 | public static func timeReport(_ entries: [Entry], start: String? = nil, end: String? = nil) -> String { |
75 | public static func timeReport(_ entries: [Entry], start: String? = nil, end: String? = nil) -> String { |
| 77 | var totals: [String: [String: Int]] = [:] |
76 | var totals: [String: [String: Int]] = [:] |
| 78 | for entry in entries { |
77 | for entry in entries { |
| @@ -90,7 +89,7 @@ public enum ClockReport { |
| 90 | let dashes7 = String(repeating: "-", count: 7) |
89 | let dashes7 = String(repeating: "-", count: 7) |
| 91 | let rule: String = "|" + dashes14 + "+" + dashes47 + "+" + dashes7 + "|\n" |
90 | let rule: String = "|" + dashes14 + "+" + dashes47 + "+" + dashes7 + "|\n" |
| 92 | func row(_ a: String, _ b: String, _ c: String) -> String { "| \(pad(a, 12)) | \(pad(b, 45)) | \(padLeft(c, 5)) |\n" } |
91 | func row(_ a: String, _ b: String, _ c: String) -> String { "| \(pad(a, 12)) | \(pad(b, 45)) | \(padLeft(c, 5)) |\n" } |
| 93 | var out = "#+title: Time Report\n\n" + row("Date", "Code", "Hours") + rule |
92 | var out = "#+title: Time Report\n\n" + row("Date", "Heading", "Hours") + rule |
| 94 | var currentWeek: String? |
93 | var currentWeek: String? |
| 95 | var weekMinutes = 0 |
94 | var weekMinutes = 0 |
| 96 | for (date, heading) in keys { |
95 | for (date, heading) in keys { |
Sources/Orgstar/ClockViews.swift
+1 −2
| @@ -62,8 +62,7 @@ final class ClockStatusItem: NSObject { |
| 62 | } |
62 | } |
| 63 | } |
63 | } |
| 64 | |
64 | |
| 65 | /// Time per day and heading, as your `tr/generate-report` writes it, for chosen files and |
65 | /// Clocked time per day and heading (`ClockReport.timeReport`) for chosen files and dates. |
| 66 | /// dates. |
| |
| 67 | struct ClockReportView: View { |
66 | struct ClockReportView: View { |
| 68 | let workspace: WorkspaceModel |
67 | let workspace: WorkspaceModel |
| 69 | @State private var start = Calendar.current.date(byAdding: .day, value: -6, to: Date()) ?? Date() |
68 | @State private var start = Calendar.current.date(byAdding: .day, value: -6, to: Date()) ?? Date() |
Tests/OrgCoreTests/ClockTests.swift
+2
| @@ -133,7 +133,9 @@ struct ClockReportTests { |
| 133 | for text in texts { |
133 | for text in texts { |
| 134 | for (start, end) in [(nil, nil), ("2026-02-18", nil), (nil, "2026-02-20"), ("2026-02-17", "2026-02-17")] as [(String?, String?)] { |
134 | for (start, end) in [(nil, nil), ("2026-02-18", nil), (nil, "2026-02-20"), ("2026-02-17", "2026-02-17")] as [(String?, String?)] { |
| 135 | let ours = ClockReport.timeReport(ClockReport.entries(text), start: start, end: end) |
135 | let ours = ClockReport.timeReport(ClockReport.entries(text), start: start, end: end) |
| |
136 | // The config titles the heading column "Code". |
| 136 | let theirs = try Self.emacsReport(text, start: start, end: end) |
137 | let theirs = try Self.emacsReport(text, start: start, end: end) |
| |
138 | .replacingOccurrences(of: "| Code |", with: "| Heading |") |
| 137 | #expect(ours == theirs, "\(start ?? "-")..\(end ?? "-")\nours:\n\(ours)\ntheirs:\n\(theirs)") |
139 | #expect(ours == theirs, "\(start ?? "-")..\(end ?? "-")\nours:\n\(ours)\ntheirs:\n\(theirs)") |
| 138 | } |
140 | } |
| 139 | } |
141 | } |