Commit bb078835d8

bb078835d89f772620a8fe5e0dc5c5ba3e78ab12

parent: 0a98939218

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-13 01:13 UTC

iOS: a time for schedule and deadline prompts

The editor's date prompt had a calendar but no time, and picking a day wrote
over a time typed into the field. It gets the capture sheet's Time switch and
picker. Switching a time on starts at the next whole hour instead of 00:00,
and the capture sheet keeps an existing time switched on.

Layout: unified · split

Sources/OrgstarMobile/CaptureScreen.swift +17 −2
@@ -271,6 +271,16 @@ struct QuestionField: View {
271271 if !tags.contains(choice) { answer = (tags + [choice]).joined(separator: ":") }
272272 }
273273
274 /// `date` at the next whole hour from now when it has no time of day yet, for a time
275 /// switched on; otherwise as it is.
276 static func timed(_ date: Date, now: Date = Date()) -> Date {
277 let calendar = Calendar.current
278 let parts = calendar.dateComponents([.hour, .minute], from: date)
279 guard parts.hour == 0, parts.minute == 0 else { return date }
280 let hour = min(calendar.component(.hour, from: now) + 1, 23)
281 return calendar.date(bySettingHour: hour, minute: 0, second: 0, of: date) ?? date
282 }
283
274284 static func stamp(_ date: Date, withTime: Bool) -> String {
275285 let formatter = DateFormatter()
276286 formatter.locale = Locale(identifier: "en_US_POSIX")
@@ -335,7 +345,7 @@ private struct EntryFields: View {
335345 }
336346
337347 static func initial(_ stamp: Timestamp?) -> Date {
338 guard let stamp else { return Date() }
348 guard let stamp else { return Calendar.current.startOfDay(for: Date()) }
339349 let point = stamp.start
340350 return Calendar.current.date(from: DateComponents(year: point.year, month: point.month, day: point.day, hour: point.hour, minute: point.minute)) ?? Date()
341351 }
@@ -363,6 +373,7 @@ private struct DateTimeSheet: View {
363373 Form {
364374 DatePicker(title, selection: $date, displayedComponents: .date).datePickerStyle(.graphical)
365375 Toggle("Time", isOn: $withTime)
376 .onChange(of: withTime) { if withTime { date = QuestionField.timed(date) } }
366377 if withTime { DatePicker("Time", selection: $date, displayedComponents: .hourAndMinute) }
367378 }
368379 .navigationTitle(title)
@@ -373,7 +384,11 @@ private struct DateTimeSheet: View {
373384 }
374385 }
375386 .presentationDetents([.large])
376 .onAppear { date = initial }
387 .onAppear {
388 date = initial
389 let parts = Calendar.current.dateComponents([.hour, .minute], from: initial)
390 withTime = parts.hour != 0 || parts.minute != 0
391 }
377392 }
378393}
379394
Sources/OrgstarMobile/EditorScreen.swift +9 −9
@@ -691,6 +691,7 @@ struct PromptSheet: View {
691691 let answer: (String?) -> Void
692692 @State private var text = ""
693693 @State private var date = Date()
694 @State private var withTime = false
694695 @State private var keys: [FastSelection.Input] = []
695696
696697 var body: some View {
@@ -710,7 +711,13 @@ struct PromptSheet: View {
710711 if prompt.date != nil {
711712 DatePicker("Date", selection: $date, displayedComponents: [.date])
712713 .datePickerStyle(.graphical)
713 .onChange(of: date) { text = Self.stamp(date) }
714 .onChange(of: date) { text = QuestionField.stamp(date, withTime: withTime) }
715 Toggle("Time", isOn: $withTime)
716 .onChange(of: withTime) {
717 if withTime { date = QuestionField.timed(date) }
718 text = QuestionField.stamp(date, withTime: withTime)
719 }
720 if withTime { DatePicker("Time", selection: $date, displayedComponents: .hourAndMinute) }
714721 }
715722 if !prompt.choices.isEmpty {
716723 let matching = prompt.choices.filter { lastPart.isEmpty || $0.localizedCaseInsensitiveContains(lastPart) }
@@ -736,7 +743,7 @@ struct PromptSheet: View {
736743 }
737744 .onAppear {
738745 text = prompt.initial
739 if let day = prompt.date?.defaultDate { date = day }
746 date = prompt.date?.defaultDate ?? Calendar.current.startOfDay(for: Date())
740747 }
741748 }
742749
@@ -781,13 +788,6 @@ struct PromptSheet: View {
781788 if fast.multiple, !fast.inherited.isEmpty { Text("Inherited: :" + fast.inherited.joined(separator: ":") + ":") }
782789 }
783790 }
784
785 static func stamp(_ date: Date) -> String {
786 let formatter = DateFormatter()
787 formatter.locale = Locale(identifier: "en_US_POSIX")
788 formatter.dateFormat = "yyyy-MM-dd"
789 return formatter.string(from: date)
790 }
791791}
792792
793793/// `org-edit-special` and `org-table-edit-field`: the text edited apart, put back with Save.