emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Diary sexp and comparing dates, agenda


From: Ihor Radchenko
Subject: Re: Diary sexp and comparing dates, agenda
Date: Fri, 12 Jan 2024 23:00:33 +0000

David Rogers <davidandrewrogers@gmail.com> writes:

> * Example 1
> <%%(= 245 (mf-days-from-easter))>
>
> because "mf-days-from-easter" is defined in my init file, along 
> with the definition of Easter itself. This does what it looks like 
> it should do; this year, Example 1 is shown on December 1.
>
> And I can do
>
> * Example 2
> <%%(and (diary-float 1 0 5 7) (<= (mf-days-from-easter) -56))>
>
> to say "five Sundays after January 6th, but only if Easter is 
> still 8 weeks away or more".
>
> But Example 1 isn't quite finished, because that date is too close 
> to Christmas. I can easily show a diary sexp defining when "too 
> close to Christmas" is:
>
> <%%(diary-float 12 0 -4 24)>
>
> So I want to combine these ideas, to say "Show Example 1 in the 
> agenda 245 days after Easter each year, but only if it's earlier 
> than the fourth Sunday before Christmas".

You don't need diary-float - it returns true/false whether current DATE
fits the arguments.

Instead, you can make use of `calendar-nth-named-absday'.
For example,

<%%(and (= 245 (mf-days-from-easter))
        (< (calendar-absolute-from-gregorian date)
           (calendar-nth-named-absday -4 0 12 24)))>

Diary sexps are nothing but ordinary Elisp, with an extra twist that
during evaluation `date' variable is bound to current calendar date.
When they return nil, DATE does not match.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]