1 ;;; holidays.el --- holiday functions for the calendar package
3 ;;; Copyright (C) 1989, 1990, 1992, 1993 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
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 ;; This collection of functions implements the holiday features as described
29 ;; Comments, corrections, and improvements should be sent to
30 ;; Edward M. Reingold Department of Computer Science
31 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
32 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
33 ;; Urbana, Illinois 61801
35 ;; Technical details of all the calendrical calculations can be found in
36 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
37 ;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
38 ;; pages 899-928. ``Calendrical Calculations, Part II: Three Historical
39 ;; Calendars'' by E. M. Reingold, N. Dershowitz, and S. M. Clamen,
40 ;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993),
43 ;; Hard copies of these two papers can be obtained by sending email to
44 ;; reingold@cs.uiuc.edu with the SUBJECT "send-paper-cal" (no quotes) and
45 ;; the message BODY containing your mailing address (snail).
51 (autoload 'solar-equinoxes-solstices
"solar"
52 "Date and time of equinoxes and solstices, if visible in the calendar window.
53 Requires floating point."
56 (defun holidays (&optional arg
)
57 "Display the holidays for last month, this month, and next month.
58 If called with an optional prefix argument, prompts for month and year.
60 This function is suitable for execution in a .emacs file."
63 (let* ((completion-ignore-case t
)
64 (date (calendar-current-date))
71 (mapcar 'list
(append calendar-month-name-array nil
))
73 (calendar-make-alist calendar-month-name-array
)))
74 (extract-calendar-month date
)))
81 (extract-calendar-year (calendar-current-date))))
82 (extract-calendar-year date
))))
83 (list-calendar-holidays))))
85 (defun check-calendar-holidays (date)
86 "Check the list of holidays for any that occur on DATE.
87 The value returned is a list of strings of relevant holiday descriptions.
88 The holidays are those in the list calendar-holidays."
89 (let* ((displayed-month (extract-calendar-month date
))
90 (displayed-year (extract-calendar-year date
))
91 (h (calendar-holiday-list))
94 (if (calendar-date-equal date
(car (car h
)))
95 (setq holiday-list
(append holiday-list
(cdr (car h
)))))
99 (defun calendar-cursor-holidays ()
100 "Find holidays for the date specified by the cursor in the calendar window."
102 (message "Checking holidays...")
103 (let* ((date (calendar-cursor-to-date t
))
104 (date-string (calendar-date-string date
))
105 (holiday-list (check-calendar-holidays date
))
106 (holiday-string (mapconcat 'identity holiday-list
"; "))
107 (msg (format "%s: %s" date-string holiday-string
)))
108 (if (not holiday-list
)
109 (message "No holidays known for %s" date-string
)
110 (if (<= (length msg
) (frame-width))
112 (set-buffer (get-buffer-create holiday-buffer
))
113 (setq buffer-read-only nil
)
114 (calendar-set-mode-line date-string
)
116 (insert (mapconcat 'identity holiday-list
"\n"))
117 (goto-char (point-min))
118 (set-buffer-modified-p nil
)
119 (setq buffer-read-only t
)
120 (display-buffer holiday-buffer
)
121 (message "Checking holidays...done")))))
123 (defun mark-calendar-holidays ()
124 "Mark notable days in the calendar window."
126 (setq mark-holidays-in-calendar t
)
127 (message "Marking holidays...")
128 (let ((holiday-list (calendar-holiday-list)))
130 (mark-visible-calendar-date
131 (car (car holiday-list
)) calendar-holiday-marker
)
132 (setq holiday-list
(cdr holiday-list
))))
133 (message "Marking holidays...done"))
135 (defun list-calendar-holidays ()
136 "Create a buffer containing the holidays for the current calendar window.
137 The holidays are those in the list calendar-notable-days. Returns t if any
138 holidays are found, nil if not."
140 (message "Looking up holidays...")
141 (let ((holiday-list (calendar-holiday-list))
146 (if (not holiday-list
)
148 (message "Looking up holidays...none found")
150 (set-buffer (get-buffer-create holiday-buffer
))
151 (setq buffer-read-only nil
)
152 (increment-calendar-month m1 y1 -
1)
153 (increment-calendar-month m2 y2
1)
154 (calendar-set-mode-line
156 (format "Notable Dates from %s to %s, %d%%-"
157 (calendar-month-name m1
) (calendar-month-name m2
) y2
)
158 (format "Notable Dates from %s, %d to %s, %d%%-"
159 (calendar-month-name m1
) y1
(calendar-month-name m2
) y2
)))
163 '(lambda (x) (concat (calendar-date-string (car x
))
166 (goto-char (point-min))
167 (set-buffer-modified-p nil
)
168 (setq buffer-read-only t
)
169 (display-buffer holiday-buffer
)
170 (message "Looking up holidays...done")
173 (defun calendar-holiday-list ()
174 "Form the list of holidays that occur on dates in the calendar window.
175 The holidays are those in the list calendar-holidays."
176 (let ((p calendar-holidays
)
180 (if calendar-debug-sexp
181 (let ((stack-trace-on-error t
))
186 (message "Bad holiday list item: %s" (car p
))
189 (setq holiday-list
(append holidays holiday-list
))))
191 (setq holiday-list
(sort holiday-list
'calendar-date-compare
))))
193 ;; Below are the functions that calculate the dates of holidays; these
194 ;; are eval'ed in the function calendar-holiday-list. If you
195 ;; write other such functions, be sure to imitate the style used below.
196 ;; Remember that each function must return a list of items of the form
197 ;; ((month day year) string) of VISIBLE dates in the calendar window.
199 (defun holiday-fixed (month day string
)
200 "Holiday on MONTH, DAY (Gregorian) called STRING.
201 If MONTH, DAY is visible, the value returned is the list (((MONTH DAY year)
202 STRING)). Returns nil if it is not visible in the current calendar window."
203 (let ((m displayed-month
)
205 (increment-calendar-month m y
(- 11 month
))
207 (list (list (list month day y
) string
)))))
209 (defun holiday-float (month dayname n string
&optional day
)
210 "Holiday on MONTH, DAYNAME (Nth occurrence, Gregorian) called STRING.
211 If the Nth DAYNAME in MONTH is visible, the value returned is the list
212 (((MONTH DAY year) STRING)).
214 If N<0, count backward from the end of MONTH.
216 An optional parameter DAY means the Nth DAYNAME after/before MONTH DAY.
218 Returns nil if it is not visible in the current calendar window."
219 (let ((m displayed-month
)
221 (increment-calendar-month m y
(- 11 month
))
223 (list (list (calendar-nth-named-day n dayname month y day
) string
)))))
225 (defun holiday-julian (month day string
)
226 "Holiday on MONTH, DAY (Julian) called STRING.
227 If MONTH, DAY (Julian) is visible, the value returned is corresponding
228 Gregorian date in the form of the list (((month day year) STRING)). Returns
229 nil if it is not visible in the current calendar window."
230 (let ((m1 displayed-month
)
235 (increment-calendar-month m1 y1 -
1)
236 (increment-calendar-month m2 y2
1)
237 (let* ((start-date (calendar-absolute-from-gregorian
239 (end-date (calendar-absolute-from-gregorian
240 (list m2
(calendar-last-day-of-month m2 y2
) y2
)))
241 (julian-start (calendar-julian-from-absolute start-date
))
242 (julian-end (calendar-julian-from-absolute end-date
))
243 (julian-y1 (extract-calendar-year julian-start
))
244 (julian-y2 (extract-calendar-year julian-end
)))
245 (setq year
(if (< 10 month
) julian-y1 julian-y2
))
246 (let ((date (calendar-gregorian-from-absolute
247 (calendar-absolute-from-julian
248 (list month day year
)))))
249 (if (calendar-date-is-visible-p date
)
250 (list (list date string
)))))))
252 (defun holiday-islamic (month day string
)
253 "Holiday on MONTH, DAY (Islamic) called STRING.
254 If MONTH, DAY (Islamic) is visible, the value returned is corresponding
255 Gregorian date in the form of the list (((month day year) STRING)). Returns
256 nil if it is not visible in the current calendar window."
257 (let* ((islamic-date (calendar-islamic-from-absolute
258 (calendar-absolute-from-gregorian
259 (list displayed-month
15 displayed-year
))))
260 (m (extract-calendar-month islamic-date
))
261 (y (extract-calendar-year islamic-date
))
264 nil
;; Islamic calendar doesn't apply.
265 (increment-calendar-month m y
(- 10 month
))
266 (if (> m
7);; Islamic date might be visible
267 (let ((date (calendar-gregorian-from-absolute
268 (calendar-absolute-from-islamic (list month day y
)))))
269 (if (calendar-date-is-visible-p date
)
270 (list (list date string
))))))))
272 (defun holiday-hebrew (month day string
)
273 "Holiday on MONTH, DAY (Hebrew) called STRING.
274 If MONTH, DAY (Hebrew) is visible, the value returned is corresponding
275 Gregorian date in the form of the list (((month day year) STRING)). Returns
276 nil if it is not visible in the current calendar window."
277 (if (memq displayed-month
;; This test is only to speed things up a bit;
278 (list ;; it works fine without the test too.
279 (if (< 11 month
) (- month
11) (+ month
1))
280 (if (< 10 month
) (- month
10) (+ month
2))
281 (if (< 9 month
) (- month
9) (+ month
3))
282 (if (< 8 month
) (- month
8) (+ month
4))
283 (if (< 7 month
) (- month
7) (+ month
5))))
284 (let ((m1 displayed-month
)
289 (increment-calendar-month m1 y1 -
1)
290 (increment-calendar-month m2 y2
1)
291 (let* ((start-date (calendar-absolute-from-gregorian
293 (end-date (calendar-absolute-from-gregorian
294 (list m2
(calendar-last-day-of-month m2 y2
) y2
)))
295 (hebrew-start (calendar-hebrew-from-absolute start-date
))
296 (hebrew-end (calendar-hebrew-from-absolute end-date
))
297 (hebrew-y1 (extract-calendar-year hebrew-start
))
298 (hebrew-y2 (extract-calendar-year hebrew-end
)))
299 (setq year
(if (< 6 month
) hebrew-y2 hebrew-y1
))
300 (let ((date (calendar-gregorian-from-absolute
301 (calendar-absolute-from-hebrew
302 (list month day year
)))))
303 (if (calendar-date-is-visible-p date
)
304 (list (list date string
))))))))
306 (defun holiday-sexp (sexp string
)
307 "Sexp holiday for dates in the calendar window.
308 SEXP is an expression in variable `year' evaluates to `date'.
310 STRING is an expression in `date' that evaluates to the holiday description
313 If `date' is visible in the calendar window, the holiday STRING is on that
314 date. If date is nil, or if the date is not visible, there is no holiday."
315 (let ((m displayed-month
)
317 (increment-calendar-month m y -
1)
318 (filter-visible-calendar-holidays
322 (string (if date
(eval string
))))
323 (list (list date string
)))
326 (string (if date
(eval string
))))
327 (list (list date string
)))))))
329 (defun holiday-advent ()
330 "Date of Advent, if visible in calendar window."
331 (let ((year displayed-year
)
332 (month displayed-month
))
333 (increment-calendar-month month year -
1)
334 (let ((advent (calendar-gregorian-from-absolute
335 (calendar-dayname-on-or-before 0
336 (calendar-absolute-from-gregorian
337 (list 12 3 year
))))))
338 (if (calendar-date-is-visible-p advent
)
339 (list (list advent
"Advent"))))))
341 (defun holiday-easter-etc ()
342 "List of dates related to Easter, as visible in calendar window."
343 (if (and (> displayed-month
5) (not all-christian-calendar-holidays
))
344 nil
;; Ash Wednesday, Good Friday, and Easter are not visible.
345 (let* ((century (1+ (/ displayed-year
100)))
346 (shifted-epact ;; Age of moon for April 5...
347 (%
(+ 14 (* 11 (% displayed-year
19));; ...by Nicaean rule
348 (- ;; ...corrected for the Gregorian century rule
350 (/ ;; ...corrected for Metonic cycle inaccuracy.
351 (+ 5 (* 8 century
)) 25)
352 (* 30 century
));; Keeps value positive.
354 (adjusted-epact ;; Adjust for 29.5 day month.
355 (if (or (= shifted-epact
0)
356 (and (= shifted-epact
1) (< 10 (% displayed-year
19))))
359 (paschal-moon ;; Day after the full moon on or after March 21.
360 (- (calendar-absolute-from-gregorian (list 4 19 displayed-year
))
362 (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon
7)))
365 (list (calendar-gregorian-from-absolute abs-easter
)
367 (list (calendar-gregorian-from-absolute (- abs-easter
2))
369 (list (calendar-gregorian-from-absolute (- abs-easter
46))
373 (list (calendar-gregorian-from-absolute (- abs-easter
63))
374 "Septuagesima Sunday")
375 (list (calendar-gregorian-from-absolute (- abs-easter
56))
377 (list (calendar-gregorian-from-absolute (- abs-easter
49))
379 (list (calendar-gregorian-from-absolute (- abs-easter
48))
381 (list (calendar-gregorian-from-absolute (- abs-easter
47))
383 (list (calendar-gregorian-from-absolute (- abs-easter
14))
385 (list (calendar-gregorian-from-absolute (- abs-easter
7))
387 (list (calendar-gregorian-from-absolute (- abs-easter
3))
389 (list (calendar-gregorian-from-absolute (+ abs-easter
35))
391 (list (calendar-gregorian-from-absolute (+ abs-easter
39))
393 (list (calendar-gregorian-from-absolute (+ abs-easter
49))
394 "Pentecost (Whitsunday)")
395 (list (calendar-gregorian-from-absolute (+ abs-easter
50))
397 (list (calendar-gregorian-from-absolute (+ abs-easter
56))
399 (list (calendar-gregorian-from-absolute (+ abs-easter
60))
402 (filter-visible-calendar-holidays mandatory
)))
403 (if all-christian-calendar-holidays
406 (filter-visible-calendar-holidays optional
)
410 (defun holiday-greek-orthodox-easter ()
411 "Date of Easter according to the rule of the Council of Nicaea."
412 (let ((m displayed-month
)
414 (increment-calendar-month m y
1)
416 (extract-calendar-year
417 (calendar-julian-from-absolute
418 (calendar-absolute-from-gregorian
419 (list m
(calendar-last-day-of-month m y
) y
)))))
420 (shifted-epact ;; Age of moon for April 5.
422 (* 11 (% julian-year
19)))
424 (paschal-moon ;; Day after full moon on or after March 21.
425 (- (calendar-absolute-from-julian (list 4 19 julian-year
))
427 (nicaean-easter;; Sunday following the Paschal moon
428 (calendar-gregorian-from-absolute
429 (calendar-dayname-on-or-before 0 (+ paschal-moon
7)))))
430 (if (calendar-date-is-visible-p nicaean-easter
)
431 (list (list nicaean-easter
"Pascha (Greek Orthodox Easter)"))))))
433 (defun holiday-rosh-hashanah-etc ()
434 "List of dates related to Rosh Hashanah, as visible in calendar window."
435 (if (or (< displayed-month
8)
436 (> displayed-month
11))
437 nil
;; None of the dates is visible
438 (let* ((abs-r-h (calendar-absolute-from-hebrew
439 (list 7 1 (+ displayed-year
3761))))
442 (list (calendar-gregorian-from-absolute abs-r-h
)
443 (format "Rosh HaShanah %d" (+ 3761 displayed-year
)))
444 (list (calendar-gregorian-from-absolute (+ abs-r-h
9))
446 (list (calendar-gregorian-from-absolute (+ abs-r-h
14))
448 (list (calendar-gregorian-from-absolute (+ abs-r-h
21))
450 (list (calendar-gregorian-from-absolute (+ abs-r-h
22))
454 (list (calendar-gregorian-from-absolute
455 (calendar-dayname-on-or-before 6 (- abs-r-h
4)))
457 (list (calendar-gregorian-from-absolute (1- abs-r-h
))
458 "Erev Rosh HaShannah")
459 (list (calendar-gregorian-from-absolute (1+ abs-r-h
))
460 "Rosh HaShanah (second day)")
461 (list (calendar-gregorian-from-absolute
462 (if (= (% abs-r-h
7) 4) (+ abs-r-h
3) (+ abs-r-h
2)))
464 (list (calendar-gregorian-from-absolute
465 (calendar-dayname-on-or-before 6 (+ 7 abs-r-h
)))
467 (list (calendar-gregorian-from-absolute (+ abs-r-h
8))
469 (list (calendar-gregorian-from-absolute (+ abs-r-h
13))
471 (list (calendar-gregorian-from-absolute (+ abs-r-h
15))
472 "Sukkot (second day)")
473 (list (calendar-gregorian-from-absolute (+ abs-r-h
16))
474 "Hol Hamoed Sukkot (first day)")
475 (list (calendar-gregorian-from-absolute (+ abs-r-h
17))
476 "Hol Hamoed Sukkot (second day)")
477 (list (calendar-gregorian-from-absolute (+ abs-r-h
18))
478 "Hol Hamoed Sukkot (third day)")
479 (list (calendar-gregorian-from-absolute (+ abs-r-h
19))
480 "Hol Hamoed Sukkot (fourth day)")
481 (list (calendar-gregorian-from-absolute (+ abs-r-h
20))
482 "Hoshannah Rabbah")))
484 (filter-visible-calendar-holidays mandatory
)))
485 (if all-hebrew-calendar-holidays
488 (filter-visible-calendar-holidays optional
)
492 (defun holiday-hanukkah ()
493 "List of dates related to Hanukkah, as visible in calendar window."
494 (if (memq displayed-month
;; This test is only to speed things up a bit;
495 '(10 11 12 1 2));; it works fine without the test too.
496 (let ((m displayed-month
)
498 (increment-calendar-month m y
1)
499 (let* ((h-y (extract-calendar-year
500 (calendar-hebrew-from-absolute
501 (calendar-absolute-from-gregorian
502 (list m
(calendar-last-day-of-month m y
) y
)))))
503 (abs-h (calendar-absolute-from-hebrew (list 9 25 h-y
))))
504 (filter-visible-calendar-holidays
506 (list (calendar-gregorian-from-absolute (1- abs-h
))
508 (list (calendar-gregorian-from-absolute abs-h
)
509 "Hanukkah (first day)")
510 (list (calendar-gregorian-from-absolute (1+ abs-h
))
511 "Hanukkah (second day)")
512 (list (calendar-gregorian-from-absolute (+ abs-h
2))
513 "Hanukkah (third day)")
514 (list (calendar-gregorian-from-absolute (+ abs-h
3))
515 "Hanukkah (fourth day)")
516 (list (calendar-gregorian-from-absolute (+ abs-h
4))
517 "Hanukkah (fifth day)")
518 (list (calendar-gregorian-from-absolute (+ abs-h
5))
519 "Hanukkah (sixth day)")
520 (list (calendar-gregorian-from-absolute (+ abs-h
6))
521 "Hanukkah (seventh day)")
522 (list (calendar-gregorian-from-absolute (+ abs-h
7))
523 "Hanukkah (eighth day)")))))))
525 (defun holiday-passover-etc ()
526 "List of dates related to Passover, as visible in calendar window."
527 (if (< 7 displayed-month
)
528 nil
;; None of the dates is visible
529 (let* ((abs-p (calendar-absolute-from-hebrew
530 (list 1 15 (+ displayed-year
3760))))
533 (list (calendar-gregorian-from-absolute abs-p
)
535 (list (calendar-gregorian-from-absolute (+ abs-p
50))
539 (list (calendar-gregorian-from-absolute
540 (calendar-dayname-on-or-before 6 (- abs-p
43)))
542 (list (calendar-gregorian-from-absolute
543 (calendar-dayname-on-or-before 6 (- abs-p
30)))
545 (list (calendar-gregorian-from-absolute
546 (if (= (% abs-p
7) 2) (- abs-p
33) (- abs-p
31)))
548 (list (calendar-gregorian-from-absolute (- abs-p
31))
550 (list (calendar-gregorian-from-absolute (- abs-p
30))
552 (list (calendar-gregorian-from-absolute
553 (if (zerop (% abs-p
7)) (- abs-p
28) (- abs-p
29)))
555 (list (calendar-gregorian-from-absolute
556 (- (calendar-dayname-on-or-before 6 (- abs-p
14)) 7))
558 (list (calendar-gregorian-from-absolute
559 (calendar-dayname-on-or-before 6 (- abs-p
14)))
561 (list (calendar-gregorian-from-absolute
562 (calendar-dayname-on-or-before 6 (1- abs-p
)))
564 (list (calendar-gregorian-from-absolute (1- abs-p
))
566 (list (calendar-gregorian-from-absolute (1+ abs-p
))
567 "Passover (second day)")
568 (list (calendar-gregorian-from-absolute (+ abs-p
2))
569 "Hol Hamoed Passover (first day)")
570 (list (calendar-gregorian-from-absolute (+ abs-p
3))
571 "Hol Hamoed Passover (second day)")
572 (list (calendar-gregorian-from-absolute (+ abs-p
4))
573 "Hol Hamoed Passover (third day)")
574 (list (calendar-gregorian-from-absolute (+ abs-p
5))
575 "Hol Hamoed Passover (fourth day)")
576 (list (calendar-gregorian-from-absolute (+ abs-p
6))
577 "Passover (seventh day)")
578 (list (calendar-gregorian-from-absolute (+ abs-p
7))
579 "Passover (eighth day)")
580 (list (calendar-gregorian-from-absolute (+ abs-p
12))
582 (list (calendar-gregorian-from-absolute
583 (if (zerop (% abs-p
7))
585 (if (= (% abs-p
7) 6)
589 (list (calendar-gregorian-from-absolute (+ abs-p
33))
591 (list (calendar-gregorian-from-absolute (+ abs-p
43))
593 (list (calendar-gregorian-from-absolute (+ abs-p
49))
595 (list (calendar-gregorian-from-absolute (+ abs-p
51))
596 "Shavuot (second day)")))
598 (filter-visible-calendar-holidays mandatory
)))
599 (if all-hebrew-calendar-holidays
602 (filter-visible-calendar-holidays optional
)
606 (defun holiday-tisha-b-av-etc ()
607 "List of dates around Tisha B'Av, as visible in calendar window."
608 (if (or (< displayed-month
5)
609 (> displayed-month
9))
610 nil
;; None of the dates is visible
611 (let* ((abs-t-a (calendar-absolute-from-hebrew
612 (list 5 9 (+ displayed-year
3760)))))
614 (filter-visible-calendar-holidays
616 (list (calendar-gregorian-from-absolute
617 (if (= (% abs-t-a
7) 6) (- abs-t-a
20) (- abs-t-a
21)))
619 (list (calendar-gregorian-from-absolute
620 (calendar-dayname-on-or-before 6 abs-t-a
))
622 (list (calendar-gregorian-from-absolute
623 (if (= (% abs-t-a
7) 6) (1+ abs-t-a
) abs-t-a
))
625 (list (calendar-gregorian-from-absolute
626 (calendar-dayname-on-or-before 6 (+ abs-t-a
7)))
627 "Shabbat Nahamu"))))))
629 (defun filter-visible-calendar-holidays (l)
630 "Return a list of all visible holidays of those on L."
635 (calendar-date-is-visible-p (car (car p
)))
636 (setq visible
(append (list (car p
)) visible
)))
642 ;;; holidays.el ends here