emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Testing if a scheduled date is prior to another date
@ 2021-08-22 13:26 Tim Landscheidt
  2021-08-30 14:59 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Tim Landscheidt @ 2021-08-22 13:26 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

in a capture template, I want to test whether the scheduled
date for a specific task is prior to another, calculated
date (and depending on the answer, insert a checkbox or
not).

I can get the scheduled date for the task by:

| (with-current-buffer (find-file-noselect "/path/to/file.org")
|   (save-mark-and-excursion
|     (goto-char
|      (org-find-entry-with-id "TASK_ID"))
|     (org-element-property ':scheduled (org-element-at-point))))

which returns a structure like:

| (timestamp
|  (:type active
|   :raw-value "<2021-08-30 Mo 08:00 .+4d>"
|   :year-start 2021
|   :month-start 8
|   :day-start 30
|   :hour-start 8
|   :minute-start 0
|   :year-end 2021
|   :month-end 8
|   :day-end 30
|   :hour-end 8
|   :minute-end 0
|   :begin 436166
|   :end 436192
|   :post-blank 0
|   :repeater-type restart
|   :repeater-value 4
|   :repeater-unit day))

However, comparing this value with org-time< & Co. is futile
as org-2ft always returns 0.

Before I wade through the various functions to build a con-
version chain, what is the best practice to compare time-
stamp values with dates?  (And if there is an org-mode func-
tion that checks if the task at point is scheduled prior to
another date, I'd appreciate pointers as well :-).)

TIA,
Tim



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Testing if a scheduled date is prior to another date
  2021-08-22 13:26 Testing if a scheduled date is prior to another date Tim Landscheidt
@ 2021-08-30 14:59 ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2021-08-30 14:59 UTC (permalink / raw)
  To: Tim Landscheidt; +Cc: emacs-orgmode

Tim Landscheidt <tim@tim-landscheidt.de> writes:

> Before I wade through the various functions to build a con-
> version chain, what is the best practice to compare time-
> stamp values with dates?  (And if there is an org-mode func-
> tion that checks if the task at point is scheduled prior to
> another date, I'd appreciate pointers as well :-).)

You can try org-parse-time-string + org-element-timestamp-interpreter
from org.

Alternatively, you can use external 'ts library: ts-parse-org-element

Best,
Ihor


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-30 14:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-22 13:26 Testing if a scheduled date is prior to another date Tim Landscheidt
2021-08-30 14:59 ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).