diff options
| author | Craig Jennings <c@cjennings.net> | 2025-10-25 20:42:21 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-10-25 20:42:21 -0500 |
| commit | 4f8ee4eb200922df24388afb0efafec90987a761 (patch) | |
| tree | 0951e287638156cbe368fa60662499b69a444ca0 /chime.el | |
| parent | 33fd717a31ea6bbc7b544923ba9dc6d756b152af (diff) | |
feat:chime: Enhance timestamp extraction in `chime--extract-time`
Expand `chime--extract-time` to handle plain timestamps alongside
scheduled and deadline timestamps. This enhancement includes parsing
timestamps from entry bodies, while avoiding duplicates from
planning lines. Updated and expanded unit tests to cover new
behaviors, including repeating timestamps and org-gcal integration,
ensuring robustness across different timestamp scenarios.
Diffstat (limited to 'chime.el')
| -rw-r--r-- | chime.el | 41 |
1 files changed, 34 insertions, 7 deletions
@@ -604,15 +604,42 @@ Returns nil if parsing fails or timestamp is malformed." (defun chime--extract-time (marker) "Extract timestamps from MARKER. +Extracts SCHEDULED and DEADLINE from properties, plus any plain +timestamps found in the entry body. Timestamps are extracted as cons cells. car holds org-formatted string, cdr holds time in list-of-integer format." - (-non-nil - (--map - (let ((org-timestamp (org-entry-get marker it))) - (and org-timestamp - (cons org-timestamp - (chime--timestamp-parse org-timestamp)))) - '("DEADLINE" "SCHEDULED" "TIMESTAMP")))) + (let ((property-timestamps + ;; Extract SCHEDULED and DEADLINE from properties + (-non-nil + (--map + (let ((org-timestamp (org-entry-get marker it))) + (and org-timestamp + (cons org-timestamp + (chime--timestamp-parse org-timestamp)))) + '("DEADLINE" "SCHEDULED")))) + (plain-timestamps + ;; Extract plain timestamps from entry body + ;; Skip planning lines (SCHEDULED, DEADLINE, CLOSED) to avoid duplicates + (org-with-point-at marker + (let ((timestamps nil)) + (save-excursion + ;; Skip heading and planning lines, but NOT other drawers (nil arg) + ;; This allows extraction from :org-gcal: and similar drawers + (org-end-of-meta-data nil) + (let ((start (point)) + (end (save-excursion (org-end-of-subtree t) (point)))) + ;; Only search if there's content after metadata + (when (< start end) + (goto-char start) + ;; Search for timestamps until end of entry + (while (re-search-forward org-ts-regexp end t) + (let ((timestamp-str (match-string 0))) + (push (cons timestamp-str + (chime--timestamp-parse timestamp-str)) + timestamps)))))) + (nreverse timestamps))))) + ;; Combine property and plain timestamps, removing duplicates and nils + (-non-nil (append property-timestamps plain-timestamps)))) (defun chime--extract-title (marker) "Extract event title from MARKER. |
