Sources/OrgApp/WatchPayload.swift
27 lines · 1448 bytes
1import Foundation
2import OrgPresentation
3import OrgWatchData
4
5extension WatchAgenda {
6 /// Today's group of the agenda, for the watch, with the running clock and the entry
7 /// Clock In Last would take.
8 public init(groups: [AgendaDayGroup], today: Int, clock: ClockModel.Running?, lastClocked: String?, generated: Date, calendar: Calendar = .current) {
9 let group = groups.first { $0.day == today }
10 let midnight = group?.date(calendar: calendar) ?? calendar.startOfDay(for: generated)
11 func entry(_ row: AgendaRow) -> Entry {
12 func at(_ hhmm: Int?) -> Date? {
13 hhmm.flatMap { calendar.date(byAdding: .minute, value: ($0 / 100) * 60 + $0 % 100, to: midnight) }
14 }
15 let item = row.item
16 return Entry(
17 id: row.id, title: row.title, gutter: row.gutter, category: row.category, todo: row.todo, status: row.status.rawValue,
18 isDone: row.isDone, isEvent: row.isEvent, start: at(row.start), end: at(row.end), path: item?.path,
19 offset: item?.headingOffset, headingLine: item?.headingLine, doneKeyword: item?.doneKeyword
20 )
21 }
22 self.init(
23 generated: generated, day: midnight, overdue: group?.overdue.map(entry) ?? [], rows: group?.rows.map(entry) ?? [],
24 clock: clock.map { Clock(heading: $0.heading, startedAt: $0.startedAt) }, lastClocked: lastClocked
25 )
26 }
27}