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 {
271 if !tags.contains(choice) { answer = (tags + [choice]).joined(separator: ":") } 271 if !tags.contains(choice) { answer = (tags + [choice]).joined(separator: ":") }
272 } 272 }
273 273
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
274 static func stamp(_ date: Date, withTime: Bool) -> String { 284 static func stamp(_ date: Date, withTime: Bool) -> String {
275 let formatter = DateFormatter() 285 let formatter = DateFormatter()
276 formatter.locale = Locale(identifier: "en_US_POSIX") 286 formatter.locale = Locale(identifier: "en_US_POSIX")
@@ -335,7 +345,7 @@ private struct EntryFields: View {
335 } 345 }
336 346
337 static func initial(_ stamp: Timestamp?) -> Date { 347 static func initial(_ stamp: Timestamp?) -> Date {
338 guard let stamp else { return Date() } 348 guard let stamp else { return Calendar.current.startOfDay(for: Date()) }
339 let point = stamp.start 349 let point = stamp.start
340 return Calendar.current.date(from: DateComponents(year: point.year, month: point.month, day: point.day, hour: point.hour, minute: point.minute)) ?? Date() 350 return Calendar.current.date(from: DateComponents(year: point.year, month: point.month, day: point.day, hour: point.hour, minute: point.minute)) ?? Date()
341 } 351 }
@@ -363,6 +373,7 @@ private struct DateTimeSheet: View {
363 Form { 373 Form {
364 DatePicker(title, selection: $date, displayedComponents: .date).datePickerStyle(.graphical) 374 DatePicker(title, selection: $date, displayedComponents: .date).datePickerStyle(.graphical)
365 Toggle("Time", isOn: $withTime) 375 Toggle("Time", isOn: $withTime)
376 .onChange(of: withTime) { if withTime { date = QuestionField.timed(date) } }
366 if withTime { DatePicker("Time", selection: $date, displayedComponents: .hourAndMinute) } 377 if withTime { DatePicker("Time", selection: $date, displayedComponents: .hourAndMinute) }
367 } 378 }
368 .navigationTitle(title) 379 .navigationTitle(title)
@@ -373,7 +384,11 @@ private struct DateTimeSheet: View {
373 } 384 }
374 } 385 }
375 .presentationDetents([.large]) 386 .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 }
377 } 392 }
378} 393}
379 394
Sources/OrgstarMobile/EditorScreen.swift +9 −9
@@ -691,6 +691,7 @@ struct PromptSheet: View {
691 let answer: (String?) -> Void 691 let answer: (String?) -> Void
692 @State private var text = "" 692 @State private var text = ""
693 @State private var date = Date() 693 @State private var date = Date()
694 @State private var withTime = false
694 @State private var keys: [FastSelection.Input] = [] 695 @State private var keys: [FastSelection.Input] = []
695 696
696 var body: some View { 697 var body: some View {
@@ -710,7 +711,13 @@ struct PromptSheet: View {
710 if prompt.date != nil { 711 if prompt.date != nil {
711 DatePicker("Date", selection: $date, displayedComponents: [.date]) 712 DatePicker("Date", selection: $date, displayedComponents: [.date])
712 .datePickerStyle(.graphical) 713 .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) }
714 } 721 }
715 if !prompt.choices.isEmpty { 722 if !prompt.choices.isEmpty {
716 let matching = prompt.choices.filter { lastPart.isEmpty || $0.localizedCaseInsensitiveContains(lastPart) } 723 let matching = prompt.choices.filter { lastPart.isEmpty || $0.localizedCaseInsensitiveContains(lastPart) }
@@ -736,7 +743,7 @@ struct PromptSheet: View {
736 } 743 }
737 .onAppear { 744 .onAppear {
738 text = prompt.initial 745 text = prompt.initial
739 if let day = prompt.date?.defaultDate { date = day } 746 date = prompt.date?.defaultDate ?? Calendar.current.startOfDay(for: Date())
740 } 747 }
741 } 748 }
742 749
@@ -781,13 +788,6 @@ struct PromptSheet: View {
781 if fast.multiple, !fast.inherited.isEmpty { Text("Inherited: :" + fast.inherited.joined(separator: ":") + ":") } 788 if fast.multiple, !fast.inherited.isEmpty { Text("Inherited: :" + fast.inherited.joined(separator: ":") + ":") }
782 } 789 }
783 } 790 }
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 }
791} 791}
792 792
793/// `org-edit-special` and `org-table-edit-field`: the text edited apart, put back with Save. 793/// `org-edit-special` and `org-table-edit-field`: the text edited apart, put back with Save.