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 {
165 return (n * (direction == "-" ? -1 : 1), what, relativeToDefault, match) 165 return (n * (direction == "-" ? -1 : 1), what, relativeToDefault, match)
166 } 166 }
167 167
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
168 /// `org-read-date`'s reading of a prompt answer: an empty one takes the default date. 183 /// `org-read-date`'s reading of a prompt answer: an empty one takes the default date.
169 public static func read(_ answer: String, default defaultDate: Date?, now: Date, calendar: Calendar) -> Answer { 184 public static func read(_ answer: String, default defaultDate: Date?, now: Date, calendar: Calendar) -> Answer {
170 let def = defaultDate ?? now 185 let def = defaultDate ?? now
171 var input = answer 186 var input = expandWords(answer)
172 if input.trimmingCharacters(in: .whitespaces).isEmpty { 187 if input.trimmingCharacters(in: .whitespaces).isEmpty {
173 let c = calendar.dateComponents([.year, .month, .day], from: def) 188 let c = calendar.dateComponents([.year, .month, .day], from: def)
174 input = String(format: "%04d-%02d-%02d", c.year!, c.month!, c.day!) 189 input = String(format: "%04d-%02d-%02d", c.year!, c.month!, c.day!)
Tests/OrgCoreTests/ReadDateTests.swift +13
@@ -48,6 +48,19 @@ struct ReadDateTests {
48 "w42", "2027-w01", "w3-5", "tomorrow", "nonsense", 48 "w42", "2027-w01", "w3-5", "tomorrow", "nonsense",
49 ] 49 ]
50 50
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
51 @Test func examples() { 64 @Test func examples() {
52 let answer = ReadDate.analyze("fri 10:00", default: Self.now, now: Self.now, calendar: Self.utc) 65 let answer = ReadDate.analyze("fri 10:00", default: Self.now, now: Self.now, calendar: Self.utc)
53 #expect(Self.format(answer) == "2026-09-11 10:00|nil") 66 #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=
82| =+fri= | The next Friday after today | 82| =+fri= | The next Friday after today |
83| =-fri= | The last Friday before today | 83| =-fri= | The last Friday before today |
84| =+2fri= | The second Friday from today | 84| =+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 |
85| =2026-10-07=, =2026-10-7= | That date | 87| =2026-10-07=, =2026-10-7= | That date |
86| =10-7= | 7 October, the next one | 88| =10-7= | 7 October, the next one |
87| =7.10.=, =7.10.2027= | 7 October (day first) | 89| =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=
97| =10:00+1:30= | 10:00-11:30 | 99| =10:00+1:30= | 10:00-11:30 |
98| =fri 10:00=, =+2d 9:00= | A date and a time together | 100| =fri 10:00=, =+2d 9:00= | A date and a time together |
99 101
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.
101 103
102* Changing dates 104* Changing dates
103 105
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
239Other: 239Other:
240 240
241- =C-c C-q= before the first heading (setting file tags) isn't supported. 241- =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.
242- Priority ranges that aren't letters or numbers are refused. 243- Priority ranges that aren't letters or numbers are refused.
243- =#+SETUPFILE= URLs aren't fetched. 244- =#+SETUPFILE= URLs aren't fetched.
244- Most =#+STARTUP= options for footnotes, entities, numbering and odd levels are accepted and ignored; see [[file:13-configuration.org][Configuration]]. 245- Most =#+STARTUP= options for footnotes, entities, numbering and odd levels are accepted and ignored; see [[file:13-configuration.org][Configuration]].