Commit 173b70c8c8

173b70c8c8b365f7ecea07fd246988a8d37964ac

parent: 8a7d6e3547

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-14 03:45 UTC

Date prompt reads today, tomorrow, yesterday, next week and last week

Org's prompt ignores words it doesn't know, so "tomorrow" gave the default
date. ReadDate.read rewrites these five words to Org's relative forms (+0,
+1, -1, +1w, -1w) before analysis, so a time after them still counts and
the analyzer itself stays what org-read-date-analyze does. Listed as an
orgstar addition in chapters 6 and 15.

Closes #73

Layout: unified · split

Sources/OrgCore/Time/ReadDate.swift +16 −1
@@ -165,10 +165,25 @@ public enum ReadDate {
165165 return (n * (direction == "-" ? -1 : 1), what, relativeToDefault, match)
166166 }
167167
168 /// Words orgstar reads that Org's prompt ignores, and the relative forms they stand for.
169 /// Rewritten before analysis, so a time after them still counts (`tomorrow 14:00`).
170 static let words: [(String, String)] = [
171 ("next week", "+1w"), ("last week", "-1w"), ("today", "+0"), ("tomorrow", "+1"), ("yesterday", "-1"),
172 ]
173
174 static func expandWords(_ input: String) -> String {
175 let trimmed = input.trimmingCharacters(in: .whitespaces)
176 let lower = trimmed.lowercased()
177 for (word, form) in words where lower == word || lower.hasPrefix(word + " ") {
178 return form + trimmed.dropFirst(word.count)
179 }
180 return input
181 }
182
168183 /// `org-read-date`'s reading of a prompt answer: an empty one takes the default date.
169184 public static func read(_ answer: String, default defaultDate: Date?, now: Date, calendar: Calendar) -> Answer {
170185 let def = defaultDate ?? now
171 var input = answer
186 var input = expandWords(answer)
172187 if input.trimmingCharacters(in: .whitespaces).isEmpty {
173188 let c = calendar.dateComponents([.year, .month, .day], from: def)
174189 input = String(format: "%04d-%02d-%02d", c.year!, c.month!, c.day!)
Tests/OrgCoreTests/ReadDateTests.swift +13
@@ -48,6 +48,19 @@ struct ReadDateTests {
4848 "w42", "2027-w01", "w3-5", "tomorrow", "nonsense",
4949 ]
5050
51 /// orgstar reads these words; Org's prompt ignores them. `analyze` stays Org's.
52 @Test func wordsBeforeAnalysis() {
53 func read(_ s: String) -> String { Self.format(ReadDate.read(s, default: nil, now: Self.now, calendar: Self.utc)) }
54 #expect(read("today") == "2026-09-10|nil")
55 #expect(read("tomorrow") == "2026-09-11|nil")
56 #expect(read("Yesterday") == "2026-09-09|nil")
57 #expect(read("next week") == "2026-09-17|nil")
58 #expect(read("last week") == "2026-09-03|nil")
59 #expect(read("tomorrow 14:00") == "2026-09-11 14:00|nil")
60 #expect(read("todays") == "2026-09-10|nil")
61 #expect(Self.format(ReadDate.analyze("tomorrow", default: Self.now, now: Self.now, calendar: Self.utc)) == "2026-09-10|nil")
62 }
63
5164 @Test func examples() {
5265 let answer = ReadDate.analyze("fri 10:00", default: Self.now, now: Self.now, calendar: Self.utc)
5366 #expect(Self.format(answer) == "2026-09-11 10:00|nil")
docs/manual/guide/06-dates-and-clocking.org +3 −1
@@ -82,6 +82,8 @@ orgstar reads the answer as Org 9.8 does, with =org-read-date-prefer-future= =t=
8282| =+fri= | The next Friday after today |
8383| =-fri= | The last Friday before today |
8484| =+2fri= | The second Friday from today |
85| =today=, =tomorrow=, =yesterday= | Those days. orgstar's additions; Org's prompt ignores them |
86| =next week=, =last week= | Seven days from today, forward or back. orgstar's additions |
8587| =2026-10-07=, =2026-10-7= | That date |
8688| =10-7= | 7 October, the next one |
8789| =7.10.=, =7.10.2027= | 7 October (day first) |
@@ -97,7 +99,7 @@ orgstar reads the answer as Org 9.8 does, with =org-read-date-prefer-future= =t=
9799| =10:00+1:30= | 10:00-11:30 |
98100| =fri 10:00=, =+2d 9:00= | A date and a time together |
99101
100Forms without a sign, such as =fri=, =15= or =10:00=, fill in what is missing from the default date: the date of the timestamp being changed, or today. Forms with a single sign count from today; =++= counts from the default date. Two-digit years are read relative to the current year. Words the prompt does not recognize are ignored, so =tomorrow= gives the default date.
102Forms without a sign, such as =fri=, =15= or =10:00=, fill in what is missing from the default date: the date of the timestamp being changed, or today. Forms with a single sign count from today; =++= counts from the default date. Two-digit years are read relative to the current year. Other words the prompt does not recognize are ignored and give the default date. =today=, =tomorrow=, =yesterday=, =next week= and =last week= are orgstar's additions, read before the rest of the answer; Org's prompt ignores them.
101103
102104* Changing dates
103105
docs/manual/guide/15-alongside-emacs.org +1
@@ -239,6 +239,7 @@ Tables and dynamic blocks (see [[file:10-tables.org][Tables]] and [[file:06-date
239239Other:
240240
241241- =C-c C-q= before the first heading (setting file tags) isn't supported.
242- The date prompt also reads =today=, =tomorrow=, =yesterday=, =next week= and =last week=, which Org's prompt ignores.
242243- Priority ranges that aren't letters or numbers are refused.
243244- =#+SETUPFILE= URLs aren't fetched.
244245- Most =#+STARTUP= options for footnotes, entities, numbering and odd levels are accepted and ignored; see [[file:13-configuration.org][Configuration]].