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, 2009, 2010 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 of the License, or
15 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
32 (load "hol-loaddefs" nil t
)
34 (defgroup holidays nil
35 "Holidays support in calendar."
40 ;; The various holiday variables are autoloaded because people
41 ;; are used to using them to set calendar-holidays without having to
42 ;; explicitly load this file.
45 (defcustom holiday-general-holidays
47 '((holiday-fixed 1 1 "New Year's Day")
48 (holiday-float 1 1 3 "Martin Luther King Day")
49 (holiday-fixed 2 2 "Groundhog Day")
50 (holiday-fixed 2 14 "Valentine's Day")
51 (holiday-float 2 1 3 "President's Day")
52 (holiday-fixed 3 17 "St. Patrick's Day")
53 (holiday-fixed 4 1 "April Fools' Day")
54 (holiday-float 5 0 2 "Mother's Day")
55 (holiday-float 5 1 -
1 "Memorial Day")
56 (holiday-fixed 6 14 "Flag Day")
57 (holiday-float 6 0 3 "Father's Day")
58 (holiday-fixed 7 4 "Independence Day")
59 (holiday-float 9 1 1 "Labor Day")
60 (holiday-float 10 1 2 "Columbus Day")
61 (holiday-fixed 10 31 "Halloween")
62 (holiday-fixed 11 11 "Veteran's Day")
63 (holiday-float 11 4 4 "Thanksgiving")))
64 "General holidays. Default value is for the United States.
65 See the documentation for `calendar-holidays' for details."
69 (put 'holiday-general-holidays
'risky-local-variable t
)
71 (define-obsolete-variable-alias 'general-holidays
72 'holiday-general-holidays
"23.1")
75 (defcustom holiday-oriental-holidays
77 '((holiday-chinese-new-year)
78 (if calendar-chinese-all-holidays-flag
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)
89 See the documentation for `calendar-holidays' for details."
90 :version
"23.1" ; added more holidays
94 (put 'holiday-oriental-holidays
'risky-local-variable t
)
96 (define-obsolete-variable-alias 'oriental-holidays
97 'holiday-oriental-holidays
"23.1")
100 (defcustom holiday-local-holidays nil
102 See the documentation for `calendar-holidays' for details."
106 (put 'holiday-local-holidays
'risky-local-variable t
)
108 (define-obsolete-variable-alias 'local-holidays
'holiday-local-holidays
"23.1")
111 (defcustom holiday-other-holidays nil
112 "User defined holidays.
113 See the documentation for `calendar-holidays' for details."
117 (put 'holiday-other-holidays
'risky-local-variable t
)
119 (define-obsolete-variable-alias 'other-holidays
'holiday-other-holidays
"23.1")
122 (defvar hebrew-holidays-1
124 '((holiday-hebrew-rosh-hashanah)
125 (if calendar-hebrew-all-holidays-flag
128 (let ((m displayed-month
)
131 (calendar-increment-month m y -
1)
132 (setq year
(calendar-extract-year
133 (calendar-julian-from-absolute
134 (calendar-absolute-from-gregorian (list m
1 y
)))))
135 (if (zerop (%
(1+ year
) 4))
137 21)) "\"Tal Umatar\" (evening)"))))
138 "Component of the old default value of `holiday-hebrew-holidays'.")
140 (put 'hebrew-holidays-1
'risky-local-variable t
)
141 (make-obsolete-variable 'hebrew-holidays-1
'hebrew-holidays
"23.1")
144 (defvar hebrew-holidays-2
146 '((holiday-hebrew-hanukkah) ; respects calendar-hebrew-all-holidays-flag
147 (if calendar-hebrew-all-holidays-flag
150 (let ((h-year (calendar-extract-year
151 (calendar-hebrew-from-absolute
152 (calendar-absolute-from-gregorian
153 (list displayed-month
28 displayed-year
))))))
154 (if (= 6 (%
(calendar-hebrew-to-absolute (list 10 10 h-year
))
158 (if calendar-hebrew-all-holidays-flag
159 (holiday-hebrew 11 15 "Tu B'Shevat"))))
160 "Component of the old default value of `holiday-hebrew-holidays'.")
162 (put 'hebrew-holidays-2
'risky-local-variable t
)
163 (make-obsolete-variable 'hebrew-holidays-2
'hebrew-holidays
"23.1")
166 (defvar hebrew-holidays-3
168 '((if calendar-hebrew-all-holidays-flag
171 (let* ((m displayed-month
)
174 (calendar-increment-month m y
1)
175 (calendar-extract-year
176 (calendar-hebrew-from-absolute
177 (calendar-absolute-from-gregorian
178 (list m
(calendar-last-day-of-month m y
) y
))))))
180 (calendar-hebrew-from-absolute
182 (%
(calendar-hebrew-to-absolute
185 (calendar-dayname-on-or-before
186 6 (calendar-hebrew-to-absolute
187 (list 11 17 h-year
)))
188 (calendar-dayname-on-or-before
189 6 (calendar-hebrew-to-absolute
190 (list 11 16 h-year
))))))
191 (day (calendar-extract-day s-s
)))
194 "Component of the old default value of `holiday-hebrew-holidays'.")
196 (put 'hebrew-holidays-3
'risky-local-variable t
)
197 (make-obsolete-variable 'hebrew-holidays-3
'hebrew-holidays
"23.1")
200 (defvar hebrew-holidays-4
202 '((holiday-hebrew-passover)
203 (and calendar-hebrew-all-holidays-flag
204 (let* ((m displayed-month
)
207 (calendar-increment-month m y -
1)
208 (calendar-extract-year
209 (calendar-julian-from-absolute
210 (calendar-absolute-from-gregorian (list m
1 y
)))))))
212 (holiday-julian 3 26 "Kiddush HaHamah"))
213 (if calendar-hebrew-all-holidays-flag
214 (holiday-hebrew-tisha-b-av))))
215 "Component of the old default value of `holiday-hebrew-holidays'.")
217 (put 'hebrew-holidays-4
'risky-local-variable t
)
218 (make-obsolete-variable 'hebrew-holidays-4
'hebrew-holidays
"23.1")
221 (defcustom holiday-hebrew-holidays
223 '((holiday-hebrew-passover)
224 (holiday-hebrew-rosh-hashanah)
225 (holiday-hebrew-hanukkah)
226 (if calendar-hebrew-all-holidays-flag
228 (holiday-hebrew-tisha-b-av)
229 (holiday-hebrew-misc)))))
231 See the documentation for `calendar-holidays' for details."
233 :version
"23.1" ; removed dependency on hebrew-holidays-N
236 (put 'holiday-hebrew-holidays
'risky-local-variable t
)
238 (define-obsolete-variable-alias 'hebrew-holidays
239 'holiday-hebrew-holidays
"23.1")
242 (defcustom holiday-christian-holidays
244 '((holiday-easter-etc) ; respects calendar-christian-all-holidays-flag
245 (holiday-fixed 12 25 "Christmas")
246 (if calendar-christian-all-holidays-flag
248 (holiday-fixed 1 6 "Epiphany")
249 (holiday-julian 12 25 "Eastern Orthodox Christmas")
250 (holiday-greek-orthodox-easter)
251 (holiday-fixed 8 15 "Assumption")
252 (holiday-advent 0 "Advent")))))
254 See the documentation for `calendar-holidays' for details."
258 (put 'holiday-christian-holidays
'risky-local-variable t
)
260 (define-obsolete-variable-alias 'christian-holidays
261 'holiday-christian-holidays
"23.1")
264 (defcustom holiday-islamic-holidays
266 '((holiday-islamic-new-year)
267 (holiday-islamic 9 1 "Ramadan Begins")
268 (if calendar-islamic-all-holidays-flag
270 (holiday-islamic 1 10 "Ashura")
271 (holiday-islamic 3 12 "Mulad-al-Nabi")
272 (holiday-islamic 7 26 "Shab-e-Mi'raj")
273 (holiday-islamic 8 15 "Shab-e-Bara't")
274 (holiday-islamic 9 27 "Shab-e Qadr")
275 (holiday-islamic 10 1 "Id-al-Fitr")
276 (holiday-islamic 12 10 "Id-al-Adha")))))
278 See the documentation for `calendar-holidays' for details."
282 (put 'holiday-islamic-holidays
'risky-local-variable t
)
284 (define-obsolete-variable-alias 'islamic-holidays
285 'holiday-islamic-holidays
"23.1")
288 (defcustom holiday-bahai-holidays
290 '((holiday-bahai-new-year)
291 (holiday-bahai-ridvan) ; respects calendar-bahai-all-holidays-flag
292 (holiday-fixed 5 23 "Declaration of the Bab")
293 (holiday-fixed 5 29 "Ascension of Baha'u'llah")
294 (holiday-fixed 7 9 "Martyrdom of the Bab")
295 (holiday-fixed 10 20 "Birth of the Bab")
296 (holiday-fixed 11 12 "Birth of Baha'u'llah")
297 (if calendar-bahai-all-holidays-flag
299 (holiday-fixed 11 26 "Day of the Covenant")
300 (holiday-fixed 11 28 "Ascension of `Abdu'l-Baha")))))
302 See the documentation for `calendar-holidays' for details."
306 (put 'holiday-bahai-holidays
'risky-local-variable t
)
308 (define-obsolete-variable-alias 'bahai-holidays
'holiday-bahai-holidays
"23.1")
311 (defcustom holiday-solar-holidays
313 '((solar-equinoxes-solstices)
314 (holiday-sexp calendar-daylight-savings-starts
315 (format "Daylight Saving Time Begins %s"
317 (/ calendar-daylight-savings-starts-time
(float 60))
318 calendar-standard-time-zone-name
)))
319 (holiday-sexp calendar-daylight-savings-ends
320 (format "Daylight Saving Time Ends %s"
322 (/ calendar-daylight-savings-ends-time
(float 60))
323 calendar-daylight-time-zone-name
)))))
324 "Sun-related holidays.
325 See the documentation for `calendar-holidays' for details."
329 (put 'holiday-solar-holidays
'risky-local-variable t
)
331 (define-obsolete-variable-alias 'solar-holidays
'holiday-solar-holidays
"23.1")
333 ;; This one should not be autoloaded, else .emacs changes of
334 ;; holiday-general-holidays etc have no effect.
335 ;; FIXME should have some :set-after.
336 (defcustom calendar-holidays
337 (append holiday-general-holidays holiday-local-holidays
338 holiday-other-holidays holiday-christian-holidays
339 holiday-hebrew-holidays holiday-islamic-holidays
340 holiday-bahai-holidays holiday-oriental-holidays
341 holiday-solar-holidays
)
342 "List of notable days for the command \\[holidays].
344 Additional holidays are easy to add to the list, just put them in the
345 list `holiday-other-holidays' in your .emacs file. Similarly, by setting
346 any of `holiday-general-holidays', `holiday-local-holidays',
347 `holiday-christian-holidays', `holiday-hebrew-holidays',
348 `holiday-islamic-holidays', `holiday-bahai-holidays',
349 `holiday-oriental-holidays', or `holiday-solar-holidays' to nil in your
350 .emacs file, you can eliminate unwanted categories of holidays.
352 The aforementioned variables control the holiday choices offered
353 by the function `holiday-list' when it is called interactively.
355 They also initialize the default value of `calendar-holidays',
356 which is the default list of holidays used by the function
357 `holiday-list' in the non-interactive case. Note that these
358 variables have no effect on `calendar-holidays' after it has been
359 set (e.g. after the calendar is loaded). In that case, customize
360 `calendar-holidays' directly.
362 The intention is that (in the US) `holiday-local-holidays' be set in
363 site-init.el and `holiday-other-holidays' be set by the user.
365 Entries on the list are expressions that return (possibly empty) lists of
366 items of the form ((month day year) string) of a holiday in the
367 three-month period centered around `displayed-month' of `displayed-year'.
368 Several basic functions are provided for this purpose:
370 (holiday-fixed MONTH DAY STRING) is a fixed date on the Gregorian calendar
371 (holiday-float MONTH DAYNAME K STRING &optional DAY) is the Kth DAYNAME
372 (0 for Sunday, etc.) after/before Gregorian
373 MONTH DAY. K<0 means count back from the end
374 of the month. Optional DAY defaults to 1 if
375 K>0, and MONTH's last day otherwise.
376 (holiday-hebrew MONTH DAY STRING) a fixed date on the Hebrew calendar
377 (holiday-islamic MONTH DAY STRING) a fixed date on the Islamic calendar
378 (holiday-bahai MONTH DAY STRING) a fixed date on the Baha'i calendar
379 (holiday-julian MONTH DAY STRING) a fixed date on the Julian calendar
380 (holiday-sexp SEXP STRING) SEXP is a Gregorian-date-valued expression
381 in the variable `year'; if it evaluates to
382 a visible date, that's the holiday; if it
383 evaluates to nil, there's no holiday. STRING
384 is an expression in the variable `date'.
386 For example, to add Bastille Day, celebrated in France on July 14, add
388 (holiday-fixed 7 14 \"Bastille Day\")
390 to the list. To add Hurricane Supplication Day, celebrated in the Virgin
391 Islands on the fourth Monday in August, add
393 (holiday-float 8 1 4 \"Hurricane Supplication Day\")
395 to the list (the last Monday would be specified with `-1' instead of `4').
396 To add the last day of Hanukkah to the list, use
398 (holiday-hebrew 10 2 \"Last day of Hanukkah\")
400 since the Hebrew months are numbered with 1 starting from Nisan.
401 To add the Islamic feast celebrating Mohammed's birthday, use
403 (holiday-islamic 3 12 \"Mohammed's Birthday\")
405 since the Islamic months are numbered from 1 starting with Muharram.
406 To add an entry for the Baha'i festival of Ridvan, use
408 (holiday-bahai 2 13 \"Festival of Ridvan\")
410 since the Baha'i months are numbered from 1 starting with Baha.
411 To add Thomas Jefferson's birthday, April 2, 1743 (Julian), use
413 (holiday-julian 4 2 \"Jefferson's Birthday\")
415 To include a holiday conditionally, use the sexp form or a conditional. For
416 example, to include American presidential elections, which occur on the first
417 Tuesday after the first Monday in November of years divisible by 4, add
420 '(if (zerop (% year 4))
421 (calendar-gregorian-from-absolute
422 (1+ (calendar-dayname-on-or-before
423 1 (+ 6 (calendar-absolute-from-gregorian
424 (list 11 1 year)))))))
425 \"US Presidential Election\")
429 (if (zerop (% displayed-year 4))
431 (calendar-extract-day
432 (calendar-gregorian-from-absolute
433 (1+ (calendar-dayname-on-or-before
434 1 (+ 6 (calendar-absolute-from-gregorian
435 (list 11 1 displayed-year)))))))
436 \"US Presidential Election\"))
438 to the list. To include the phases of the moon, add
442 to the holiday list, where `lunar-phases' is an Emacs-Lisp function that
443 you've written to return a (possibly empty) list of the relevant VISIBLE dates
444 with descriptive strings such as
446 (((2 6 1989) \"New Moon\") ((2 12 1989) \"First Quarter Moon\") ... )."
450 (put 'calendar-holidays
'risky-local-variable t
)
452 ;;; End of user options.
455 ;; FIXME name that makes sense
457 (defun calendar-holiday-list ()
458 "Form the list of holidays that occur on dates in the calendar window.
459 The holidays are those in the list `calendar-holidays'."
462 (dolist (p calendar-holidays res
)
463 (if (setq h
(if calendar-debug-sexp
464 (let ((stack-trace-on-error t
))
469 (message "Bad holiday list item: %s" p
)
471 (setq res
(append h res
))))
472 'calendar-date-compare
)))
474 (defvar displayed-month
) ; from calendar-generate
475 (defvar displayed-year
)
477 ;; FIXME name that makes sense
479 (defun calendar-list-holidays (&optional event
)
480 "Create a buffer containing the holidays for the current calendar window.
481 The holidays are those in the list `calendar-notable-days'.
482 Returns non-nil if any holidays are found.
483 If EVENT is non-nil, it's an event indicating the buffer position to
484 use instead of point."
485 (interactive (list last-nonmenu-event
))
486 ;; If called from a menu, with the calendar window not selected.
488 (if event
(window-buffer (posn-window (event-start event
)))
490 (message "Looking up holidays...")
491 (let ((holiday-list (calendar-holiday-list))
496 (if (not holiday-list
)
497 (message "Looking up holidays...none found")
498 (calendar-in-read-only-buffer holiday-buffer
499 (calendar-increment-month m1 y1 -
1)
500 (calendar-increment-month m2 y2
1)
501 (calendar-set-mode-line
503 (format "Notable Dates from %s to %s, %d%%-"
504 (calendar-month-name m1
) (calendar-month-name m2
) y2
)
505 (format "Notable Dates from %s, %d to %s, %d%%-"
506 (calendar-month-name m1
) y1
(calendar-month-name m2
) y2
)))
509 (lambda (x) (concat (calendar-date-string (car x
))
512 (message "Looking up holidays...done"))
515 (define-obsolete-function-alias
516 'list-calendar-holidays
'calendar-list-holidays
"23.1")
519 (defun holidays (&optional arg
)
520 "Display the holidays for last month, this month, and next month.
521 If called with an optional prefix argument ARG, prompts for month and year.
522 This function is suitable for execution in a .emacs file."
525 (let* ((completion-ignore-case t
)
526 (date (if arg
(calendar-read-date t
)
527 (calendar-current-date)))
528 (displayed-month (calendar-extract-month date
))
529 (displayed-year (calendar-extract-year date
)))
530 (calendar-list-holidays))))
532 ;; rms: "Emacs commands to display a list of something generally start
533 ;; with `list-'. Please make `list-holidays' the principal name."
535 (defun list-holidays (y1 &optional y2 l label
)
536 "Display holidays for years Y1 to Y2 (inclusive).
537 Y2 defaults to Y1. The optional list of holidays L defaults to
538 `calendar-holidays'. If you want to control what holidays are
539 displayed, use a different list. For example,
541 (list-holidays 2006 2006
542 (append holiday-general-holidays holiday-local-holidays))
544 will display holidays for the year 2006 defined in the two
545 mentioned lists, and nothing else.
547 When called interactively, this command offers a choice of
548 holidays, based on the variables `holiday-solar-holidays' etc. See the
549 documentation of `calendar-holidays' for a list of the variables
550 that control the choices, as well as a description of the format
553 The optional LABEL is used to label the buffer created."
555 (let* ((start-year (calendar-read
556 "Starting year of holidays (>0): "
558 (number-to-string (calendar-extract-year
559 (calendar-current-date)))))
560 (end-year (calendar-read
561 (format "Ending year (inclusive) of holidays (>=%s): "
563 (lambda (x) (>= x start-year
))
564 (number-to-string start-year
)))
565 (completion-ignore-case t
)
568 (cons "All" calendar-holidays
)
569 (cons "Equinoxes/Solstices"
570 (list (list 'solar-equinoxes-solstices
)))
571 (if holiday-general-holidays
572 (cons "General" holiday-general-holidays
))
573 (if holiday-local-holidays
574 (cons "Local" holiday-local-holidays
))
575 (if holiday-other-holidays
576 (cons "Other" holiday-other-holidays
))
577 (if holiday-christian-holidays
578 (cons "Christian" holiday-christian-holidays
))
579 (if holiday-hebrew-holidays
580 (cons "Hebrew" holiday-hebrew-holidays
))
581 (if holiday-islamic-holidays
582 (cons "Islamic" holiday-islamic-holidays
))
583 (if holiday-bahai-holidays
584 (cons "Baha'i" holiday-bahai-holidays
))
585 (if holiday-oriental-holidays
586 (cons "Oriental" holiday-oriental-holidays
))
587 (if holiday-solar-holidays
588 (cons "Solar" holiday-solar-holidays
))
591 (completing-read "List (TAB for choices): " lists nil t
)))
592 (which (if (string-equal choice
"Ask")
593 (eval (read-variable "Enter list name: "))
594 (cdr (assoc choice lists
))))
595 (name (if (string-equal choice
"Equinoxes/Solstices")
597 (if (member choice
'("Ask" ""))
599 (format "%s Holidays" choice
)))))
600 (list start-year end-year which name
)))
601 (unless y2
(setq y2 y1
))
602 (message "Computing holidays...")
603 (let ((calendar-holidays (or l calendar-holidays
))
604 (title (or label
"Holidays"))
605 (s (calendar-absolute-from-gregorian (list 2 1 y1
)))
606 (e (calendar-absolute-from-gregorian (list 11 1 y2
)))
611 (setq holiday-list
(append holiday-list
(calendar-holiday-list)))
612 (calendar-increment-month displayed-month displayed-year
3)
613 (setq s
(calendar-absolute-from-gregorian
614 (list displayed-month
1 displayed-year
))))
616 (calendar-in-read-only-buffer holiday-buffer
617 (calendar-set-mode-line
619 (format "%s for %s" title y1
)
620 (format "%s for %s-%s" title y1 y2
)))
623 (lambda (x) (concat (calendar-date-string (car x
))
626 (message "Computing holidays...done"))))
629 (defalias 'holiday-list
'list-holidays
)
632 (defun calendar-check-holidays (date)
633 "Check the list of holidays for any that occur on DATE.
634 The value returned is a list of strings of relevant holiday descriptions.
635 The holidays are those in the list `calendar-holidays'."
636 (let ((displayed-month (calendar-extract-month date
))
637 (displayed-year (calendar-extract-year date
))
639 (dolist (h (calendar-holiday-list) holiday-list
)
640 (if (calendar-date-equal date
(car h
))
641 (setq holiday-list
(append holiday-list
(cdr h
)))))))
643 (define-obsolete-function-alias
644 'check-calendar-holidays
'calendar-check-holidays
"23.1")
646 (declare-function x-popup-menu
"menu.c" (position menu
))
649 (defun calendar-cursor-holidays (&optional date event
)
650 "Find holidays for the date specified by the cursor in the calendar window.
651 Optional DATE is a list (month day year) to use instead of the
652 cursor position. EVENT specifies a buffer position to use for a date."
653 (interactive (list nil last-nonmenu-event
))
654 (message "Checking holidays...")
655 (or date
(setq date
(calendar-cursor-to-date t event
)))
656 (let ((date-string (calendar-date-string date
))
657 (holiday-list (calendar-check-holidays date
))
659 (if (mouse-event-p event
)
660 (and (setq selection
(cal-menu-x-popup-menu event
661 (format "Holidays for %s" date-string
)
663 (mapcar 'list holiday-list
)
665 (call-interactively selection
))
666 (if (not holiday-list
)
667 (message "No holidays known for %s" date-string
)
668 (if (<= (length (setq msg
669 (format "%s: %s" date-string
670 (mapconcat 'identity holiday-list
"; "))))
673 (calendar-in-read-only-buffer holiday-buffer
674 (calendar-set-mode-line date-string
)
675 (insert (mapconcat 'identity holiday-list
"\n")))
676 (message "Checking holidays...done"))))))
678 ;; FIXME move to calendar?
680 (defun calendar-mark-holidays (&optional event
)
681 "Mark notable days in the calendar window.
682 If EVENT is non-nil, it's an event indicating the buffer position to
683 use instead of point."
684 (interactive (list last-nonmenu-event
))
685 ;; If called from a menu, with the calendar window not selected.
687 (if event
(window-buffer (posn-window (event-start event
)))
689 (setq calendar-mark-holidays-flag t
)
690 (message "Marking holidays...")
691 (dolist (holiday (calendar-holiday-list))
692 (calendar-mark-visible-date (car holiday
) calendar-holiday-marker
))
693 (message "Marking holidays...done")))
695 (define-obsolete-function-alias
696 'mark-calendar-holidays
'calendar-mark-holidays
"23.1")
698 ;; Below are the functions that calculate the dates of holidays; these
699 ;; are eval'ed in the function calendar-holiday-list. If you
700 ;; write other such functions, be sure to imitate the style used below.
701 ;; Remember that each function must return a list of items of the form
702 ;; ((month day year) string) of VISIBLE dates in the calendar window.
704 (defun holiday-fixed (month day string
)
705 "Holiday on MONTH, DAY (Gregorian) called STRING.
706 If MONTH, DAY is visible, the value returned is the list (((MONTH DAY year)
707 STRING)). Returns nil if it is not visible in the current calendar window."
708 ;; This determines whether a given month is visible in the calendar.
709 ;; cf calendar-date-is-visible-p (which also checks the year part).
710 ;; The day is irrelevant since only full months are displayed.
711 ;; Since the calendar displays three months at a time, month N
712 ;; is visible if displayed-month = N-1, N, N+1.
713 ;; In particular, November is visible if d-m = 10, 11, 12.
714 ;; This is useful, because we can do a one-sided test:
715 ;; November is visible if d-m > 9. (Similarly, February is visible if
717 ;; To determine if December is visible, we can shift the calendar
718 ;; back a month and ask if November is visible; to determine if
719 ;; October is visible, we can shift it forward a month and ask if
720 ;; November is visible; etc.
721 (let ((m displayed-month
)
723 (calendar-increment-month m y
(- 11 month
))
724 (if (> m
9) ; is november visible?
725 (list (list (list month day y
) string
)))))
727 (defun holiday-float (month dayname n string
&optional day
)
728 "Holiday called STRING on the Nth DAYNAME after/before MONTH DAY.
729 DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on.
730 If N>0, use the Nth DAYNAME after MONTH DAY.
731 If N<0, use the Nth DAYNAME before MONTH DAY.
732 DAY defaults to 1 if N>0, and MONTH's last day otherwise.
733 If the holiday is visible in the calendar window, returns a
734 list (((month day year) STRING)). Otherwise returns nil."
735 ;; This is messy because the holiday may be visible, while the date
736 ;; on which it is based is not. For example, the first Monday after
737 ;; December 30 may be visible when January is not. For large values
738 ;; of |n| the problem is more grotesque. If we didn't have to worry
739 ;; about such cases, we could just use the original version of this
741 ;; (let ((m displayed-month)
742 ;; (y displayed-year))
743 ;; (calendar-increment-month m y (- 11 month))
744 ;; (if (> m 9); month in year y is visible
745 ;; (list (list (calendar-nth-named-day n dayname month y day) string)))))
746 (let* ((m1 displayed-month
)
750 (d1 (progn ; first possible base date for holiday
751 (calendar-increment-month m1 y1 -
1)
752 (+ (calendar-nth-named-absday 1 dayname m1 y1
)
755 (d2 ; last possible base date for holiday
757 (calendar-increment-month m2 y2
1)
758 (+ (calendar-nth-named-absday -
1 dayname m2 y2
)
761 (y1 (calendar-extract-year (calendar-gregorian-from-absolute d1
)))
762 (y2 (calendar-extract-year (calendar-gregorian-from-absolute d2
)))
763 (y ; year of base date
764 (if (or (= y1 y2
) (> month
9))
767 (d ; day of base date
770 (calendar-last-day-of-month month y
))))
771 (date ; base date for holiday
772 (calendar-absolute-from-gregorian (list month d y
))))
773 (and (<= d1 date
) (<= date d2
)
774 (list (list (calendar-nth-named-day n dayname month y d
)
777 (defun holiday-filter-visible-calendar (hlist)
778 "Filter list of holidays HLIST, and return only the visible ones.
779 HLIST is a list of elements of the form (DATE) TEXT."
780 (delq nil
(mapcar (lambda (p)
781 (and (car p
) (calendar-date-is-visible-p (car p
)) p
))
784 (define-obsolete-function-alias
785 'filter-visible-calendar-holidays
'holiday-filter-visible-calendar
"23.1")
787 (defun holiday-sexp (sexp string
)
788 "Sexp holiday for dates in the calendar window.
789 SEXP is an expression in variable `year' that is evaluated to
790 give `date'. STRING is an expression in `date' that evaluates to
791 the holiday description of `date'. If `date' is visible in the
792 calendar window, the holiday STRING is on that date. If date is
793 nil, or if the date is not visible, there is no holiday."
794 (let ((m displayed-month
)
797 (calendar-increment-month m y -
1)
798 (holiday-filter-visible-calendar
803 (list date
(if date
(eval string
))))
807 (list date
(if date
(eval string
))))))))
810 (defun holiday-advent (&optional n string
)
811 "Date of Nth day after advent (named STRING), if visible in calendar window.
812 Negative values of N are interpreted as days before advent.
813 STRING is used purely for display purposes. The return value has
814 the form ((MONTH DAY YEAR) STRING), where the date is that of the
815 Nth day before or after advent.
817 For backwards compatibility, if this function is called with no
818 arguments, then it returns the value appropriate for advent itself."
819 ;; Backwards compatibility layer.
821 (holiday-advent 0 "Advent")
822 (let* ((year displayed-year
)
823 (month displayed-month
)
825 (calendar-increment-month month year -
1)
826 (calendar-gregorian-from-absolute
828 (calendar-dayname-on-or-before
830 (calendar-absolute-from-gregorian
831 (list 12 3 year
))))))))
832 (if (calendar-date-is-visible-p advent
)
833 (list (list advent string
))))))
835 (defun holiday-easter-etc (&optional n string
)
836 "Date of Nth day after Easter (named STRING), if visible in calendar window.
837 Negative values of N are interpreted as days before Easter.
838 STRING is used purely for display purposes. The return value has
839 the form ((MONTH DAY YEAR) STRING), where the date is that of the
840 Nth day before or after Easter.
842 For backwards compatibility, if this function is called with no
843 arguments, then it returns a list of \"standard\" Easter-related
844 holidays (with more entries if `calendar-christian-all-holidays-flag'
846 ;; Backwards compatibility layer.
850 (apply 'holiday-easter-etc e
))
851 ;; The combined list is not in order.
853 (if calendar-christian-all-holidays-flag
854 '((-63 "Septuagesima Sunday")
855 (-56 "Sexagesima Sunday")
856 (-49 "Shrove Sunday")
857 (-48 "Shrove Monday")
858 (-47 "Shrove Tuesday")
859 (-14 "Passion Sunday")
861 (-3 "Maundy Thursday")
862 (35 "Rogation Sunday")
864 (49 "Pentecost (Whitsunday)")
866 (56 "Trinity Sunday")
867 (60 "Corpus Christi")))
868 '((-46 "Ash Wednesday")
870 (0 "Easter Sunday")))))
871 (let* ((century (1+ (/ displayed-year
100)))
872 (shifted-epact ; age of moon for April 5...
873 (%
(+ 14 (* 11 (% displayed-year
19)) ; ...by Nicaean rule
874 (- ; ...corrected for the Gregorian century rule
876 (/ ; ...corrected for Metonic cycle inaccuracy
877 (+ 5 (* 8 century
)) 25)
878 (* 30 century
)) ; keeps value positive
880 (adjusted-epact ; adjust for 29.5 day month
881 (if (or (zerop shifted-epact
)
882 (and (= shifted-epact
1) (< 10 (% displayed-year
19))))
885 (paschal-moon ; day after the full moon on or after March 21
886 (- (calendar-absolute-from-gregorian (list 4 19 displayed-year
))
888 (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon
7)))
889 (greg (calendar-gregorian-from-absolute (+ abs-easter n
))))
890 (if (calendar-date-is-visible-p greg
)
891 (list (list greg string
))))))
893 ;; Prior call to calendar-julian-from-absolute will autoload cal-julian.
894 (declare-function calendar-julian-to-absolute
"cal-julian" (date))
896 (defun holiday-greek-orthodox-easter ()
897 "Date of Easter according to the rule of the Council of Nicaea."
898 (let* ((m displayed-month
)
901 (calendar-increment-month m y
1)
902 (calendar-extract-year
903 (calendar-julian-from-absolute
904 (calendar-absolute-from-gregorian
905 (list m
(calendar-last-day-of-month m y
) y
))))))
906 (shifted-epact ; age of moon for April 5
908 (* 11 (% julian-year
19)))
910 (paschal-moon ; day after full moon on or after March 21
911 (- (calendar-julian-to-absolute (list 4 19 julian-year
))
913 (nicaean-easter ; Sunday following the Paschal moon
914 (calendar-gregorian-from-absolute
915 (calendar-dayname-on-or-before 0 (+ paschal-moon
7)))))
916 (if (calendar-date-is-visible-p nicaean-easter
)
917 (list (list nicaean-easter
"Pascha (Greek Orthodox Easter)")))))
921 ;; arch-tag: 48eb3117-75a7-4dbe-8fd9-873c3cbb0d37
922 ;;; holidays.el ends here