(holiday-oriental-holidays): Add more holidays.
[emacs.git] / lisp / calendar / holidays.el
blob8a994c7e269975900bf9bb9d0fd842bc4ba0d4ca
1 ;;; holidays.el --- holiday functions for the calendar package
3 ;; Copyright (C) 1989, 1990, 1992, 1993, 1994, 1997, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
7 ;; Maintainer: Glenn Morris <rgm@gnu.org>
8 ;; Keywords: holidays, calendar
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
27 ;;; Commentary:
29 ;; See calendar.el.
31 ;;; Code:
33 (require 'calendar)
34 (require 'hol-loaddefs)
36 (defgroup holidays nil
37 "Holidays support in calendar."
38 :group 'calendar
39 :prefix "holidays-"
40 :group 'local)
42 ;; The various holiday variables are autoloaded because people
43 ;; are used to using them to set calendar-holidays without having to
44 ;; explicitly load this file.
46 ;;;###autoload
47 (defcustom holiday-general-holidays
48 '((holiday-fixed 1 1 "New Year's Day")
49 (holiday-float 1 1 3 "Martin Luther King Day")
50 (holiday-fixed 2 2 "Groundhog Day")
51 (holiday-fixed 2 14 "Valentine's Day")
52 (holiday-float 2 1 3 "President's Day")
53 (holiday-fixed 3 17 "St. Patrick's Day")
54 (holiday-fixed 4 1 "April Fools' Day")
55 (holiday-float 5 0 2 "Mother's Day")
56 (holiday-float 5 1 -1 "Memorial Day")
57 (holiday-fixed 6 14 "Flag Day")
58 (holiday-float 6 0 3 "Father's Day")
59 (holiday-fixed 7 4 "Independence Day")
60 (holiday-float 9 1 1 "Labor Day")
61 (holiday-float 10 1 2 "Columbus Day")
62 (holiday-fixed 10 31 "Halloween")
63 (holiday-fixed 11 11 "Veteran's Day")
64 (holiday-float 11 4 4 "Thanksgiving"))
65 "General holidays. Default value is for the United States.
66 See the documentation for `calendar-holidays' for details."
67 :type 'sexp
68 :group 'holidays)
69 ;;;###autoload
70 (put 'holiday-general-holidays 'risky-local-variable t)
71 ;;;###autoload
72 (define-obsolete-variable-alias 'general-holidays
73 'holiday-general-holidays "23.1")
75 ;;;###autoload
76 (defcustom holiday-oriental-holidays
77 '((holiday-chinese-new-year)
78 (if calendar-chinese-all-holidays-flag
79 (append
80 (holiday-chinese 1 15 "Lantern Festival")
81 (holiday-chinese-qingming)
82 (holiday-chinese 5 5 "Dragon Boat Festival")
83 (holiday-chinese 7 7 "Double Seventh Festival")
84 (holiday-chinese 8 15 "Mid-Autumn Festival")
85 (holiday-chinese 9 9 "Double Ninth Festival")
86 (holiday-chinese-winter-solstice)
87 )))
88 "Oriental holidays.
89 See the documentation for `calendar-holidays' for details."
90 :version "23.1" ; added more holidays
91 :type 'sexp
92 :group 'holidays)
93 ;;;###autoload
94 (put 'holiday-oriental-holidays 'risky-local-variable t)
95 ;;;###autoload
96 (define-obsolete-variable-alias 'oriental-holidays
97 'holiday-oriental-holidays "23.1")
99 ;;;###autoload
100 (defcustom holiday-local-holidays nil
101 "Local holidays.
102 See the documentation for `calendar-holidays' for details."
103 :type 'sexp
104 :group 'holidays)
105 ;;;###autoload
106 (put 'holiday-local-holidays 'risky-local-variable t)
107 ;;;###autoload
108 (define-obsolete-variable-alias 'local-holidays 'holiday-local-holidays "23.1")
110 ;;;###autoload
111 (defcustom holiday-other-holidays nil
112 "User defined holidays.
113 See the documentation for `calendar-holidays' for details."
114 :type 'sexp
115 :group 'holidays)
116 ;;;###autoload
117 (put 'holiday-other-holidays 'risky-local-variable t)
118 ;;;###autoload
119 (define-obsolete-variable-alias 'other-holidays 'holiday-other-holidays "23.1")
121 ;;;###autoload
122 (defvar hebrew-holidays-1
123 '((holiday-hebrew-rosh-hashanah)
124 (if calendar-hebrew-all-holidays-flag
125 (holiday-julian
127 (let ((m displayed-month)
128 (y displayed-year)
129 year)
130 (calendar-increment-month m y -1)
131 (setq year (calendar-extract-year
132 (calendar-julian-from-absolute
133 (calendar-absolute-from-gregorian (list m 1 y)))))
134 (if (zerop (% (1+ year) 4))
136 21)) "\"Tal Umatar\" (evening)")))
137 "Component of the old default value of `holiday-hebrew-holidays'.")
138 ;;;###autoload
139 (put 'hebrew-holidays-1 'risky-local-variable t)
140 (make-obsolete-variable 'hebrew-holidays-1 'hebrew-holidays "23.1")
142 ;;;###autoload
143 (defvar hebrew-holidays-2
144 '((holiday-hebrew-hanukkah) ; respects calendar-hebrew-all-holidays-flag
145 (if calendar-hebrew-all-holidays-flag
146 (holiday-hebrew
148 (let ((h-year (calendar-extract-year
149 (calendar-hebrew-from-absolute
150 (calendar-absolute-from-gregorian
151 (list displayed-month 28 displayed-year))))))
152 (if (= 6 (% (calendar-hebrew-to-absolute (list 10 10 h-year))
154 11 10))
155 "Tzom Teveth"))
156 (if calendar-hebrew-all-holidays-flag
157 (holiday-hebrew 11 15 "Tu B'Shevat")))
158 "Component of the old default value of `holiday-hebrew-holidays'.")
159 ;;;###autoload
160 (put 'hebrew-holidays-2 'risky-local-variable t)
161 (make-obsolete-variable 'hebrew-holidays-2 'hebrew-holidays "23.1")
163 ;;;###autoload
164 (defvar hebrew-holidays-3
165 '((if calendar-hebrew-all-holidays-flag
166 (holiday-hebrew
168 (let* ((m displayed-month)
169 (y displayed-year)
170 (h-year (progn
171 (calendar-increment-month m y 1)
172 (calendar-extract-year
173 (calendar-hebrew-from-absolute
174 (calendar-absolute-from-gregorian
175 (list m (calendar-last-day-of-month m y) y))))))
176 (s-s
177 (calendar-hebrew-from-absolute
178 (if (= 6
179 (% (calendar-hebrew-to-absolute
180 (list 7 1 h-year))
182 (calendar-dayname-on-or-before
183 6 (calendar-hebrew-to-absolute
184 (list 11 17 h-year)))
185 (calendar-dayname-on-or-before
186 6 (calendar-hebrew-to-absolute
187 (list 11 16 h-year))))))
188 (day (calendar-extract-day s-s)))
189 day)
190 "Shabbat Shirah")))
191 "Component of the old default value of `holiday-hebrew-holidays'.")
192 ;;;###autoload
193 (put 'hebrew-holidays-3 'risky-local-variable t)
194 (make-obsolete-variable 'hebrew-holidays-3 'hebrew-holidays "23.1")
196 ;;;###autoload
197 (defvar hebrew-holidays-4
198 '((holiday-hebrew-passover)
199 (and calendar-hebrew-all-holidays-flag
200 (let* ((m displayed-month)
201 (y displayed-year)
202 (year (progn
203 (calendar-increment-month m y -1)
204 (calendar-extract-year
205 (calendar-julian-from-absolute
206 (calendar-absolute-from-gregorian (list m 1 y)))))))
207 (= 21 (% year 28)))
208 (holiday-julian 3 26 "Kiddush HaHamah"))
209 (if calendar-hebrew-all-holidays-flag
210 (holiday-hebrew-tisha-b-av)))
211 "Component of the old default value of `holiday-hebrew-holidays'.")
212 ;;;###autoload
213 (put 'hebrew-holidays-4 'risky-local-variable t)
214 (make-obsolete-variable 'hebrew-holidays-4 'hebrew-holidays "23.1")
216 ;;;###autoload
217 (defcustom holiday-hebrew-holidays
218 '((holiday-hebrew-passover)
219 (holiday-hebrew-rosh-hashanah)
220 (holiday-hebrew-hanukkah)
221 (if calendar-hebrew-all-holidays-flag
222 (append
223 (holiday-hebrew-tisha-b-av)
224 (holiday-hebrew-misc))))
225 "Jewish holidays.
226 See the documentation for `calendar-holidays' for details."
227 :type 'sexp
228 :version "23.1" ; removed dependency on hebrew-holidays-N
229 :group 'holidays)
230 ;;;###autoload
231 (put 'holiday-hebrew-holidays 'risky-local-variable t)
232 ;;;###autoload
233 (define-obsolete-variable-alias 'hebrew-holidays
234 'holiday-hebrew-holidays "23.1")
236 ;;;###autoload
237 (defcustom holiday-christian-holidays
238 '((holiday-easter-etc) ; respects calendar-christian-all-holidays-flag
239 (holiday-fixed 12 25 "Christmas")
240 (if calendar-christian-all-holidays-flag
241 (append
242 (holiday-fixed 1 6 "Epiphany")
243 (holiday-julian 12 25 "Eastern Orthodox Christmas")
244 (holiday-greek-orthodox-easter)
245 (holiday-fixed 8 15 "Assumption")
246 (holiday-advent 0 "Advent"))))
247 "Christian holidays.
248 See the documentation for `calendar-holidays' for details."
249 :type 'sexp
250 :group 'holidays)
251 ;;;###autoload
252 (put 'holiday-christian-holidays 'risky-local-variable t)
253 ;;;###autoload
254 (define-obsolete-variable-alias 'christian-holidays
255 'holiday-christian-holidays "23.1")
257 ;;;###autoload
258 (defcustom holiday-islamic-holidays
259 '((holiday-islamic-new-year)
260 (holiday-islamic 9 1 "Ramadan Begins")
261 (if calendar-islamic-all-holidays-flag
262 (append
263 (holiday-islamic 1 10 "Ashura")
264 (holiday-islamic 3 12 "Mulad-al-Nabi")
265 (holiday-islamic 7 26 "Shab-e-Mi'raj")
266 (holiday-islamic 8 15 "Shab-e-Bara't")
267 (holiday-islamic 9 27 "Shab-e Qadr")
268 (holiday-islamic 10 1 "Id-al-Fitr")
269 (holiday-islamic 12 10 "Id-al-Adha"))))
270 "Islamic holidays.
271 See the documentation for `calendar-holidays' for details."
272 :type 'sexp
273 :group 'holidays)
274 ;;;###autoload
275 (put 'holiday-islamic-holidays 'risky-local-variable t)
276 ;;;###autoload
277 (define-obsolete-variable-alias 'islamic-holidays
278 'holiday-islamic-holidays "23.1")
280 ;;;###autoload
281 (defcustom holiday-bahai-holidays
282 '((holiday-bahai-new-year)
283 (holiday-bahai-ridvan) ; respects calendar-bahai-all-holidays-flag
284 (holiday-fixed 5 23 "Declaration of the Bab")
285 (holiday-fixed 5 29 "Ascension of Baha'u'llah")
286 (holiday-fixed 7 9 "Martyrdom of the Bab")
287 (holiday-fixed 10 20 "Birth of the Bab")
288 (holiday-fixed 11 12 "Birth of Baha'u'llah")
289 (if calendar-bahai-all-holidays-flag
290 (append
291 (holiday-fixed 11 26 "Day of the Covenant")
292 (holiday-fixed 11 28 "Ascension of `Abdu'l-Baha"))))
293 "Baha'i holidays.
294 See the documentation for `calendar-holidays' for details."
295 :type 'sexp
296 :group 'holidays)
297 ;;;###autoload
298 (put 'holiday-bahai-holidays 'risky-local-variable t)
299 ;;;###autoload
300 (define-obsolete-variable-alias 'bahai-holidays 'holiday-bahai-holidays "23.1")
302 ;;;###autoload
303 (defcustom holiday-solar-holidays
304 '((solar-equinoxes-solstices)
305 (holiday-sexp calendar-daylight-savings-starts
306 (format "Daylight Saving Time Begins %s"
307 (solar-time-string
308 (/ calendar-daylight-savings-starts-time (float 60))
309 calendar-standard-time-zone-name)))
310 (holiday-sexp calendar-daylight-savings-ends
311 (format "Daylight Saving Time Ends %s"
312 (solar-time-string
313 (/ calendar-daylight-savings-ends-time (float 60))
314 calendar-daylight-time-zone-name))))
315 "Sun-related holidays.
316 See the documentation for `calendar-holidays' for details."
317 :type 'sexp
318 :group 'holidays)
319 ;;;###autoload
320 (put 'holiday-solar-holidays 'risky-local-variable t)
321 ;;;###autoload
322 (define-obsolete-variable-alias 'solar-holidays 'holiday-solar-holidays "23.1")
324 ;;;###autoload
325 (defcustom calendar-holidays
326 (append holiday-general-holidays holiday-local-holidays
327 holiday-other-holidays holiday-christian-holidays
328 holiday-hebrew-holidays holiday-islamic-holidays
329 holiday-bahai-holidays holiday-oriental-holidays
330 holiday-solar-holidays)
331 "List of notable days for the command \\[holidays].
333 Additional holidays are easy to add to the list, just put them in the
334 list `holiday-other-holidays' in your .emacs file. Similarly, by setting
335 any of `holiday-general-holidays', `holiday-local-holidays',
336 `holiday-christian-holidays', `holiday-hebrew-holidays',
337 `holiday-islamic-holidays', `holiday-bahai-holidays',
338 `holiday-oriental-holidays', or `holiday-solar-holidays' to nil in your
339 .emacs file, you can eliminate unwanted categories of holidays.
341 The aforementioned variables control the holiday choices offered
342 by the function `holiday-list' when it is called interactively.
344 They also initialize the default value of `calendar-holidays',
345 which is the default list of holidays used by the function
346 `holiday-list' in the non-interactive case. Note that these
347 variables have no effect on `calendar-holidays' after it has been
348 set (e.g. after the calendar is loaded). In that case, customize
349 `calendar-holidays' directly.
351 The intention is that (in the US) `holiday-local-holidays' be set in
352 site-init.el and `holiday-other-holidays' be set by the user.
354 Entries on the list are expressions that return (possibly empty) lists of
355 items of the form ((month day year) string) of a holiday in the
356 three-month period centered around `displayed-month' of `displayed-year'.
357 Several basic functions are provided for this purpose:
359 (holiday-fixed MONTH DAY STRING) is a fixed date on the Gregorian calendar
360 (holiday-float MONTH DAYNAME K STRING &optional day) is the Kth DAYNAME in
361 MONTH on the Gregorian calendar (0 for Sunday,
362 etc.); K<0 means count back from the end of the
363 month. An optional parameter DAY means the Kth
364 DAYNAME after/before MONTH DAY.
365 (holiday-hebrew MONTH DAY STRING) a fixed date on the Hebrew calendar
366 (holiday-islamic MONTH DAY STRING) a fixed date on the Islamic calendar
367 (holiday-bahai MONTH DAY STRING) a fixed date on the Baha'i calendar
368 (holiday-julian MONTH DAY STRING) a fixed date on the Julian calendar
369 (holiday-sexp SEXP STRING) SEXP is a Gregorian-date-valued expression
370 in the variable `year'; if it evaluates to
371 a visible date, that's the holiday; if it
372 evaluates to nil, there's no holiday. STRING
373 is an expression in the variable `date'.
375 For example, to add Bastille Day, celebrated in France on July 14, add
377 (holiday-fixed 7 14 \"Bastille Day\")
379 to the list. To add Hurricane Supplication Day, celebrated in the Virgin
380 Islands on the fourth Monday in August, add
382 (holiday-float 8 1 4 \"Hurricane Supplication Day\")
384 to the list (the last Monday would be specified with `-1' instead of `4').
385 To add the last day of Hanukkah to the list, use
387 (holiday-hebrew 10 2 \"Last day of Hanukkah\")
389 since the Hebrew months are numbered with 1 starting from Nisan.
390 To add the Islamic feast celebrating Mohammed's birthday, use
392 (holiday-islamic 3 12 \"Mohammed's Birthday\")
394 since the Islamic months are numbered from 1 starting with Muharram.
395 To add an entry for the Baha'i festival of Ridvan, use
397 (holiday-bahai 2 13 \"Festival of Ridvan\")
399 since the Baha'i months are numbered from 1 starting with Baha.
400 To add Thomas Jefferson's birthday, April 2, 1743 (Julian), use
402 (holiday-julian 4 2 \"Jefferson's Birthday\")
404 To include a holiday conditionally, use the sexp form or a conditional. For
405 example, to include American presidential elections, which occur on the first
406 Tuesday after the first Monday in November of years divisible by 4, add
408 (holiday-sexp
409 '(if (zerop (% year 4))
410 (calendar-gregorian-from-absolute
411 (1+ (calendar-dayname-on-or-before
412 1 (+ 6 (calendar-absolute-from-gregorian
413 (list 11 1 year)))))))
414 \"US Presidential Election\")
418 (if (zerop (% displayed-year 4))
419 (holiday-fixed 11
420 (calendar-extract-day
421 (calendar-gregorian-from-absolute
422 (1+ (calendar-dayname-on-or-before
423 1 (+ 6 (calendar-absolute-from-gregorian
424 (list 11 1 displayed-year)))))))
425 \"US Presidential Election\"))
427 to the list. To include the phases of the moon, add
429 (lunar-phases)
431 to the holiday list, where `lunar-phases' is an Emacs-Lisp function that
432 you've written to return a (possibly empty) list of the relevant VISIBLE dates
433 with descriptive strings such as
435 (((2 6 1989) \"New Moon\") ((2 12 1989) \"First Quarter Moon\") ... )."
436 :type 'sexp
437 :group 'holidays)
438 ;;;###autoload
439 (put 'calendar-holidays 'risky-local-variable t)
441 ;;; End of user options.
444 ;; FIXME name that makes sense
445 ;;;###diary-autoload
446 (defun calendar-holiday-list ()
447 "Form the list of holidays that occur on dates in the calendar window.
448 The holidays are those in the list `calendar-holidays'."
449 (let (res h)
450 (sort
451 (dolist (p calendar-holidays res)
452 (if (setq h (if calendar-debug-sexp
453 (let ((stack-trace-on-error t))
454 (eval p))
455 (condition-case nil
456 (eval p)
457 (error (beep)
458 (message "Bad holiday list item: %s" p)
459 (sleep-for 2)))))
460 (setq res (append h res))))
461 'calendar-date-compare)))
463 (defvar displayed-month) ; from calendar-generate
464 (defvar displayed-year)
466 ;; FIXME name that makes sense
467 ;;;###cal-autoload
468 (defun calendar-list-holidays ()
469 "Create a buffer containing the holidays for the current calendar window.
470 The holidays are those in the list `calendar-notable-days'.
471 Returns non-nil if any holidays are found."
472 (interactive)
473 (message "Looking up holidays...")
474 (let ((holiday-list (calendar-holiday-list))
475 (m1 displayed-month)
476 (y1 displayed-year)
477 (m2 displayed-month)
478 (y2 displayed-year))
479 (if (not holiday-list)
480 (message "Looking up holidays...none found")
481 (calendar-in-read-only-buffer holiday-buffer
482 (calendar-increment-month m1 y1 -1)
483 (calendar-increment-month m2 y2 1)
484 (calendar-set-mode-line
485 (if (= y1 y2)
486 (format "Notable Dates from %s to %s, %d%%-"
487 (calendar-month-name m1) (calendar-month-name m2) y2)
488 (format "Notable Dates from %s, %d to %s, %d%%-"
489 (calendar-month-name m1) y1 (calendar-month-name m2) y2)))
490 (insert
491 (mapconcat
492 (lambda (x) (concat (calendar-date-string (car x))
493 ": " (cadr x)))
494 holiday-list "\n")))
495 (message "Looking up holidays...done"))
496 holiday-list))
498 (define-obsolete-function-alias
499 'list-calendar-holidays 'calendar-list-holidays "23.1")
501 ;;;###autoload
502 (defun holidays (&optional arg)
503 "Display the holidays for last month, this month, and next month.
504 If called with an optional prefix argument ARG, prompts for month and year.
505 This function is suitable for execution in a .emacs file."
506 (interactive "P")
507 (save-excursion
508 (let* ((completion-ignore-case t)
509 (date (if arg (calendar-read-date t)
510 (calendar-current-date)))
511 (displayed-month (calendar-extract-month date))
512 (displayed-year (calendar-extract-year date)))
513 (calendar-list-holidays))))
515 ;; rms: "Emacs commands to display a list of something generally start
516 ;; with `list-'. Please make `list-holidays' the principal name."
517 ;;;###autoload
518 (defun list-holidays (y1 &optional y2 l label)
519 "Display holidays for years Y1 to Y2 (inclusive).
520 Y2 defaults to Y1. The optional list of holidays L defaults to
521 `calendar-holidays'. If you want to control what holidays are
522 displayed, use a different list. For example,
524 (list-holidays 2006 2006
525 (append holiday-general-holidays holiday-local-holidays))
527 will display holidays for the year 2006 defined in the two
528 mentioned lists, and nothing else.
530 When called interactively, this command offers a choice of
531 holidays, based on the variables `holiday-solar-holidays' etc. See the
532 documentation of `calendar-holidays' for a list of the variables
533 that control the choices, as well as a description of the format
534 of a holiday list.
536 The optional LABEL is used to label the buffer created."
537 (interactive
538 (let* ((start-year (calendar-read
539 "Starting year of holidays (>0): "
540 (lambda (x) (> x 0))
541 (number-to-string (calendar-extract-year
542 (calendar-current-date)))))
543 (end-year (calendar-read
544 (format "Ending year (inclusive) of holidays (>=%s): "
545 start-year)
546 (lambda (x) (>= x start-year))
547 (number-to-string start-year)))
548 (completion-ignore-case t)
549 (lists
550 (list
551 (cons "All" calendar-holidays)
552 (cons "Equinoxes/Solstices"
553 (list (list 'solar-equinoxes-solstices)))
554 (if holiday-general-holidays
555 (cons "General" holiday-general-holidays))
556 (if holiday-local-holidays
557 (cons "Local" holiday-local-holidays))
558 (if holiday-other-holidays
559 (cons "Other" holiday-other-holidays))
560 (if holiday-christian-holidays
561 (cons "Christian" holiday-christian-holidays))
562 (if holiday-hebrew-holidays
563 (cons "Hebrew" holiday-hebrew-holidays))
564 (if holiday-islamic-holidays
565 (cons "Islamic" holiday-islamic-holidays))
566 (if holiday-bahai-holidays
567 (cons "Baha'i" holiday-bahai-holidays))
568 (if holiday-oriental-holidays
569 (cons "Oriental" holiday-oriental-holidays))
570 (if holiday-solar-holidays
571 (cons "Solar" holiday-solar-holidays))
572 (cons "Ask" nil)))
573 (choice (capitalize
574 (completing-read "List (TAB for choices): " lists nil t)))
575 (which (if (string-equal choice "Ask")
576 (eval (read-variable "Enter list name: "))
577 (cdr (assoc choice lists))))
578 (name (if (string-equal choice "Equinoxes/Solstices")
579 choice
580 (if (member choice '("Ask" ""))
581 "Holidays"
582 (format "%s Holidays" choice)))))
583 (list start-year end-year which name)))
584 (unless y2 (setq y2 y1))
585 (message "Computing holidays...")
586 (let ((calendar-holidays (or l calendar-holidays))
587 (title (or label "Holidays"))
588 (s (calendar-absolute-from-gregorian (list 2 1 y1)))
589 (e (calendar-absolute-from-gregorian (list 11 1 y2)))
590 (displayed-month 2)
591 (displayed-year y1)
592 holiday-list)
593 (while (<= s e)
594 (setq holiday-list (append holiday-list (calendar-holiday-list)))
595 (calendar-increment-month displayed-month displayed-year 3)
596 (setq s (calendar-absolute-from-gregorian
597 (list displayed-month 1 displayed-year))))
598 (save-excursion
599 (calendar-in-read-only-buffer holiday-buffer
600 (calendar-set-mode-line
601 (if (= y1 y2)
602 (format "%s for %s" title y1)
603 (format "%s for %s-%s" title y1 y2)))
604 (insert
605 (mapconcat
606 (lambda (x) (concat (calendar-date-string (car x))
607 ": " (cadr x)))
608 holiday-list "\n")))
609 (message "Computing holidays...done"))))
611 ;;;###autoload
612 (defalias 'holiday-list 'list-holidays)
614 ;;;###diary-autoload
615 (defun calendar-check-holidays (date)
616 "Check the list of holidays for any that occur on DATE.
617 The value returned is a list of strings of relevant holiday descriptions.
618 The holidays are those in the list `calendar-holidays'."
619 (let ((displayed-month (calendar-extract-month date))
620 (displayed-year (calendar-extract-year date))
621 holiday-list)
622 (dolist (h (calendar-holiday-list) holiday-list)
623 (if (calendar-date-equal date (car h))
624 (setq holiday-list (append holiday-list (cdr h)))))))
626 (define-obsolete-function-alias
627 'check-calendar-holidays 'calendar-check-holidays "23.1")
629 ;;;###cal-autoload
630 (defun calendar-cursor-holidays ()
631 "Find holidays for the date specified by the cursor in the calendar window."
632 (interactive)
633 (message "Checking holidays...")
634 (let* ((date (calendar-cursor-to-date t))
635 (date-string (calendar-date-string date))
636 (holiday-list (calendar-check-holidays date))
637 (holiday-string (mapconcat 'identity holiday-list "; "))
638 (msg (format "%s: %s" date-string holiday-string)))
639 (if (not holiday-list)
640 (message "No holidays known for %s" date-string)
641 (if (<= (length msg) (frame-width))
642 (message "%s" msg)
643 (calendar-in-read-only-buffer holiday-buffer
644 (calendar-set-mode-line date-string)
645 (insert (mapconcat 'identity holiday-list "\n")))
646 (message "Checking holidays...done")))))
648 ;; FIXME move to calendar?
649 ;;;###cal-autoload
650 (defun calendar-mark-holidays ()
651 "Mark notable days in the calendar window."
652 (interactive)
653 (setq calendar-mark-holidays-flag t)
654 (message "Marking holidays...")
655 (dolist (holiday (calendar-holiday-list))
656 (calendar-mark-visible-date (car holiday) calendar-holiday-marker))
657 (message "Marking holidays...done"))
659 (define-obsolete-function-alias
660 'mark-calendar-holidays 'calendar-mark-holidays "23.1")
662 ;; Below are the functions that calculate the dates of holidays; these
663 ;; are eval'ed in the function calendar-holiday-list. If you
664 ;; write other such functions, be sure to imitate the style used below.
665 ;; Remember that each function must return a list of items of the form
666 ;; ((month day year) string) of VISIBLE dates in the calendar window.
668 (defun holiday-fixed (month day string)
669 "Holiday on MONTH, DAY (Gregorian) called STRING.
670 If MONTH, DAY is visible, the value returned is the list (((MONTH DAY year)
671 STRING)). Returns nil if it is not visible in the current calendar window."
672 ;; This determines whether a given month is visible in the calendar.
673 ;; cf calendar-date-is-visible-p (which also checks the year part).
674 ;; The day is irrelevant since only full months are displayed.
675 ;; Since the calendar displays three months at a time, month N
676 ;; is visible if displayed-month = N-1, N, N+1.
677 ;; In particular, November is visible if d-m = 10, 11, 12.
678 ;; This is useful, because we can do a one-sided test:
679 ;; November is visible if d-m > 9. (Similarly, February is visible if
680 ;; d-m < 4.)
681 ;; To determine if December is visible, we can shift the calendar
682 ;; back a month and ask if November is visible; to determine if
683 ;; October is visible, we can shift it forward a month and ask if
684 ;; November is visible; etc.
685 (let ((m displayed-month)
686 (y displayed-year))
687 (calendar-increment-month m y (- 11 month))
688 (if (> m 9) ; is november visible?
689 (list (list (list month day y) string)))))
691 (defun holiday-float (month dayname n string &optional day)
692 "Holiday on MONTH, DAYNAME (Nth occurrence) called STRING.
693 If the Nth DAYNAME in MONTH is visible, the value returned is the list
694 \(((MONTH DAY year) STRING)).
696 If N<0, count backward from the end of MONTH.
698 An optional parameter DAY means the Nth DAYNAME on or after/before MONTH DAY.
700 Returns nil if it is not visible in the current calendar window."
701 ;; This is messy because the holiday may be visible, while the date
702 ;; on which it is based is not. For example, the first Monday after
703 ;; December 30 may be visible when January is not. For large values
704 ;; of |n| the problem is more grotesque. If we didn't have to worry
705 ;; about such cases, we could just use the original version of this
706 ;; function:
707 ;; (let ((m displayed-month)
708 ;; (y displayed-year))
709 ;; (calendar-increment-month m y (- 11 month))
710 ;; (if (> m 9); month in year y is visible
711 ;; (list (list (calendar-nth-named-day n dayname month y day) string)))))
712 (let* ((m1 displayed-month)
713 (y1 displayed-year)
714 (m2 displayed-month)
715 (y2 displayed-year)
716 (d1 (progn ; first possible base date for holiday
717 (calendar-increment-month m1 y1 -1)
718 (+ (calendar-nth-named-absday 1 dayname m1 y1)
719 (* -7 n)
720 (if (> n 0) 1 -7))))
721 (d2 ; last possible base date for holiday
722 (progn
723 (calendar-increment-month m2 y2 1)
724 (+ (calendar-nth-named-absday -1 dayname m2 y2)
725 (* -7 n)
726 (if (> n 0) 7 -1))))
727 (y1 (calendar-extract-year (calendar-gregorian-from-absolute d1)))
728 (y2 (calendar-extract-year (calendar-gregorian-from-absolute d2)))
729 (y ; year of base date
730 (if (or (= y1 y2) (> month 9))
732 y2))
733 (d ; day of base date
734 (or day (if (> n 0)
736 (calendar-last-day-of-month month y))))
737 (date ; base date for holiday
738 (calendar-absolute-from-gregorian (list month d y))))
739 (and (<= d1 date) (<= date d2)
740 (list (list (calendar-nth-named-day n dayname month y d)
741 string)))))
743 (defun holiday-filter-visible-calendar (hlist)
744 "Filter list of holidays HLIST, and return only the visible ones.
745 HLIST is a list of elements of the form (DATE) TEXT."
746 (delq nil (mapcar (lambda (p)
747 (and (car p) (calendar-date-is-visible-p (car p)) p))
748 hlist)))
750 (define-obsolete-function-alias
751 'filter-visible-calendar-holidays 'holiday-filter-visible-calendar "23.1")
753 (defun holiday-sexp (sexp string)
754 "Sexp holiday for dates in the calendar window.
755 SEXP is an expression in variable `year' that is evaluated to
756 give `date'. STRING is an expression in `date' that evaluates to
757 the holiday description of `date'. If `date' is visible in the
758 calendar window, the holiday STRING is on that date. If date is
759 nil, or if the date is not visible, there is no holiday."
760 (let ((m displayed-month)
761 (y displayed-year)
762 year date)
763 (calendar-increment-month m y -1)
764 (holiday-filter-visible-calendar
765 (list
766 (progn
767 (setq year y
768 date (eval sexp))
769 (list date (if date (eval string))))
770 (progn
771 (setq year (1+ y)
772 date (eval sexp))
773 (list date (if date (eval string))))))))
776 (defun holiday-advent (&optional n string)
777 "Date of Nth day after advent (named STRING), if visible in calendar window.
778 Negative values of N are interpreted as days before advent.
779 STRING is used purely for display purposes. The return value has
780 the form ((MONTH DAY YEAR) STRING), where the date is that of the
781 Nth day before or after advent.
783 For backwards compatibility, if this function is called with no
784 arguments, then it returns the value appropriate for advent itself."
785 ;; Backwards compatibility layer.
786 (if (not n)
787 (holiday-advent 0 "Advent")
788 (let* ((year displayed-year)
789 (month displayed-month)
790 (advent (progn
791 (calendar-increment-month month year -1)
792 (calendar-gregorian-from-absolute
793 (+ n
794 (calendar-dayname-on-or-before
796 (calendar-absolute-from-gregorian
797 (list 12 3 year))))))))
798 (if (calendar-date-is-visible-p advent)
799 (list (list advent string))))))
801 (defun holiday-easter-etc (&optional n string)
802 "Date of Nth day after Easter (named STRING), if visible in calendar window.
803 Negative values of N are interpreted as days before Easter.
804 STRING is used purely for display purposes. The return value has
805 the form ((MONTH DAY YEAR) STRING), where the date is that of the
806 Nth day before or after Easter.
808 For backwards compatibility, if this function is called with no
809 arguments, then it returns a list of \"standard\" Easter-related
810 holidays (with more entries if `calendar-christian-all-holidays-flag'
811 is non-nil)."
812 ;; Backwards compatibility layer.
813 (if (not n)
814 (apply 'append
815 (mapcar (lambda (e)
816 (apply 'holiday-easter-etc e))
817 ;; The combined list is not in order.
818 (append
819 (if calendar-christian-all-holidays-flag
820 '((-63 "Septuagesima Sunday")
821 (-56 "Sexagesima Sunday")
822 (-49 "Shrove Sunday")
823 (-48 "Shrove Monday")
824 (-47 "Shrove Tuesday")
825 (-14 "Passion Sunday")
826 (-7 "Palm Sunday")
827 (-3 "Maundy Thursday")
828 (35 "Rogation Sunday")
829 (39 "Ascension Day")
830 (49 "Pentecost (Whitsunday)")
831 (50 "Whitmonday")
832 (56 "Trinity Sunday")
833 (60 "Corpus Christi")))
834 '((-46 "Ash Wednesday")
835 (-2 "Good Friday")
836 (0 "Easter Sunday")))))
837 (let* ((century (1+ (/ displayed-year 100)))
838 (shifted-epact ; age of moon for April 5...
839 (% (+ 14 (* 11 (% displayed-year 19)) ; ...by Nicaean rule
840 (- ; ...corrected for the Gregorian century rule
841 (/ (* 3 century) 4))
842 (/ ; ...corrected for Metonic cycle inaccuracy
843 (+ 5 (* 8 century)) 25)
844 (* 30 century)) ; keeps value positive
845 30))
846 (adjusted-epact ; adjust for 29.5 day month
847 (if (or (zerop shifted-epact)
848 (and (= shifted-epact 1) (< 10 (% displayed-year 19))))
849 (1+ shifted-epact)
850 shifted-epact))
851 (paschal-moon ; day after the full moon on or after March 21
852 (- (calendar-absolute-from-gregorian (list 4 19 displayed-year))
853 adjusted-epact))
854 (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))
855 (greg (calendar-gregorian-from-absolute (+ abs-easter n))))
856 (if (calendar-date-is-visible-p greg)
857 (list (list greg string))))))
859 ;; Prior call to calendar-julian-from-absolute will autoload cal-julian.
860 (declare-function calendar-julian-to-absolute "cal-julian" (date))
862 (defun holiday-greek-orthodox-easter ()
863 "Date of Easter according to the rule of the Council of Nicaea."
864 (let* ((m displayed-month)
865 (y displayed-year)
866 (julian-year (progn
867 (calendar-increment-month m y 1)
868 (calendar-extract-year
869 (calendar-julian-from-absolute
870 (calendar-absolute-from-gregorian
871 (list m (calendar-last-day-of-month m y) y))))))
872 (shifted-epact ; age of moon for April 5
873 (% (+ 14
874 (* 11 (% julian-year 19)))
875 30))
876 (paschal-moon ; day after full moon on or after March 21
877 (- (calendar-julian-to-absolute (list 4 19 julian-year))
878 shifted-epact))
879 (nicaean-easter ; Sunday following the Paschal moon
880 (calendar-gregorian-from-absolute
881 (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))))
882 (if (calendar-date-is-visible-p nicaean-easter)
883 (list (list nicaean-easter "Pascha (Greek Orthodox Easter)")))))
885 (provide 'holidays)
887 ;; arch-tag: 48eb3117-75a7-4dbe-8fd9-873c3cbb0d37
888 ;;; holidays.el ends here