emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: David Rogers <davidandrewrogers@gmail.com>
Cc: Org-mode list <emacs-orgmode@gnu.org>
Subject: Re: Diary sexp and comparing dates, agenda
Date: Fri, 12 Jan 2024 23:00:33 +0000	[thread overview]
Message-ID: <87jzoenomm.fsf@localhost> (raw)
In-Reply-To: <rzhwmsfhz4i.fsf@gmail.com>

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>


  parent reply	other threads:[~2024-01-12 22:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-12  5:58 Diary sexp and comparing dates, agenda David Rogers
2024-01-12 17:01 ` Tory S. Anderson
2024-01-12 18:11 ` Ken Mankoff
2024-01-12 23:00 ` Ihor Radchenko [this message]
2024-01-13  5:41   ` David Rogers
2024-01-13 20:05     ` Ihor Radchenko
2024-01-13 23:44       ` David Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87jzoenomm.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=davidandrewrogers@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).