*** empty log message ***
[emacs.git] / lisp / calendar / holidays.el
blob437be3c5aba9147ec691440098bca0412cacb8b4
1 ;;; holidays.el --- holiday functions for the calendar package
3 ;; Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is distributed in the hope that it will be useful,
8 ;; but WITHOUT ANY WARRANTY. No author or distributor
9 ;; accepts responsibility to anyone for the consequences of using it
10 ;; or for whether it serves any particular purpose or works at all,
11 ;; unless he says so in writing. Refer to the GNU Emacs General Public
12 ;; License for full details.
14 ;; Everyone is granted permission to copy, modify and redistribute
15 ;; GNU Emacs, but only under the conditions described in the
16 ;; GNU Emacs General Public License. A copy of this license is
17 ;; supposed to have been given to you along with GNU Emacs so you
18 ;; can know your rights and responsibilities. It should be in a
19 ;; file named COPYING. Among other things, the copyright notice
20 ;; and this notice must be preserved on all copies.
22 ;; This collection of functions implements the holiday features as described
23 ;; in calendar.el.
25 ;; Comments, corrections, and improvements should be sent to
26 ;; Edward M. Reingold Department of Computer Science
27 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
28 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
29 ;; Urbana, Illinois 61801
31 ;; Technical details of all the calendrical calculations can be found in
32 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
33 ;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
34 ;; pages 899-928.
36 (require 'calendar)
37 (defun holidays ()
38 "Display the holidays for last month, this month, and next month.
39 This function is suitable for execution in a .emacs file."
40 (interactive)
41 (save-excursion
42 (let* ((date (calendar-current-date))
43 (displayed-month (extract-calendar-month date))
44 (displayed-year (extract-calendar-year date)))
45 (list-calendar-holidays))))
47 (defun check-calendar-holidays (date)
48 "Check the list of holidays for any that occur on DATE.
49 The value returned is a list of strings of relevant holiday descriptions.
50 The holidays are those in the list calendar-holidays."
51 (let* ((displayed-month (extract-calendar-month date))
52 (displayed-year (extract-calendar-year date))
53 (h (calendar-holiday-list))
54 (holiday-list))
55 (while h
56 (if (calendar-date-equal date (car (car h)))
57 (setq holiday-list (append holiday-list (cdr (car h)))))
58 (setq h (cdr h)))
59 holiday-list))
61 (defun calendar-cursor-holidays ()
62 "Find holidays for the date specified by the cursor in the calendar window."
63 (interactive)
64 (message "Checking holidays...")
65 (let* ((date (calendar-cursor-to-date))
66 (date-string (calendar-date-string date))
67 (holiday-list (check-calendar-holidays date))
68 (holiday-string (mapconcat 'identity holiday-list "; "))
69 (msg (format "%s: %s" date-string holiday-string)))
70 (if (not holiday-list)
71 (message "No holidays known for %s" date-string)
72 (if (<= (length msg) (screen-width))
73 (message msg)
74 (set-buffer (get-buffer-create holiday-buffer))
75 (setq buffer-read-only nil)
76 (setq mode-line-format
77 (format "--------------------------%s%%-"
78 date-string))
79 (erase-buffer)
80 (insert (mapconcat 'identity holiday-list "\n"))
81 (goto-char (point-min))
82 (set-buffer-modified-p nil)
83 (setq buffer-read-only t)
84 (display-buffer holiday-buffer)
85 (message "Checking holidays...done")))))
87 (defun mark-calendar-holidays ()
88 "Mark notable days in the calendar window."
89 (interactive)
90 (setq mark-holidays-in-calendar t)
91 (message "Marking holidays...")
92 (let ((holiday-list (calendar-holiday-list)))
93 (while holiday-list
94 (mark-visible-calendar-date
95 (car (car holiday-list)) calendar-holiday-marker)
96 (setq holiday-list (cdr holiday-list))))
97 (message "Marking holidays...done"))
99 (defun list-calendar-holidays ()
100 "Create a buffer containing the holidays for the current calendar window.
101 The holidays are those in the list calendar-notable-days. Returns t if any
102 holidays are found, nil if not."
103 (interactive)
104 (message "Looking up holidays...")
105 (let ((holiday-list (calendar-holiday-list))
106 (m1 displayed-month)
107 (y1 displayed-year)
108 (m2 displayed-month)
109 (y2 displayed-year))
110 (if (not holiday-list)
111 (progn
112 (message "Looking up holidays...none found")
113 nil)
114 (set-buffer (get-buffer-create holiday-buffer))
115 (setq buffer-read-only nil)
116 (increment-calendar-month m1 y1 -1)
117 (increment-calendar-month m2 y2 1)
118 (setq mode-line-format
119 (format "-------------Notable Dates from %s, %d to %s, %d%%-"
120 (calendar-month-name m1) y1 (calendar-month-name m2) y2))
121 (erase-buffer)
122 (insert
123 (mapconcat
124 '(lambda (x) (concat (calendar-date-string (car x))
125 ": " (car (cdr x))))
126 holiday-list "\n"))
127 (goto-char (point-min))
128 (set-buffer-modified-p nil)
129 (setq buffer-read-only t)
130 (display-buffer holiday-buffer)
131 (message "Looking up holidays...done")
132 t)))
134 (defun calendar-holiday-list ()
135 "Form the list of holidays that occur on dates in the calendar window.
136 The holidays are those in the list calendar-holidays."
137 (let ((p calendar-holidays)
138 (holiday-list))
139 (while p
140 (let* ((function-name
141 (intern (format "calendar-holiday-function-%s" (car (car p)))))
142 (holidays
143 (if (cdr (car p));; optional arguments
144 (funcall function-name (cdr (car p)))
145 (funcall function-name))))
146 (if holidays
147 (setq holiday-list (append holidays holiday-list))))
148 (setq p (cdr p)))
149 (setq holiday-list (sort holiday-list 'calendar-date-compare))))
151 ;; Below are the functions that calculate the dates of holidays; these
152 ;; are called by the funcall in the function calendar-holiday-list. If you
153 ;; write other such functions, be sure to imitate the style used below,
154 ;; including the evaluation of each element in the list that constitutes
155 ;; the argument to the function. If you don't do this evaluation, the
156 ;; list calendar-holidays cannot contain expressions (as, for example, in
157 ;; the entry for the Islamic new year. Also remember that each function
158 ;; must return a list of items of the form ((month day year) string);
159 ;; the date (month day year) should be visible in the calendar window.
161 (defun calendar-holiday-function-fixed (x)
162 "Returns the corresponding Gregorian date, if visible in the window, to
163 month, year where month is (car X) and year is (car (cdr X)). If it is
164 visible, the value returned is the list (((month day year) string)) where
165 string is (car (nthcdr 2 X)). Returns nil if it is not visible in the
166 current calendar window."
167 (let* ((month (eval (car x)))
168 (day (eval (car (cdr x))))
169 (string (eval (car (nthcdr 2 x))))
170 (m displayed-month)
171 (y displayed-year))
172 (increment-calendar-month m y (- 11 month))
173 (if (> m 9)
174 (list (list (list month day y) string)))))
176 (defun calendar-holiday-function-float (x)
177 "Returns the corresponding Gregorian date, if visible in the window, to the
178 n-th occurrence (negative counts from the end of the month) of dayname in
179 month, year where month is (car X), year is (car (cdr X)), n is
180 \(car \(nthcdr 2 X\)\). If it is visible, the value returned is the list
181 \(\(\(month day year)\ string\)\) where string is (car (nthcdr 3 X)).
182 Returns nil if it is not visible in the current calendar window."
183 (let* ((month (eval (car x)))
184 (dayname (eval (car (cdr x))))
185 (n (eval (car (nthcdr 2 x))))
186 (string (eval (car (nthcdr 3 x))))
187 (m displayed-month)
188 (y displayed-year))
189 (increment-calendar-month m y (- 11 month))
190 (if (> m 9)
191 (list (list (calendar-nth-named-day n dayname month y) string)))))
193 (defun calendar-holiday-function-julian (x)
194 "Returns the corresponding Gregorian date, if visible in the window, to the
195 Julian date month, year where month is (car X) and year is (car (cdr X)).
196 If it is visible, the value returned is the list (((month day year) string))
197 where string is (car (nthcdr 2 X)). Returns nil if it is not visible in the
198 current calendar window."
199 (let* ((month (eval (car x)))
200 (day (eval (car (cdr x))))
201 (string (eval (car (nthcdr 2 x))))
202 (m1 displayed-month)
203 (y1 displayed-year)
204 (m2 displayed-month)
205 (y2 displayed-year)
206 (year))
207 (increment-calendar-month m1 y1 -1)
208 (increment-calendar-month m2 y2 1)
209 (let* ((start-date (calendar-absolute-from-gregorian
210 (list m1 1 y1)))
211 (end-date (calendar-absolute-from-gregorian
212 (list m2 (calendar-last-day-of-month m2 y2) y2)))
213 (julian-start (calendar-julian-from-absolute start-date))
214 (julian-end (calendar-julian-from-absolute end-date))
215 (julian-y1 (extract-calendar-year julian-start))
216 (julian-y2 (extract-calendar-year julian-end)))
217 (setq year (if (< 10 month) julian-y1 julian-y2))
218 (let ((date (calendar-gregorian-from-absolute
219 (calendar-absolute-from-julian
220 (list month day year)))))
221 (if (calendar-date-is-visible-p date)
222 (list (list date string)))))))
224 (defun calendar-holiday-function-islamic (x)
225 "Returns the corresponding Gregorian date, if visible in the window, to the
226 Islamic date month, day where month is (car X) and day is (car (cdr X)).
227 If it is visible, the value returned is the list (((month day year) string))
228 where string is (car (nthcdr 2 X)). Returns nil if it is not visible in
229 the current calendar window."
230 (let* ((month (eval (car x)))
231 (day (eval (car (cdr x))))
232 (string (eval (car (nthcdr 2 x))))
233 (islamic-date (calendar-islamic-from-absolute
234 (calendar-absolute-from-gregorian
235 (list displayed-month 15 displayed-year))))
236 (m (extract-calendar-month islamic-date))
237 (y (extract-calendar-year islamic-date))
238 (date))
239 (if (< m 1)
240 nil;; Islamic calendar doesn't apply.
241 (increment-calendar-month m y (- 10 month))
242 (if (> m 7);; Islamic date might be visible
243 (let ((date (calendar-gregorian-from-absolute
244 (calendar-absolute-from-islamic (list month day y)))))
245 (if (calendar-date-is-visible-p date)
246 (list (list date string))))))))
248 (defun calendar-holiday-function-hebrew (x)
249 "Returns the corresponding Gregorian date, if visible in the window, to the
250 Hebrew date month, day where month is (car X) and day is (car (cdr X)).
251 If it is visible, the value returned is the list (((month day year) string))
252 where string is (car (nthcdr 2 X)). Returns nil if it is not visible in
253 the current calendar window."
254 (let* ((month (eval (car x)))
255 (day (eval (car (cdr x))))
256 (string (eval (car (nthcdr 2 x)))))
257 (if (memq displayed-month;; This test is only to speed things up a bit;
258 (list ;; it works fine without the test too.
259 (if (< 11 month) (- month 11) (+ month 1))
260 (if (< 10 month) (- month 10) (+ month 2))
261 (if (< 9 month) (- month 9) (+ month 3))
262 (if (< 8 month) (- month 8) (+ month 4))
263 (if (< 7 month) (- month 7) (+ month 5))))
264 (let ((m1 displayed-month)
265 (y1 displayed-year)
266 (m2 displayed-month)
267 (y2 displayed-year)
268 (year))
269 (increment-calendar-month m1 y1 -1)
270 (increment-calendar-month m2 y2 1)
271 (let* ((start-date (calendar-absolute-from-gregorian
272 (list m1 1 y1)))
273 (end-date (calendar-absolute-from-gregorian
274 (list m2 (calendar-last-day-of-month m2 y2) y2)))
275 (hebrew-start (calendar-hebrew-from-absolute start-date))
276 (hebrew-end (calendar-hebrew-from-absolute end-date))
277 (hebrew-y1 (extract-calendar-year hebrew-start))
278 (hebrew-y2 (extract-calendar-year hebrew-end)))
279 (setq year (if (< 6 month) hebrew-y2 hebrew-y1))
280 (let ((date (calendar-gregorian-from-absolute
281 (calendar-absolute-from-hebrew
282 (list month day year)))))
283 (if (calendar-date-is-visible-p date)
284 (list (list date string)))))))))
286 (defun calendar-holiday-function-if (x)
287 "Conditional holiday for dates in the calendar window.
288 The boolean condition is (car X). If t, the holiday (car (cdr X)) is
289 checked. If nil, the holiday (car (cdr (cdr X))), if there, is checked."
290 (let* ((boolean (eval (car x)))
291 (h (if boolean (car (cdr x)) (car (cdr (cdr x))))))
292 (if h
293 (let* ((function-name
294 (intern (format "calendar-holiday-function-%s" (car h))))
295 (holidays
296 (if (cdr h);; optional arguments
297 (funcall function-name (cdr h))
298 (funcall function-name))))
299 holidays))))
301 (defun calendar-holiday-function-advent ()
302 "Date of Advent, if visible in calendar window."
303 (let ((year displayed-year)
304 (month displayed-month))
305 (increment-calendar-month month year -1)
306 (let ((advent (calendar-gregorian-from-absolute
307 (calendar-dayname-on-or-before 0
308 (calendar-absolute-from-gregorian
309 (list 12 3 year))))))
310 (if (calendar-date-is-visible-p advent)
311 (list (list advent "Advent"))))))
313 (defun calendar-holiday-function-easter-etc ()
314 "List of dates related to Easter, as visible in calendar window."
315 (if (and (> displayed-month 5) (not all-christian-calendar-holidays))
316 nil;; Ash Wednesday, Good Friday, and Easter are not visible.
317 (let* ((century (1+ (/ displayed-year 100)))
318 (shifted-epact ;; Age of moon for April 5...
319 (% (+ 14 (* 11 (% displayed-year 19));; ...by Nicaean rule
320 (- ;; ...corrected for the Gregorian century rule
321 (/ (* 3 century) 4))
322 (/ ;; ...corrected for Metonic cycle inaccuracy.
323 (+ 5 (* 8 century)) 25)
324 (* 30 century));; Keeps value positive.
325 30))
326 (adjusted-epact ;; Adjust for 29.5 day month.
327 (if (or (= shifted-epact 0)
328 (and (= shifted-epact 1) (< 10 (% displayed-year 19))))
329 (1+ shifted-epact)
330 shifted-epact))
331 (paschal-moon ;; Day after the full moon on or after March 21.
332 (- (calendar-absolute-from-gregorian (list 4 19 displayed-year))
333 adjusted-epact))
334 (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))
335 (mandatory
336 (list
337 (list (calendar-gregorian-from-absolute abs-easter)
338 "Easter Sunday")
339 (list (calendar-gregorian-from-absolute (- abs-easter 2))
340 "Good Friday")
341 (list (calendar-gregorian-from-absolute (- abs-easter 46))
342 "Ash Wednesday")))
343 (optional
344 (list
345 (list (calendar-gregorian-from-absolute (- abs-easter 63))
346 "Septuagesima Sunday")
347 (list (calendar-gregorian-from-absolute (- abs-easter 56))
348 "Sexagesima Sunday")
349 (list (calendar-gregorian-from-absolute (- abs-easter 49))
350 "Shrove Sunday")
351 (list (calendar-gregorian-from-absolute (- abs-easter 48))
352 "Shrove Monday")
353 (list (calendar-gregorian-from-absolute (- abs-easter 47))
354 "Shrove Tuesday")
355 (list (calendar-gregorian-from-absolute (- abs-easter 14))
356 "Passion Sunday")
357 (list (calendar-gregorian-from-absolute (- abs-easter 7))
358 "Palm Sunday")
359 (list (calendar-gregorian-from-absolute (- abs-easter 3))
360 "Maundy Thursday")
361 (list (calendar-gregorian-from-absolute (+ abs-easter 35))
362 "Rogation Sunday")
363 (list (calendar-gregorian-from-absolute (+ abs-easter 39))
364 "Ascension Sunday")
365 (list (calendar-gregorian-from-absolute (+ abs-easter 49))
366 "Pentecost (Whitsunday)")
367 (list (calendar-gregorian-from-absolute (+ abs-easter 50))
368 "Whitmunday")
369 (list (calendar-gregorian-from-absolute (+ abs-easter 56))
370 "Trinity Sunday")
371 (list (calendar-gregorian-from-absolute (+ abs-easter 60))
372 "Corpus Christi")))
373 (output-list
374 (filter-visible-calendar-holidays mandatory)))
375 (if all-christian-calendar-holidays
376 (setq output-list
377 (append
378 (filter-visible-calendar-holidays optional)
379 output-list)))
380 output-list)))
382 (defun calendar-holiday-function-rosh-hashanah-etc ()
383 "List of dates related to Rosh Hashanah, as visible in calendar window."
384 (if (or (< displayed-month 8)
385 (> displayed-month 11))
386 nil;; None of the dates is visible
387 (let* ((abs-r-h (calendar-absolute-from-hebrew
388 (list 7 1 (+ displayed-year 3761))))
389 (mandatory
390 (list
391 (list (calendar-gregorian-from-absolute abs-r-h)
392 (format "Rosh HaShanah %d" (+ 3761 displayed-year)))
393 (list (calendar-gregorian-from-absolute (+ abs-r-h 9))
394 "Yom Kippur")
395 (list (calendar-gregorian-from-absolute (+ abs-r-h 14))
396 "Sukkot")
397 (list (calendar-gregorian-from-absolute (+ abs-r-h 21))
398 "Shemini Atzeret")
399 (list (calendar-gregorian-from-absolute (+ abs-r-h 22))
400 "Simchat Torah")))
401 (optional
402 (list
403 (list (calendar-gregorian-from-absolute
404 (calendar-dayname-on-or-before 6 (- abs-r-h 4)))
405 "Selichot (night)")
406 (list (calendar-gregorian-from-absolute (1- abs-r-h))
407 "Erev Rosh HaShannah")
408 (list (calendar-gregorian-from-absolute (1+ abs-r-h))
409 "Rosh HaShanah (second day)")
410 (list (calendar-gregorian-from-absolute
411 (if (= (% abs-r-h 7) 4) (+ abs-r-h 3) (+ abs-r-h 2)))
412 "Tzom Gedaliah")
413 (list (calendar-gregorian-from-absolute
414 (calendar-dayname-on-or-before 6 (+ 7 abs-r-h)))
415 "Shabbat Shuvah")
416 (list (calendar-gregorian-from-absolute (+ abs-r-h 8))
417 "Erev Yom Kippur")
418 (list (calendar-gregorian-from-absolute (+ abs-r-h 13))
419 "Erev Sukkot")
420 (list (calendar-gregorian-from-absolute (+ abs-r-h 15))
421 "Sukkot (second day)")
422 (list (calendar-gregorian-from-absolute (+ abs-r-h 16))
423 "Hol Hamoed Sukkot (first day)")
424 (list (calendar-gregorian-from-absolute (+ abs-r-h 17))
425 "Hol Hamoed Sukkot (second day)")
426 (list (calendar-gregorian-from-absolute (+ abs-r-h 18))
427 "Hol Hamoed Sukkot (third day)")
428 (list (calendar-gregorian-from-absolute (+ abs-r-h 19))
429 "Hol Hamoed Sukkot (fourth day)")
430 (list (calendar-gregorian-from-absolute (+ abs-r-h 20))
431 "Hoshannah Rabbah")))
432 (output-list
433 (filter-visible-calendar-holidays mandatory)))
434 (if all-hebrew-calendar-holidays
435 (setq output-list
436 (append
437 (filter-visible-calendar-holidays optional)
438 output-list)))
439 output-list)))
441 (defun calendar-holiday-function-hanukkah ()
442 "List of dates related to Hanukkah, as visible in calendar window."
443 (if (memq displayed-month;; This test is only to speed things up a bit;
444 '(10 11 12 1 2));; it works fine without the test too.
445 (let ((m displayed-month)
446 (y displayed-year))
447 (increment-calendar-month m y 1)
448 (let* ((h-y (extract-calendar-year
449 (calendar-hebrew-from-absolute
450 (calendar-absolute-from-gregorian
451 (list m (calendar-last-day-of-month m y) y)))))
452 (abs-h (calendar-absolute-from-hebrew (list 9 25 h-y))))
453 (filter-visible-calendar-holidays
454 (list
455 (list (calendar-gregorian-from-absolute (1- abs-h))
456 "Erev Hanukkah")
457 (list (calendar-gregorian-from-absolute abs-h)
458 "Hanukkah (first day)")
459 (list (calendar-gregorian-from-absolute (1+ abs-h))
460 "Hanukkah (second day)")
461 (list (calendar-gregorian-from-absolute (+ abs-h 2))
462 "Hanukkah (third day)")
463 (list (calendar-gregorian-from-absolute (+ abs-h 3))
464 "Hanukkah (fourth day)")
465 (list (calendar-gregorian-from-absolute (+ abs-h 4))
466 "Hanukkah (fifth day)")
467 (list (calendar-gregorian-from-absolute (+ abs-h 5))
468 "Hanukkah (sixth day)")
469 (list (calendar-gregorian-from-absolute (+ abs-h 6))
470 "Hanukkah (seventh day)")
471 (list (calendar-gregorian-from-absolute (+ abs-h 7))
472 "Hanukkah (eighth day)")))))))
474 (defun calendar-holiday-function-passover-etc ()
475 "List of dates related to Passover, as visible in calendar window."
476 (if (< 7 displayed-month)
477 nil;; None of the dates is visible
478 (let* ((abs-p (calendar-absolute-from-hebrew
479 (list 1 15 (+ displayed-year 3760))))
480 (mandatory
481 (list
482 (list (calendar-gregorian-from-absolute abs-p)
483 "Passover")
484 (list (calendar-gregorian-from-absolute (+ abs-p 50))
485 "Shavuot")))
486 (optional
487 (list
488 (list (calendar-gregorian-from-absolute
489 (calendar-dayname-on-or-before 6 (- abs-p 43)))
490 "Shabbat Shekalim")
491 (list (calendar-gregorian-from-absolute
492 (calendar-dayname-on-or-before 6 (- abs-p 30)))
493 "Shabbat Zachor")
494 (list (calendar-gregorian-from-absolute
495 (if (= (% abs-p 7) 2) (- abs-p 33) (- abs-p 31)))
496 "Fast of Esther")
497 (list (calendar-gregorian-from-absolute (- abs-p 31))
498 "Erev Purim")
499 (list (calendar-gregorian-from-absolute (- abs-p 30))
500 "Purim")
501 (list (calendar-gregorian-from-absolute
502 (if (zerop (% abs-p 7)) (- abs-p 28) (- abs-p 29)))
503 "Shushan Purim")
504 (list (calendar-gregorian-from-absolute
505 (- (calendar-dayname-on-or-before 6 (- abs-p 14)) 7))
506 "Shabbat Parah")
507 (list (calendar-gregorian-from-absolute
508 (calendar-dayname-on-or-before 6 (- abs-p 14)))
509 "Shabbat HaHodesh")
510 (list (calendar-gregorian-from-absolute
511 (calendar-dayname-on-or-before 6 (1- abs-p)))
512 "Shabbat HaGadol")
513 (list (calendar-gregorian-from-absolute (1- abs-p))
514 "Erev Passover")
515 (list (calendar-gregorian-from-absolute (1+ abs-p))
516 "Passover (second day)")
517 (list (calendar-gregorian-from-absolute (+ abs-p 2))
518 "Hol Hamoed Passover (first day)")
519 (list (calendar-gregorian-from-absolute (+ abs-p 3))
520 "Hol Hamoed Passover (second day)")
521 (list (calendar-gregorian-from-absolute (+ abs-p 4))
522 "Hol Hamoed Passover (third day)")
523 (list (calendar-gregorian-from-absolute (+ abs-p 5))
524 "Hol Hamoed Passover (fourth day)")
525 (list (calendar-gregorian-from-absolute (+ abs-p 6))
526 "Passover (seventh day)")
527 (list (calendar-gregorian-from-absolute (+ abs-p 7))
528 "Passover (eighth day)")
529 (list (calendar-gregorian-from-absolute (+ abs-p 12))
530 "Yom HaShoah")
531 (list (calendar-gregorian-from-absolute
532 (if (zerop (% abs-p 7))
533 (+ abs-p 18)
534 (if (= (% abs-p 7) 6)
535 (+ abs-p 19)
536 (+ abs-p 20))))
537 "Yom HaAtzma'ut")
538 (list (calendar-gregorian-from-absolute (+ abs-p 33))
539 "Lag BaOmer")
540 (list (calendar-gregorian-from-absolute (+ abs-p 43))
541 "Yom Yerushalim")
542 (list (calendar-gregorian-from-absolute (+ abs-p 49))
543 "Erev Shavuot")
544 (list (calendar-gregorian-from-absolute (+ abs-p 51))
545 "Shavuot (second day)")))
546 (output-list
547 (filter-visible-calendar-holidays mandatory)))
548 (if all-hebrew-calendar-holidays
549 (setq output-list
550 (append
551 (filter-visible-calendar-holidays optional)
552 output-list)))
553 output-list)))
555 (defun calendar-holiday-function-tisha-b-av-etc ()
556 "List of dates around Tisha B'Av, as visible in calendar window."
557 (if (or (< displayed-month 5)
558 (> displayed-month 9))
559 nil;; None of the dates is visible
560 (let* ((abs-t-a (calendar-absolute-from-hebrew
561 (list 5 9 (+ displayed-year 3760)))))
563 (filter-visible-calendar-holidays
564 (list
565 (list (calendar-gregorian-from-absolute
566 (if (= (% abs-t-a 7) 6) (- abs-t-a 20) (- abs-t-a 21)))
567 "Tzom Tammuz")
568 (list (calendar-gregorian-from-absolute
569 (calendar-dayname-on-or-before 6 abs-t-a))
570 "Shabbat Hazon")
571 (list (calendar-gregorian-from-absolute
572 (if (= (% abs-t-a 7) 6) (1+ abs-t-a) abs-t-a))
573 "Tisha B'Av")
574 (list (calendar-gregorian-from-absolute
575 (calendar-dayname-on-or-before 6 (+ abs-t-a 7)))
576 "Shabbat Nahamu"))))))
578 (defun filter-visible-calendar-holidays (l)
579 "Return a list of all visible holidays of those on L."
580 (let ((visible)
581 (p l))
582 (while p
583 (if (calendar-date-is-visible-p (car (car p)))
584 (setq visible (append (list (car p)) visible)))
585 (setq p (cdr p)))
586 visible))
588 (provide 'holidays)
590 ;;; holidays.el ends here