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: Ken Mankoff
Subject: Re: Diary sexp and comparing dates, agenda
Date: Fri, 12 Jan 2024 10:11:56 -0800
User-agent: mu4e 1.8.15; emacs 28.1

Hi David,

I'm not sure if this will help, but I have to file time sheets on the last 
weekday less than or equal to the 15th and last-day-of-month.

I wrote two diary functions to achieve this (I don't handle holiday edge 
cases). I use these functions with:

** INFO [#A] Time Sheet
<%%(kdm/diary-last-weekday-of-month date)>
<%%(kdm/diary-last-weekday-15th date)>

Functions are:

(defun kdm/diary-last-weekday-15th (date)
  (let* (
         (dow (calendar-day-of-week date))
         (dom (calendar-extract-day date))
         (weekday (and (>= dow 1) (<= dow 5))))
    (or 
     (and weekday (= dom 15))
     (and (= dow 5) (= dom 14))
     (and (= dow 5) (= dom 13)))))

(defun kdm/diary-last-weekday-of-month (date)
  (let* (
         (dow (calendar-day-of-week date))
         (dom (calendar-extract-day date))
         (month (calendar-extract-month date))
         (year (calendar-extract-year date))
         (ldom-num (calendar-last-day-of-month month year))
         (weekday (and (>= dow 1) (<= dow 5))))
    (or 
     (and weekday (= dom ldom-num))
     (and (= dow 5) (= (+ 1 dom) ldom-num))
     (and (= dow 5) (= (+ 2 dom) ldom-num)))))

  -k.

On 2024-01-11 at 21:58 -08, David Rogers <davidandrewrogers@gmail.com>
wrote...
> 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))))




reply via email to

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