Skip to content

Commit

Permalink
Add diary-offset to diary-lib.el
Browse files Browse the repository at this point in the history
* doc/emacs/calendar.texi: Document the change.
* lisp/calendar/diary-lib.el (diary-offset):
* test/lisp/calendar/icalendar-tests.el: Add a test (bug#50195).
  • Loading branch information
ycpei authored and larsmagne committed Sep 4, 2021
1 parent f9dcde3 commit ca7e76c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions doc/emacs/calendar.texi
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,20 @@ the 11 above to @samp{'(1 2 3)} and have the entry apply to the last
Thursday of January, February, and March. If the month is @code{t}, the
entry applies to all months of the year.

@findex diary-offset
@example
%%(diary-offset '(diary-float t 3 4) 2) Monthly committee meeting
@end example

@noindent
This entry applies to the Saturday after the third Thursday of each
month. The 2 specifies number of days after when the sexp
@w{@code{'(diary-float t 3 4)}} would evaluate to @code{t}. This is
useful when for example your organization has a committee meeting two
days after every monthly meeting which takes place on the third
Thursday, or if you would like to attend a virtual meeting scheduled
in a different timezone causing a difference in the date.

Each of the standard sexp diary entries takes an optional parameter
specifying the name of a face or a single-character string to use when
marking the entry in the calendar. Most generally, sexp diary entries
Expand Down
8 changes: 8 additions & 0 deletions etc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2814,6 +2814,14 @@ never be narrower than 19 characters.
'gomoku-move-sw' and 'gomoku-move-ne' now work correctly, and
horizontal movements now stop at the edge of the board.

+++
*** New diary sexp 'diary-offset'.
It offsets another diary sexp by a number of days. This is useful
when for example your organization has a committee meeting two days
after every monthly meeting which takes place on the third Thursday,
or if you would like to attend a virtual meeting scheduled in a
different timezone causing a difference in the date.

** xterm-mouse mode

---
Expand Down
11 changes: 11 additions & 0 deletions lisp/calendar/diary-lib.el
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,17 @@ string to use when highlighting the day in the calendar."
(and (>= diff 0) (zerop (% diff n))
(cons mark (format entry cycle (diary-ordinal-suffix cycle))))))

;; To be called from diary-sexp-entry, where DATE, ENTRY are bound.
(defun diary-offset (sexp days)
"Offsetted diary entry. Offsets SEXP by DAYS days.
Entry applies if the date is DAYS days after another diary-sexp SEXP."
(with-no-warnings (defvar date))
(unless (integerp days)
(user-error "Days must be an integer"))
(let ((date (calendar-gregorian-from-absolute
(- (calendar-absolute-from-gregorian date) days))))
(eval sexp)))

(defun diary-day-of-year ()
"Day of year and number of days remaining in the year of date diary entry."
(with-no-warnings (defvar date))
Expand Down
7 changes: 7 additions & 0 deletions test/lisp/calendar/icalendar-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,13 @@ RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=09;BYMONTHDAY=21
SUMMARY:ff birthday (%d years old)")


(icalendar-tests--test-export
nil
nil
"%%(diary-offset '(diary-float t 3 4) 1) asdf"
nil)


;; FIXME!

;; export 2004-10-28 monthly, weekly entries
Expand Down

0 comments on commit ca7e76c

Please sign in to comment.