1 ;;; holidays.el --- holiday functions for the calendar package
3 ;; Copyright (C) 1989, 1990, 1992, 1993, 1994 Free Software Foundation, Inc.
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
6 ;; Keywords: holidays, calendar
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This collection of functions implements the holiday features as described
30 ;; Comments, corrections, and improvements should be sent to
31 ;; Edward M. Reingold Department of Computer Science
32 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
33 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
34 ;; Urbana, Illinois 61801
36 ;; Technical details of all the calendrical calculations can be found in
37 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
38 ;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
39 ;; pages 899-928. ``Calendrical Calculations, Part II: Three Historical
40 ;; Calendars'' by E. M. Reingold, N. Dershowitz, and S. M. Clamen,
41 ;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993),
44 ;; Hard copies of these two papers can be obtained by sending email to
45 ;; reingold@cs.uiuc.edu with the SUBJECT "send-paper-cal" (no quotes) and
46 ;; the message BODY containing your mailing address (snail).
52 (autoload 'holiday-julian
"cal-julian"
53 "Holiday on MONTH, DAY (Julian) called STRING."
56 (autoload 'holiday-hebrew
"cal-hebrew"
57 "Holiday on MONTH, DAY (Hebrew) called STRING."
60 (autoload 'holiday-rosh-hashanah-etc
"cal-hebrew"
61 "List of dates related to Rosh Hashanah, as visible in calendar window."
64 (autoload 'holiday-hanukkah
"cal-hebrew"
65 "List of dates related to Hanukkah, as visible in calendar window."
68 (autoload 'holiday-passover-etc
"cal-hebrew"
69 "List of dates related to Passover, as visible in calendar window."
72 (autoload 'holiday-tisha-b-av-etc
"cal-hebrew"
73 "List of dates around Tisha B'Av, as visible in calendar window."
76 (autoload 'holiday-islamic
"cal-islam"
77 "Holiday on MONTH, DAY (Islamic) called STRING."
80 (autoload 'holiday-chinese-new-year
"cal-china"
81 "Date of Chinese New Year."
84 (autoload 'solar-equinoxes-solstices
"solar"
85 "Date and time of equinoxes and solstices, if visible in the calendar window.
86 Requires floating point."
89 (defun holidays (&optional arg
)
90 "Display the holidays for last month, this month, and next month.
91 If called with an optional prefix argument, prompts for month and year.
93 This function is suitable for execution in a .emacs file."
96 (let* ((completion-ignore-case t
)
98 (calendar-read-date t
)
99 (calendar-current-date)))
100 (displayed-month (extract-calendar-month date
))
101 (displayed-year (extract-calendar-year date
)))
102 (list-calendar-holidays))))
104 (defun check-calendar-holidays (date)
105 "Check the list of holidays for any that occur on DATE.
106 The value returned is a list of strings of relevant holiday descriptions.
107 The holidays are those in the list calendar-holidays."
108 (let* ((displayed-month (extract-calendar-month date
))
109 (displayed-year (extract-calendar-year date
))
110 (h (calendar-holiday-list))
113 (if (calendar-date-equal date
(car (car h
)))
114 (setq holiday-list
(append holiday-list
(cdr (car h
)))))
118 (defun calendar-cursor-holidays ()
119 "Find holidays for the date specified by the cursor in the calendar window."
121 (message "Checking holidays...")
122 (let* ((date (calendar-cursor-to-date t
))
123 (date-string (calendar-date-string date
))
124 (holiday-list (check-calendar-holidays date
))
125 (holiday-string (mapconcat 'identity holiday-list
"; "))
126 (msg (format "%s: %s" date-string holiday-string
)))
127 (if (not holiday-list
)
128 (message "No holidays known for %s" date-string
)
129 (if (<= (length msg
) (frame-width))
131 (set-buffer (get-buffer-create holiday-buffer
))
132 (setq buffer-read-only nil
)
133 (calendar-set-mode-line date-string
)
135 (insert (mapconcat 'identity holiday-list
"\n"))
136 (goto-char (point-min))
137 (set-buffer-modified-p nil
)
138 (setq buffer-read-only t
)
139 (display-buffer holiday-buffer
)
140 (message "Checking holidays...done")))))
142 (defun mark-calendar-holidays ()
143 "Mark notable days in the calendar window."
145 (setq mark-holidays-in-calendar t
)
146 (message "Marking holidays...")
147 (let ((holiday-list (calendar-holiday-list)))
149 (mark-visible-calendar-date
150 (car (car holiday-list
)) calendar-holiday-marker
)
151 (setq holiday-list
(cdr holiday-list
))))
152 (message "Marking holidays...done"))
154 (defun list-calendar-holidays ()
155 "Create a buffer containing the holidays for the current calendar window.
156 The holidays are those in the list calendar-notable-days. Returns t if any
157 holidays are found, nil if not."
159 (message "Looking up holidays...")
160 (let ((holiday-list (calendar-holiday-list))
165 (if (not holiday-list
)
167 (message "Looking up holidays...none found")
169 (set-buffer (get-buffer-create holiday-buffer
))
170 (setq buffer-read-only nil
)
171 (increment-calendar-month m1 y1 -
1)
172 (increment-calendar-month m2 y2
1)
173 (calendar-set-mode-line
175 (format "Notable Dates from %s to %s, %d%%-"
176 (calendar-month-name m1
) (calendar-month-name m2
) y2
)
177 (format "Notable Dates from %s, %d to %s, %d%%-"
178 (calendar-month-name m1
) y1
(calendar-month-name m2
) y2
)))
182 '(lambda (x) (concat (calendar-date-string (car x
))
185 (goto-char (point-min))
186 (set-buffer-modified-p nil
)
187 (setq buffer-read-only t
)
188 (display-buffer holiday-buffer
)
189 (message "Looking up holidays...done")
192 (defun calendar-holiday-list ()
193 "Form the list of holidays that occur on dates in the calendar window.
194 The holidays are those in the list calendar-holidays."
195 (let ((p calendar-holidays
)
199 (if calendar-debug-sexp
200 (let ((stack-trace-on-error t
))
205 (message "Bad holiday list item: %s" (car p
))
208 (setq holiday-list
(append holidays holiday-list
))))
210 (setq holiday-list
(sort holiday-list
'calendar-date-compare
))))
212 ;; Below are the functions that calculate the dates of holidays; these
213 ;; are eval'ed in the function calendar-holiday-list. If you
214 ;; write other such functions, be sure to imitate the style used below.
215 ;; Remember that each function must return a list of items of the form
216 ;; ((month day year) string) of VISIBLE dates in the calendar window.
218 (defun holiday-fixed (month day string
)
219 "Holiday on MONTH, DAY (Gregorian) called STRING.
220 If MONTH, DAY is visible, the value returned is the list (((MONTH DAY year)
221 STRING)). Returns nil if it is not visible in the current calendar window."
222 (let ((m displayed-month
)
224 (increment-calendar-month m y
(- 11 month
))
226 (list (list (list month day y
) string
)))))
228 (defun holiday-float (month dayname n string
&optional day
)
229 "Holiday on MONTH, DAYNAME (Nth occurrence, Gregorian) called STRING.
230 If the Nth DAYNAME in MONTH is visible, the value returned is the list
231 \(((MONTH DAY year) STRING)).
233 If N<0, count backward from the end of MONTH.
235 An optional parameter DAY means the Nth DAYNAME after/before MONTH DAY.
237 Returns nil if it is not visible in the current calendar window."
238 (let ((m displayed-month
)
240 (increment-calendar-month m y
(- 11 month
))
242 (list (list (calendar-nth-named-day n dayname month y day
) string
)))))
244 (defun holiday-sexp (sexp string
)
245 "Sexp holiday for dates in the calendar window.
246 SEXP is an expression in variable `year' evaluates to `date'.
248 STRING is an expression in `date' that evaluates to the holiday description
251 If `date' is visible in the calendar window, the holiday STRING is on that
252 date. If date is nil, or if the date is not visible, there is no holiday."
253 (let ((m displayed-month
)
255 (increment-calendar-month m y -
1)
256 (filter-visible-calendar-holidays
260 (string (if date
(eval string
))))
261 (list (list date string
)))
264 (string (if date
(eval string
))))
265 (list (list date string
)))))))
267 (defun holiday-advent ()
268 "Date of Advent, if visible in calendar window."
269 (let ((year displayed-year
)
270 (month displayed-month
))
271 (increment-calendar-month month year -
1)
272 (let ((advent (calendar-gregorian-from-absolute
273 (calendar-dayname-on-or-before 0
274 (calendar-absolute-from-gregorian
275 (list 12 3 year
))))))
276 (if (calendar-date-is-visible-p advent
)
277 (list (list advent
"Advent"))))))
279 (defun holiday-easter-etc ()
280 "List of dates related to Easter, as visible in calendar window."
281 (if (and (> displayed-month
5) (not all-christian-calendar-holidays
))
282 nil
;; Ash Wednesday, Good Friday, and Easter are not visible.
283 (let* ((century (1+ (/ displayed-year
100)))
284 (shifted-epact ;; Age of moon for April 5...
285 (%
(+ 14 (* 11 (% displayed-year
19));; ...by Nicaean rule
286 (- ;; ...corrected for the Gregorian century rule
288 (/ ;; ...corrected for Metonic cycle inaccuracy.
289 (+ 5 (* 8 century
)) 25)
290 (* 30 century
));; Keeps value positive.
292 (adjusted-epact ;; Adjust for 29.5 day month.
293 (if (or (= shifted-epact
0)
294 (and (= shifted-epact
1) (< 10 (% displayed-year
19))))
297 (paschal-moon ;; Day after the full moon on or after March 21.
298 (- (calendar-absolute-from-gregorian (list 4 19 displayed-year
))
300 (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon
7)))
303 (list (calendar-gregorian-from-absolute abs-easter
)
305 (list (calendar-gregorian-from-absolute (- abs-easter
2))
307 (list (calendar-gregorian-from-absolute (- abs-easter
46))
311 (list (calendar-gregorian-from-absolute (- abs-easter
63))
312 "Septuagesima Sunday")
313 (list (calendar-gregorian-from-absolute (- abs-easter
56))
315 (list (calendar-gregorian-from-absolute (- abs-easter
49))
317 (list (calendar-gregorian-from-absolute (- abs-easter
48))
319 (list (calendar-gregorian-from-absolute (- abs-easter
47))
321 (list (calendar-gregorian-from-absolute (- abs-easter
14))
323 (list (calendar-gregorian-from-absolute (- abs-easter
7))
325 (list (calendar-gregorian-from-absolute (- abs-easter
3))
327 (list (calendar-gregorian-from-absolute (+ abs-easter
35))
329 (list (calendar-gregorian-from-absolute (+ abs-easter
39))
331 (list (calendar-gregorian-from-absolute (+ abs-easter
49))
332 "Pentecost (Whitsunday)")
333 (list (calendar-gregorian-from-absolute (+ abs-easter
50))
335 (list (calendar-gregorian-from-absolute (+ abs-easter
56))
337 (list (calendar-gregorian-from-absolute (+ abs-easter
60))
340 (filter-visible-calendar-holidays mandatory
)))
341 (if all-christian-calendar-holidays
344 (filter-visible-calendar-holidays optional
)
348 (defun holiday-greek-orthodox-easter ()
349 "Date of Easter according to the rule of the Council of Nicaea."
350 (let ((m displayed-month
)
352 (increment-calendar-month m y
1)
354 (extract-calendar-year
355 (calendar-julian-from-absolute
356 (calendar-absolute-from-gregorian
357 (list m
(calendar-last-day-of-month m y
) y
)))))
358 (shifted-epact ;; Age of moon for April 5.
360 (* 11 (% julian-year
19)))
362 (paschal-moon ;; Day after full moon on or after March 21.
363 (- (calendar-absolute-from-julian (list 4 19 julian-year
))
365 (nicaean-easter;; Sunday following the Paschal moon
366 (calendar-gregorian-from-absolute
367 (calendar-dayname-on-or-before 0 (+ paschal-moon
7)))))
368 (if (calendar-date-is-visible-p nicaean-easter
)
369 (list (list nicaean-easter
"Pascha (Greek Orthodox Easter)"))))))
371 (defun filter-visible-calendar-holidays (l)
372 "Return a list of all visible holidays of those on L."
377 (calendar-date-is-visible-p (car (car p
)))
378 (setq visible
(append (list (car p
)) visible
)))
384 ;;; holidays.el ends here