emacs-orgmode
[Top][All Lists]
Advanced

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

Diary sexp and comparing dates, agenda


From: David Rogers
Subject: Diary sexp and comparing dates, agenda
Date: Thu, 11 Jan 2024 21:58:05 -0800
User-agent: Gnus/5.13 (Gnus v5.13)

Hello all

I'm using the Org agenda to show when certain church occasions will happen. Mostly I've got them working correctly, after "stealing" the method used in holidays.el for finding the date of Easter, along with someone else's function that then uses that to find the difference between Easter and today. (I'm pretty sure that whole idea was on emacswiki, and I think Paul Sexton put it together.)

So now I have a much smaller problem to solve, but I don't understand how to get it to work; I suspect it has to do with how dates get formatted within different functions. Using what I already have, I can do this:

* 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".

I could do a long string of (and (not this day, not this day, etc etc [insert long list of days] . . . , but that seems like a last resort.

Everything in this question fits into "the current year according to the agenda view" - there's no need to consider dates that cross a year boundary.

So: Is there a fairly simple way to define a (mf-days-from-advent) that will do a similar job to what (mf-days-from-easter) is already doing (i.e. it works when used in a diary sexp)?


Here are the relevant definitions I've been using:


   (defun mf-easter (displayed-year)
       (let* ((century (1+ (/ displayed-year 100)))
(shifted-epact ; age of moon for April 5... (% (+ 14 (* 11 (% displayed-year 19)) ; ...by Nicaean rule (- ; ...corrected for the Gregorian century rule
                      (/ (* 3 century) 4))
(/ ; ...corrected for Metonic cycle inaccuracy
                      (+ 5 (* 8 century)) 25)
                     (* 30 century))       ; keeps value positive
                  30))
(adjusted-epact ; adjust for 29.5 day month
               (if (or (zerop shifted-epact)
(and (= shifted-epact 1) (< 10 (% displayed-year 19))))
                   (1+ shifted-epact)
                 shifted-epact))
(paschal-moon ; day after the full moon on or after March 21 (- (calendar-absolute-from-gregorian (list 4 19 displayed-year))
                  adjusted-epact)))
(calendar-dayname-on-or-before 0 (+ paschal-moon 7))))



   (defun mf-days-from-easter ()
"When used in a diary sexp, this function will calculate how many days
are between the current date (DATE) and Easter Sunday."
     (- (calendar-absolute-from-gregorian date)
        (mf-easter (calendar-extract-year date))))


--
David



reply via email to

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