]> code.delx.au - gnu-emacs/blobdiff - lisp/calendar/holidays.el
(calendar-basic-setup): Set day to 1 in
[gnu-emacs] / lisp / calendar / holidays.el
index e29d5e6d3362eefd0d43106c57a56910deaf59b1..5a29bf8fff1fa57b0426f4d15e4be525fa66e7c4 100644 (file)
@@ -1,40 +1,39 @@
 ;;; holidays.el --- holiday functions for the calendar package
 
-;;; Copyright (C) 1989, 1990, 1992 Free Software Foundation, Inc.
+;; Copyright (C) 1989, 1990, 1992, 1993, 1994, 1997, 2001, 2002, 2003,
+;;   2004, 2005, 2006  Free Software Foundation, Inc.
 
 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
+;; Maintainer: Glenn Morris <rgm@gnu.org>
 ;; Keywords: holidays, calendar
 
 ;; This file is part of GNU Emacs.
 
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY.  No author or distributor
-;; accepts responsibility to anyone for the consequences of using it
-;; or for whether it serves any particular purpose or works at all,
-;; unless he says so in writing.  Refer to the GNU Emacs General Public
-;; License for full details.
-
-;; Everyone is granted permission to copy, modify and redistribute
-;; GNU Emacs, but only under the conditions described in the
-;; GNU Emacs General Public License.   A copy of this license is
-;; supposed to have been given to you along with GNU Emacs so you
-;; can know your rights and responsibilities.  It should be in a
-;; file named COPYING.  Among other things, the copyright notice
-;; and this notice must be preserved on all copies.
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
 ;; This collection of functions implements the holiday features as described
 ;; in calendar.el.
 
-;; Comments, corrections, and improvements should be sent to
-;;  Edward M. Reingold               Department of Computer Science
-;;  (217) 333-6733                   University of Illinois at Urbana-Champaign
-;;  reingold@cs.uiuc.edu             1304 West Springfield Avenue
-;;                                   Urbana, Illinois 61801
-
 ;; Technical details of all the calendrical calculations can be found in
+;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold
+;; and Nachum Dershowitz, Cambridge University Press (2001).
+
+;; An earlier version of the technical details appeared in
 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
 ;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
 ;; pages 899-928.  ``Calendrical Calculations, Part II: Three Historical
 ;; reingold@cs.uiuc.edu with the SUBJECT "send-paper-cal" (no quotes) and
 ;; the message BODY containing your mailing address (snail).
 
+;; Comments, corrections, and improvements should be sent to
+;;  Edward M. Reingold               Department of Computer Science
+;;  (217) 333-6733                   University of Illinois at Urbana-Champaign
+;;  reingold@cs.uiuc.edu             1304 West Springfield Avenue
+;;                                   Urbana, Illinois 61801
+
 ;;; Code:
 
+(defvar displayed-month)
+(defvar displayed-year)
+
 (require 'calendar)
 
+(autoload 'holiday-julian "cal-julian"
+  "Holiday on MONTH, DAY  (Julian) called STRING."
+  t)
+
+(autoload 'holiday-hebrew "cal-hebrew"
+  "Holiday on MONTH, DAY (Hebrew) called STRING."
+  t)
+
+(autoload 'holiday-rosh-hashanah-etc "cal-hebrew"
+  "List of dates related to Rosh Hashanah, as visible in calendar window."
+  t)
+
+(autoload 'holiday-hanukkah "cal-hebrew"
+  "List of dates related to Hanukkah, as visible in calendar window."
+  t)
+
+(autoload 'holiday-passover-etc "cal-hebrew"
+  "List of dates related to Passover, as visible in calendar window."
+  t)
+
+(autoload 'holiday-tisha-b-av-etc "cal-hebrew"
+  "List of dates around Tisha B'Av, as visible in calendar window."
+  t)
+
+(autoload 'holiday-islamic "cal-islam"
+  "Holiday on MONTH, DAY (Islamic) called STRING."
+  t)
+
+(autoload 'holiday-bahai "cal-bahai"
+  "Holiday on MONTH, DAY (Baha'i) called STRING."
+  t)
+
+(autoload 'holiday-chinese-new-year "cal-china"
+  "Date of Chinese New Year."
+  t)
+
 (autoload 'solar-equinoxes-solstices "solar"
   "Date and time of equinoxes and solstices, if visible in the calendar window.
 Requires floating point."
   t)
 
+;;;###autoload
 (defun holidays (&optional arg)
   "Display the holidays for last month, this month, and next month.
 If called with an optional prefix argument, prompts for month and year.
@@ -63,27 +108,111 @@ This function is suitable for execution in a .emacs file."
   (interactive "P")
   (save-excursion
     (let* ((completion-ignore-case t)
-           (date (calendar-current-date))
-           (displayed-month
-            (if arg
-                (cdr (assoc
-                      (capitalize
-                       (completing-read
-                        "Month name: "
-                        (mapcar 'list (append calendar-month-name-array nil))
-                        nil t))
-                      (calendar-make-alist calendar-month-name-array)))
-              (extract-calendar-month date)))
-           (displayed-year
-            (if arg
-                (calendar-read
-                 "Year (>0): "
-                 '(lambda (x) (> x 0))
-                 (int-to-string
-                  (extract-calendar-year (calendar-current-date))))
-              (extract-calendar-year date))))
+           (date (if arg
+                     (calendar-read-date t)
+                   (calendar-current-date)))
+           (displayed-month (extract-calendar-month date))
+           (displayed-year (extract-calendar-year date)))
       (list-calendar-holidays))))
 
+;;;###autoload
+(defun list-holidays (y1 y2 &optional l label)
+  "Display holidays for years Y1 to Y2 (inclusive).
+
+The optional list of holidays L defaults to `calendar-holidays'.
+If you want to control what holidays are displayed, use a
+different list.  For example,
+
+  (list-holidays 2006 2006
+    (append general-holidays local-holidays other-holidays))
+
+will display holidays for the year 2006 defined in the 3
+mentioned lists, and nothing else.
+
+When called interactively, this command offers a choice of
+holidays, based on the variables `solar-holidays' etc.  See the
+documentation of `calendar-holidays' for a list of the variables
+that control the choices, as well as a description of the format
+of a holiday list.
+
+The optional LABEL is used to label the buffer created."
+  (interactive
+   (let* ((start-year (calendar-read
+                       "Starting year of holidays (>0): "
+                       '(lambda (x) (> x 0))
+                       (int-to-string (extract-calendar-year
+                                       (calendar-current-date)))))
+          (end-year (calendar-read
+                       (format "Ending year (inclusive) of holidays (>=%s): "
+                               start-year)
+                       '(lambda (x) (>= x start-year))
+                       (int-to-string start-year)))
+          (completion-ignore-case t)
+          (lists
+           (list
+            (cons "All" calendar-holidays)
+            (if (fboundp 'atan)
+                (cons "Equinoxes/Solstices"
+                      (list (list 'solar-equinoxes-solstices))))
+            (if general-holidays (cons "General" general-holidays))
+            (if local-holidays (cons "Local" local-holidays))
+            (if other-holidays (cons "Other" other-holidays))
+            (if christian-holidays (cons "Christian" christian-holidays))
+            (if hebrew-holidays (cons "Hebrew" hebrew-holidays))
+            (if islamic-holidays (cons "Islamic" islamic-holidays))
+            (if bahai-holidays (cons "Baha'i" bahai-holidays))
+            (if oriental-holidays (cons "Oriental" oriental-holidays))
+            (if solar-holidays (cons "Solar" solar-holidays))
+            (cons "Ask" nil)))
+          (choice (capitalize
+                   (completing-read "List (TAB for choices): " lists nil t)))
+          (which (if (string-equal choice "Ask")
+                     (eval (read-variable "Enter list name: "))
+                   (cdr (assoc choice lists))))
+          (name (if (string-equal choice "Equinoxes/Solstices")
+                    choice
+                  (if (member choice '("Ask" ""))
+                      "Holidays"
+                    (format "%s Holidays" choice)))))
+     (list start-year end-year which name)))
+  (message "Computing holidays...")
+  (let* ((holiday-buffer "*Holidays*")
+         (calendar-holidays (if l l calendar-holidays))
+         (title (or label "Holidays"))
+         (holiday-list nil)
+         (s (calendar-absolute-from-gregorian (list 2 1 y1)))
+         (e (calendar-absolute-from-gregorian (list 11 1 y2)))
+         (d s)
+         (never t)
+         (displayed-month 2)
+         (displayed-year y1))
+    (while (or never (<= d e))
+      (setq holiday-list (append holiday-list (calendar-holiday-list)))
+      (setq never nil)
+      (increment-calendar-month displayed-month displayed-year 3)
+      (setq d (calendar-absolute-from-gregorian
+               (list displayed-month 1 displayed-year))))
+    (save-excursion
+      (set-buffer (get-buffer-create holiday-buffer))
+      (setq buffer-read-only nil)
+      (calendar-set-mode-line
+       (if (= y1 y2)
+           (format "%s for %s" title y1)
+         (format "%s for %s-%s" title y1 y2)))
+      (erase-buffer)
+      (goto-char (point-min))
+      (insert
+       (mapconcat
+        '(lambda (x) (concat (calendar-date-string (car x))
+                             ": " (car (cdr x))))
+        holiday-list "\n"))
+      (goto-char (point-min))
+      (set-buffer-modified-p nil)
+      (setq buffer-read-only t)
+      (display-buffer holiday-buffer)
+      (message "Computing holidays...done"))))
+
+
 (defun check-calendar-holidays (date)
   "Check the list of holidays for any that occur on DATE.
 The value returned is a list of strings of relevant holiday descriptions.
@@ -102,8 +231,7 @@ The holidays are those in the list calendar-holidays."
   "Find holidays for the date specified by the cursor in the calendar window."
   (interactive)
   (message "Checking holidays...")
-  (let* ((date (or (calendar-cursor-to-date)
-                   (error "Cursor is not on a date!")))
+  (let* ((date (calendar-cursor-to-date t))
          (date-string (calendar-date-string date))
          (holiday-list (check-calendar-holidays date))
          (holiday-string (mapconcat 'identity holiday-list ";  "))
@@ -111,7 +239,7 @@ The holidays are those in the list calendar-holidays."
     (if (not holiday-list)
         (message "No holidays known for %s" date-string)
       (if (<= (length msg) (frame-width))
-          (message msg)
+          (message "%s" msg)
         (set-buffer (get-buffer-create holiday-buffer))
         (setq buffer-read-only nil)
         (calendar-set-mode-line date-string)
@@ -155,8 +283,11 @@ holidays are found, nil if not."
       (increment-calendar-month m1 y1 -1)
       (increment-calendar-month m2 y2 1)
       (calendar-set-mode-line
-            (format "Notable Dates from %s, %d to %s, %d%%-"
-                    (calendar-month-name m1) y1 (calendar-month-name m2) y2))
+       (if (= y1 y2)
+           (format "Notable Dates from %s to %s, %d%%-"
+                   (calendar-month-name m1) (calendar-month-name m2) y2)
+         (format "Notable Dates from %s, %d to %s, %d%%-"
+                 (calendar-month-name m1) y1 (calendar-month-name m2) y2)))
       (erase-buffer)
       (insert
        (mapconcat
@@ -207,101 +338,57 @@ STRING)).  Returns nil if it is not visible in the current calendar window."
       (list (list (list month day y) string)))))
 
 (defun holiday-float (month dayname n string &optional day)
-  "Holiday on MONTH, DAYNAME (Nth occurrence, Gregorian) called STRING.
+  "Holiday on MONTH, DAYNAME (Nth occurrence) called STRING.
 If the Nth DAYNAME in MONTH is visible, the value returned is the list
-(((MONTH DAY year) STRING)).
+\(((MONTH DAY year) STRING)).
 
 If N<0, count backward from the end of MONTH.
 
-An optional parameter DAY means the Nth DAYNAME after/before MONTH DAY.
+An optional parameter DAY means the Nth DAYNAME on or after/before MONTH DAY.
 
 Returns nil if it is not visible in the current calendar window."
-  (let ((m displayed-month)
-        (y displayed-year))
-    (increment-calendar-month m y (- 11 month))
-    (if (> m 9)
-      (list (list (calendar-nth-named-day n dayname month y day) string)))))
-
-(defun holiday-julian (month day string)
-  "Holiday on MONTH, DAY  (Julian) called STRING.
-If MONTH, DAY (Julian) is visible, the value returned is corresponding
-Gregorian date in the form of the list (((month day year) STRING)).  Returns
-nil if it is not visible in the current calendar window."
-  (let ((m1 displayed-month)
-        (y1 displayed-year)
-        (m2 displayed-month)
-        (y2 displayed-year)
-        (year))
+;; This is messy because the holiday may be visible, while the date on which
+;; it is based is not.  For example, the first Monday after December 30 may be
+;; visible when January is not.  For large values of |n| the problem is more
+;; grotesque.  If we didn't have to worry about such cases, we could just use
+
+;;  (let ((m displayed-month)
+;;        (y displayed-year))
+;;    (increment-calendar-month m y (- 11 month))
+;;    (if (> m 9); month in year y is visible
+;;      (list (list (calendar-nth-named-day n dayname month y day) string)))))
+
+;; which is the way the function was originally written.
+
+  (let* ((m1 displayed-month)
+         (y1 displayed-year)
+         (m2 m1)
+         (y2 y1))
     (increment-calendar-month m1 y1 -1)
     (increment-calendar-month m2 y2 1)
-    (let* ((start-date (calendar-absolute-from-gregorian
-                        (list m1 1 y1)))
-           (end-date (calendar-absolute-from-gregorian
-                      (list m2 (calendar-last-day-of-month m2 y2) y2)))
-           (julian-start (calendar-julian-from-absolute start-date))
-           (julian-end (calendar-julian-from-absolute end-date))
-           (julian-y1 (extract-calendar-year julian-start))
-           (julian-y2 (extract-calendar-year julian-end)))
-      (setq year (if (< 10 month) julian-y1 julian-y2))
-      (let ((date (calendar-gregorian-from-absolute
-                   (calendar-absolute-from-julian
-                    (list month day year)))))
-        (if (calendar-date-is-visible-p date)
-            (list (list date string)))))))
-
-(defun holiday-islamic (month day string)
-  "Holiday on MONTH, DAY (Islamic) called STRING.
-If MONTH, DAY (Islamic) is visible, the value returned is corresponding
-Gregorian date in the form of the list (((month day year) STRING)).  Returns
-nil if it is not visible in the current calendar window."
-  (let* ((islamic-date (calendar-islamic-from-absolute
-                        (calendar-absolute-from-gregorian
-                         (list displayed-month 15 displayed-year))))
-         (m (extract-calendar-month islamic-date))
-         (y (extract-calendar-year islamic-date))
-        (date))
-    (if (< m 1)
-        nil;;   Islamic calendar doesn't apply.
-      (increment-calendar-month m y (- 10 month))
-      (if (> m 7);;  Islamic date might be visible
-          (let ((date (calendar-gregorian-from-absolute
-                       (calendar-absolute-from-islamic (list month day y)))))
-            (if (calendar-date-is-visible-p date)
-                (list (list date string))))))))
-
-(defun holiday-hebrew (month day string)
-  "Holiday on MONTH, DAY (Hebrew) called STRING.
-If MONTH, DAY (Hebrew) is visible, the value returned is corresponding
-Gregorian date in the form of the list (((month day year) STRING)).  Returns
-nil if it is not visible in the current calendar window."
-  (if (memq displayed-month;;  This test is only to speed things up a bit;
-            (list          ;;  it works fine without the test too.
-             (if (< 11 month) (- month 11) (+ month 1))
-             (if (< 10 month) (- month 10) (+ month 2))
-             (if (<  9 month) (- month  9) (+ month 3))
-             (if (<  8 month) (- month  8) (+ month 4))
-             (if (<  7 month) (- month  7) (+ month 5))))
-      (let ((m1 displayed-month)
-            (y1 displayed-year)
-            (m2 displayed-month)
-            (y2 displayed-year)
-            (year))
-        (increment-calendar-month m1 y1 -1)
-        (increment-calendar-month m2 y2 1)
-        (let* ((start-date (calendar-absolute-from-gregorian
-                            (list m1 1 y1)))
-               (end-date (calendar-absolute-from-gregorian
-                          (list m2 (calendar-last-day-of-month m2 y2) y2)))
-               (hebrew-start (calendar-hebrew-from-absolute start-date))
-               (hebrew-end (calendar-hebrew-from-absolute end-date))
-               (hebrew-y1 (extract-calendar-year hebrew-start))
-               (hebrew-y2 (extract-calendar-year hebrew-end)))
-          (setq year (if (< 6 month) hebrew-y2 hebrew-y1))
-          (let ((date (calendar-gregorian-from-absolute
-                       (calendar-absolute-from-hebrew
-                        (list month day year)))))
-            (if (calendar-date-is-visible-p date)
-                (list (list date string))))))))
+    (let* ((d1;  first possible base date for holiday
+            (+ (calendar-nth-named-absday 1 dayname m1 y1)
+               (* -7 n)
+               (if (> n 0) 1 -7)))
+           (d2;  last possible base date for holiday
+            (+ (calendar-nth-named-absday -1 dayname m2 y2)
+               (* -7 n)
+               (if (> n 0) 7 -1)))
+           (y1 (extract-calendar-year (calendar-gregorian-from-absolute d1)))
+           (y2 (extract-calendar-year (calendar-gregorian-from-absolute d2)))
+           (y; year of base date
+            (if (or (= y1 y2) (> month 9))
+                  y1
+                y2))
+           (d; day of base date
+            (or day (if (> n 0)
+                        1
+                      (calendar-last-day-of-month month y))))
+           (date; base date for holiday
+            (calendar-absolute-from-gregorian (list month d y))))
+      (if (and (<= d1 date) (<= date d2))
+          (list (list (calendar-nth-named-day n dayname month y d)
+                      string))))))
 
 (defun holiday-sexp (sexp string)
   "Sexp holiday for dates in the calendar window.
@@ -326,86 +413,88 @@ date.  If date is nil, or if the date is not visible, there is no holiday."
              (string (if date (eval string))))
         (list (list date string)))))))
 
-(defun holiday-advent ()
-  "Date of Advent, if visible in calendar window."
-  (let ((year displayed-year)
-        (month displayed-month))
-    (increment-calendar-month month year -1)
-    (let ((advent (calendar-gregorian-from-absolute
-                   (calendar-dayname-on-or-before 0
-                    (calendar-absolute-from-gregorian
-                     (list 12 3 year))))))
-      (if (calendar-date-is-visible-p advent)
-          (list (list advent "Advent"))))))
-
-(defun holiday-easter-etc ()
-  "List of dates related to Easter, as visible in calendar window."
- (if (and (> displayed-month 5) (not all-christian-calendar-holidays))
-     nil;; Ash Wednesday, Good Friday, and Easter are not visible.
-   (let* ((century (1+ (/ displayed-year 100)))
-          (shifted-epact        ;; Age of moon for April 5...
-           (% (+ 14 (* 11 (% displayed-year 19));;     ...by Nicaean rule
-                 (-           ;; ...corrected for the Gregorian century rule
-                  (/ (* 3 century) 4))
-                 (/    ;; ...corrected for Metonic cycle inaccuracy.
-                  (+ 5 (* 8 century)) 25)
-                 (* 30 century));;              Keeps value positive.
-              30))
-          (adjusted-epact       ;;  Adjust for 29.5 day month.
-           (if (or (= shifted-epact 0)
-                   (and (= shifted-epact 1) (< 10 (% displayed-year 19))))
-               (1+ shifted-epact)
-             shifted-epact))
-          (paschal-moon       ;; Day after the full moon on or after March 21.
-           (- (calendar-absolute-from-gregorian (list 4 19 displayed-year))
-              adjusted-epact))
-          (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))
-          (mandatory
-           (list
-            (list (calendar-gregorian-from-absolute abs-easter)
-                  "Easter Sunday")
-            (list (calendar-gregorian-from-absolute (- abs-easter 2))
-                  "Good Friday")
-            (list (calendar-gregorian-from-absolute (- abs-easter 46))
-                  "Ash Wednesday")))
-          (optional
-           (list
-            (list (calendar-gregorian-from-absolute (- abs-easter 63))
-                  "Septuagesima Sunday")
-            (list (calendar-gregorian-from-absolute (- abs-easter 56))
-                  "Sexagesima Sunday")
-            (list (calendar-gregorian-from-absolute (- abs-easter 49))
-                  "Shrove Sunday")
-            (list (calendar-gregorian-from-absolute (- abs-easter 48))
-                  "Shrove Monday")
-            (list (calendar-gregorian-from-absolute (- abs-easter 47))
-                  "Shrove Tuesday")
-            (list (calendar-gregorian-from-absolute (- abs-easter 14))
-                  "Passion Sunday")
-            (list (calendar-gregorian-from-absolute (- abs-easter 7))
-                  "Palm Sunday")
-            (list (calendar-gregorian-from-absolute (- abs-easter 3))
-                  "Maundy Thursday")
-            (list (calendar-gregorian-from-absolute (+ abs-easter 35))
-                  "Rogation Sunday")
-            (list (calendar-gregorian-from-absolute (+ abs-easter 39))
-                  "Ascension Day")
-            (list (calendar-gregorian-from-absolute (+ abs-easter 49))
-                  "Pentecost (Whitsunday)")
-            (list (calendar-gregorian-from-absolute (+ abs-easter 50))
-                  "Whitmunday")
-            (list (calendar-gregorian-from-absolute (+ abs-easter 56))
-                  "Trinity Sunday")
-            (list (calendar-gregorian-from-absolute (+ abs-easter 60))
-                  "Corpus Christi")))
-          (output-list
-           (filter-visible-calendar-holidays mandatory)))
-     (if all-christian-calendar-holidays
-         (setq output-list
-               (append 
-                (filter-visible-calendar-holidays optional)
-                output-list)))
-     output-list)))
+(defun holiday-advent (&optional n string)
+  "Date of Nth day after advent (named STRING), if visible in calendar window.
+Negative values of N are interpreted as days before advent.
+STRING is used purely for display purposes.  The return value has
+the form ((MONTH DAY YEAR) STRING), where the date is that of the
+Nth day before or after advent.
+
+For backwards compatibility, if this function is called with no
+arguments, then it returns the value appropriate for advent itself."
+  ;; Backwards compatibility layer.
+  (if (not n)
+      (holiday-advent 0 "Advent")
+    (let ((year displayed-year)
+          (month displayed-month))
+      (increment-calendar-month month year -1)
+      (let ((advent (calendar-gregorian-from-absolute
+                     (+ n
+                        (calendar-dayname-on-or-before
+                         0
+                         (calendar-absolute-from-gregorian
+                          (list 12 3 year)))))))
+        (if (calendar-date-is-visible-p advent)
+            (list (list advent string)))))))
+
+(defun holiday-easter-etc (&optional n string)
+  "Date of Nth day after Easter (named STRING), if visible in calendar window.
+Negative values of N are interpreted as days before Easter.
+STRING is used purely for display purposes.  The return value has
+the form ((MONTH DAY YEAR) STRING), where the date is that of the
+Nth day before or after Easter.
+
+For backwards compatibility, if this function is called with no
+arguments, then it returns a list of \"standard\" Easter-related
+holidays (with more entries if `all-christian-calendar-holidays'
+is non-nil)."
+  ;; Backwards compatibility layer.
+  (if (not n)
+      (let (res-list res)
+        (dolist (elem (append
+                       (if all-christian-calendar-holidays
+                           '((-63 . "Septuagesima Sunday")
+                             (-56 . "Sexagesima Sunday")
+                             (-49 . "Shrove Sunday")
+                             (-48 . "Shrove Monday")
+                             (-47 . "Shrove Tuesday")
+                             (-14 . "Passion Sunday")
+                             (-7 . "Palm Sunday")
+                             (-3 . "Maundy Thursday")
+                             (35 . "Rogation Sunday")
+                             (39 . "Ascension Day")
+                             (49 . "Pentecost (Whitsunday)")
+                             (50 . "Whitmonday")
+                             (56 . "Trinity Sunday")
+                             (60 . "Corpus Christi")))
+                       '((0 . "Easter Sunday")
+                         (-2 . "Good Friday")
+                         (-46 . "Ash Wednesday")))
+                      res-list)
+          ;; Filter out nil (not visible) values.
+          (if (setq res (holiday-easter-etc (car elem) (cdr elem)))
+              (setq res-list (append res res-list)))))
+    (let* ((century (1+ (/ displayed-year 100)))
+           (shifted-epact ;; Age of moon for April 5...
+            (% (+ 14 (* 11 (% displayed-year 19)) ;;     ...by Nicaean rule
+                  (- ;; ...corrected for the Gregorian century rule
+                   (/ (* 3 century) 4))
+                  (/ ;; ...corrected for Metonic cycle inaccuracy.
+                   (+ 5 (* 8 century)) 25)
+                  (* 30 century)) ;;              Keeps value positive.
+               30))
+           (adjusted-epact ;;  Adjust for 29.5 day month.
+            (if (or (zerop shifted-epact)
+                    (and (= shifted-epact 1) (< 10 (% displayed-year 19))))
+                (1+ shifted-epact)
+              shifted-epact))
+           (paschal-moon ;; Day after the full moon on or after March 21.
+            (- (calendar-absolute-from-gregorian (list 4 19 displayed-year))
+               adjusted-epact))
+           (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon 7))))
+      (filter-visible-calendar-holidays
+       (list (list (calendar-gregorian-from-absolute (+ abs-easter n))
+                   string))))))
 
 (defun holiday-greek-orthodox-easter ()
   "Date of Easter according to the rule of the Council of Nicaea."
@@ -430,202 +519,6 @@ date.  If date is nil, or if the date is not visible, there is no holiday."
       (if (calendar-date-is-visible-p nicaean-easter)
           (list (list nicaean-easter "Pascha (Greek Orthodox Easter)"))))))
 
-(defun holiday-rosh-hashanah-etc ()
-  "List of dates related to Rosh Hashanah, as visible in calendar window."
-  (if (or (< displayed-month 8)
-          (> displayed-month 11))
-      nil;; None of the dates is visible
-    (let* ((abs-r-h (calendar-absolute-from-hebrew
-                      (list 7 1 (+ displayed-year 3761))))
-            (mandatory
-             (list
-              (list (calendar-gregorian-from-absolute abs-r-h)
-                    (format "Rosh HaShanah %d" (+ 3761 displayed-year)))
-              (list (calendar-gregorian-from-absolute (+ abs-r-h 9))
-                    "Yom Kippur")
-              (list (calendar-gregorian-from-absolute (+ abs-r-h 14))
-                    "Sukkot")
-              (list (calendar-gregorian-from-absolute (+ abs-r-h 21))
-                    "Shemini Atzeret")
-              (list (calendar-gregorian-from-absolute (+ abs-r-h 22))
-                    "Simchat Torah")))
-           (optional
-            (list 
-             (list (calendar-gregorian-from-absolute
-                    (calendar-dayname-on-or-before 6 (- abs-r-h 4)))
-                   "Selichot (night)")
-             (list (calendar-gregorian-from-absolute (1- abs-r-h))
-                   "Erev Rosh HaShannah")
-             (list (calendar-gregorian-from-absolute (1+ abs-r-h))
-                   "Rosh HaShanah (second day)")
-             (list (calendar-gregorian-from-absolute
-                    (if (= (% abs-r-h 7) 4) (+ abs-r-h 3) (+ abs-r-h 2)))
-                   "Tzom Gedaliah")
-             (list (calendar-gregorian-from-absolute
-                    (calendar-dayname-on-or-before 6 (+ 7 abs-r-h)))
-                   "Shabbat Shuvah")
-             (list (calendar-gregorian-from-absolute (+ abs-r-h 8))
-                   "Erev Yom Kippur")
-             (list (calendar-gregorian-from-absolute (+ abs-r-h 13))
-                   "Erev Sukkot")
-             (list (calendar-gregorian-from-absolute (+ abs-r-h 15))
-                   "Sukkot (second day)")
-             (list (calendar-gregorian-from-absolute (+ abs-r-h 16))
-                   "Hol Hamoed Sukkot (first day)")
-             (list (calendar-gregorian-from-absolute (+ abs-r-h 17))
-                   "Hol Hamoed Sukkot (second day)")
-             (list (calendar-gregorian-from-absolute (+ abs-r-h 18))
-                   "Hol Hamoed Sukkot (third day)")
-             (list (calendar-gregorian-from-absolute (+ abs-r-h 19))
-                   "Hol Hamoed Sukkot (fourth day)")
-             (list (calendar-gregorian-from-absolute (+ abs-r-h 20))
-                   "Hoshannah Rabbah")))
-            (output-list
-             (filter-visible-calendar-holidays mandatory)))
-      (if all-hebrew-calendar-holidays
-          (setq output-list
-                (append 
-                 (filter-visible-calendar-holidays optional)
-                 output-list)))
-      output-list)))
-
-(defun holiday-hanukkah ()
-  "List of dates related to Hanukkah, as visible in calendar window."
-    (if (memq displayed-month;;  This test is only to speed things up a bit;
-              '(10 11 12 1 2));; it works fine without the test too.
-        (let ((m displayed-month)
-              (y displayed-year))
-          (increment-calendar-month m y 1)
-          (let* ((h-y (extract-calendar-year
-                         (calendar-hebrew-from-absolute
-                          (calendar-absolute-from-gregorian
-                           (list m (calendar-last-day-of-month m y) y)))))
-                 (abs-h (calendar-absolute-from-hebrew (list 9 25 h-y))))
-            (filter-visible-calendar-holidays
-             (list
-              (list (calendar-gregorian-from-absolute (1- abs-h))
-                    "Erev Hanukkah")
-              (list (calendar-gregorian-from-absolute abs-h)
-                    "Hanukkah (first day)")
-              (list (calendar-gregorian-from-absolute (1+ abs-h))
-                    "Hanukkah (second day)")
-              (list (calendar-gregorian-from-absolute (+ abs-h 2))
-                    "Hanukkah (third day)")
-              (list (calendar-gregorian-from-absolute (+ abs-h 3))
-                    "Hanukkah (fourth day)")
-              (list (calendar-gregorian-from-absolute (+ abs-h 4))
-                    "Hanukkah (fifth day)")
-              (list (calendar-gregorian-from-absolute (+ abs-h 5))
-                    "Hanukkah (sixth day)")
-              (list (calendar-gregorian-from-absolute (+ abs-h 6))
-                    "Hanukkah (seventh day)")
-              (list (calendar-gregorian-from-absolute (+ abs-h 7))
-                    "Hanukkah (eighth day)")))))))
-
-(defun holiday-passover-etc ()
-  "List of dates related to Passover, as visible in calendar window."
- (if (< 7 displayed-month)
-      nil;; None of the dates is visible
-    (let* ((abs-p (calendar-absolute-from-hebrew
-                      (list 1 15 (+ displayed-year 3760))))
-           (mandatory
-            (list
-             (list (calendar-gregorian-from-absolute abs-p)
-                   "Passover")
-             (list (calendar-gregorian-from-absolute (+ abs-p 50))
-                   "Shavuot")))
-           (optional
-            (list 
-             (list (calendar-gregorian-from-absolute
-                    (calendar-dayname-on-or-before 6 (- abs-p 43)))
-                   "Shabbat Shekalim")
-             (list (calendar-gregorian-from-absolute
-                    (calendar-dayname-on-or-before 6 (- abs-p 30)))
-                   "Shabbat Zachor")
-             (list (calendar-gregorian-from-absolute
-                    (if (= (% abs-p 7) 2) (- abs-p 33) (- abs-p 31)))
-                   "Fast of Esther")
-             (list (calendar-gregorian-from-absolute (- abs-p 31))
-                   "Erev Purim")
-             (list (calendar-gregorian-from-absolute (- abs-p 30))
-                   "Purim")
-             (list (calendar-gregorian-from-absolute
-                    (if (zerop (% abs-p 7)) (- abs-p 28) (- abs-p 29)))
-                   "Shushan Purim")
-             (list (calendar-gregorian-from-absolute
-                    (- (calendar-dayname-on-or-before 6 (- abs-p 14)) 7))
-                   "Shabbat Parah")
-             (list (calendar-gregorian-from-absolute
-                    (calendar-dayname-on-or-before 6 (- abs-p 14)))
-                   "Shabbat HaHodesh")
-             (list (calendar-gregorian-from-absolute
-                    (calendar-dayname-on-or-before 6 (1- abs-p)))
-                   "Shabbat HaGadol")
-             (list (calendar-gregorian-from-absolute (1- abs-p))
-                   "Erev Passover")
-             (list (calendar-gregorian-from-absolute (1+ abs-p))
-                   "Passover (second day)")
-             (list (calendar-gregorian-from-absolute (+ abs-p 2))
-                   "Hol Hamoed Passover (first day)")
-             (list (calendar-gregorian-from-absolute (+ abs-p 3))
-                   "Hol Hamoed Passover (second day)")
-             (list (calendar-gregorian-from-absolute (+ abs-p 4))
-                   "Hol Hamoed Passover (third day)")
-             (list (calendar-gregorian-from-absolute (+ abs-p 5))
-                   "Hol Hamoed Passover (fourth day)")
-             (list (calendar-gregorian-from-absolute (+ abs-p 6))
-                   "Passover (seventh day)")
-             (list (calendar-gregorian-from-absolute (+ abs-p 7))
-                   "Passover (eighth day)")
-             (list (calendar-gregorian-from-absolute (+ abs-p 12))
-                   "Yom HaShoah")
-             (list (calendar-gregorian-from-absolute
-                    (if (zerop (% abs-p 7))
-                        (+ abs-p 18)
-                      (if (= (% abs-p 7) 6)
-                          (+ abs-p 19)
-                        (+ abs-p 20))))
-                   "Yom HaAtzma'ut")
-             (list (calendar-gregorian-from-absolute (+ abs-p 33))
-                   "Lag BaOmer")
-             (list (calendar-gregorian-from-absolute (+ abs-p 43))
-                   "Yom Yerushalim")
-             (list (calendar-gregorian-from-absolute (+ abs-p 49))
-                   "Erev Shavuot")
-             (list (calendar-gregorian-from-absolute (+ abs-p 51))
-                   "Shavuot (second day)")))
-           (output-list
-             (filter-visible-calendar-holidays mandatory)))
-      (if all-hebrew-calendar-holidays
-          (setq output-list
-                (append 
-                 (filter-visible-calendar-holidays optional)
-                 output-list)))
-      output-list)))
-
-(defun holiday-tisha-b-av-etc ()
-  "List of dates around Tisha B'Av, as visible in calendar window."
-  (if (or (< displayed-month 5)
-          (> displayed-month 9))
-      nil;; None of the dates is visible
-    (let* ((abs-t-a (calendar-absolute-from-hebrew
-                      (list 5 9 (+ displayed-year 3760)))))
-
-      (filter-visible-calendar-holidays
-       (list 
-        (list (calendar-gregorian-from-absolute
-               (if (= (% abs-t-a 7) 6) (- abs-t-a 20) (- abs-t-a 21)))
-              "Tzom Tammuz")
-        (list (calendar-gregorian-from-absolute
-               (calendar-dayname-on-or-before 6 abs-t-a))
-              "Shabbat Hazon")
-        (list (calendar-gregorian-from-absolute
-               (if (= (% abs-t-a 7) 6) (1+ abs-t-a) abs-t-a))
-              "Tisha B'Av")
-        (list (calendar-gregorian-from-absolute
-               (calendar-dayname-on-or-before 6 (+ abs-t-a 7)))
-              "Shabbat Nahamu"))))))
-
 (defun filter-visible-calendar-holidays (l)
   "Return a list of all visible holidays of those on L."
   (let ((visible)
@@ -639,4 +532,5 @@ date.  If date is nil, or if the date is not visible, there is no holiday."
 
 (provide 'holidays)
 
+;;; arch-tag: 48eb3117-75a7-4dbe-8fd9-873c3cbb0d37
 ;;; holidays.el ends here