Work around "Attempt to modify read-only object"
[emacs.git] / lisp / calendar / holidays.el
Commit [+]AuthorDateLineData
1a06eabd Eric S. Raymond1992-05-30 23:12:08 +00001;;; holidays.el --- holiday functions for the calendar package
fc68affa Eric S. Raymond1992-07-16 07:28:05 +00002
7e09ef09
PE
Paul Eggert2015-01-01 14:26:41 -08003;; Copyright (C) 1989-1990, 1992-1994, 1997, 2001-2015 Free Software
4;; Foundation, Inc.
3a801d0c Eric S. Raymond1992-07-22 04:22:42 +00005
fc68affa Eric S. Raymond1992-07-16 07:28:05 +00006;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
aff88519 Glenn Morris2005-10-08 04:49:48 +00007;; Maintainer: Glenn Morris <rgm@gnu.org>
7e1dae73 Jim Blandy1992-08-12 12:50:10 +00008;; Keywords: holidays, calendar
bd78fa1d Chong Yidong2010-08-29 12:17:13 -04009;; Package: calendar
fc68affa Eric S. Raymond1992-07-16 07:28:05 +000010
1802278a
JB
Jim Blandy1991-08-23 03:01:50 +000011;; This file is part of GNU Emacs.
12
2ed66575 Glenn Morris2008-05-06 03:07:58 +000013;; GNU Emacs is free software: you can redistribute it and/or modify
59243403 Richard M. Stallman1994-04-07 20:30:18 +000014;; it under the terms of the GNU General Public License as published by
2ed66575
GM
Glenn Morris2008-05-06 03:07:58 +000015;; the Free Software Foundation, either version 3 of the License, or
16;; (at your option) any later version.
8ec105a0 Jim Blandy1993-06-22 03:24:23 +000017
1802278a Jim Blandy1991-08-23 03:01:50 +000018;; GNU Emacs is distributed in the hope that it will be useful,
59243403
RS
Richard M. Stallman1994-04-07 20:30:18 +000019;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;; GNU General Public License for more details.
22
23;; You should have received a copy of the GNU General Public License
2ed66575 Glenn Morris2008-05-06 03:07:58 +000024;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
1802278a Jim Blandy1991-08-23 03:01:50 +000025
fc68affa
ER
Eric S. Raymond1992-07-16 07:28:05 +000026;;; Commentary:
27
d600b865 Glenn Morris2008-04-01 02:47:40 +000028;; See calendar.el.
1802278a Jim Blandy1991-08-23 03:01:50 +000029
fc68affa
ER
Eric S. Raymond1992-07-16 07:28:05 +000030;;; Code:
31
1802278a Jim Blandy1991-08-23 03:01:50 +000032(require 'calendar)
e8a11b22 Glenn Morris2009-11-10 08:11:47 +000033(load "hol-loaddefs" nil t)
7e1dae73 Jim Blandy1992-08-12 12:50:10 +000034
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +000035(defgroup holidays nil
36 "Holidays support in calendar."
37 :group 'calendar
38 :prefix "holidays-"
39 :group 'local)
40
41;; The various holiday variables are autoloaded because people
42;; are used to using them to set calendar-holidays without having to
43;; explicitly load this file.
44
45;;;###autoload
46(defcustom holiday-general-holidays
1e8780b1 Dan Nicolaescu2009-11-06 05:16:23 +000047 (mapcar 'purecopy
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +000048 '((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")
1e8780b1 Dan Nicolaescu2009-11-06 05:16:23 +000064 (holiday-float 11 4 4 "Thanksgiving")))
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +000065 "General holidays. Default value is for the United States.
66See the documentation for `calendar-holidays' for details."
67 :type 'sexp
68 :group 'holidays)
69;;;###autoload
70(put 'holiday-general-holidays 'risky-local-variable t)
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +000071
72;;;###autoload
73(defcustom holiday-oriental-holidays
1e8780b1 Dan Nicolaescu2009-11-06 05:16:23 +000074 (mapcar 'purecopy
43c783b8
GM
Glenn Morris2008-04-23 03:00:29 +000075 '((holiday-chinese-new-year)
76 (if calendar-chinese-all-holidays-flag
77 (append
78 (holiday-chinese 1 15 "Lantern Festival")
79 (holiday-chinese-qingming)
80 (holiday-chinese 5 5 "Dragon Boat Festival")
81 (holiday-chinese 7 7 "Double Seventh Festival")
82 (holiday-chinese 8 15 "Mid-Autumn Festival")
83 (holiday-chinese 9 9 "Double Ninth Festival")
84 (holiday-chinese-winter-solstice)
1e8780b1 Dan Nicolaescu2009-11-06 05:16:23 +000085 ))))
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +000086 "Oriental holidays.
87See the documentation for `calendar-holidays' for details."
43c783b8 Glenn Morris2008-04-23 03:00:29 +000088 :version "23.1" ; added more holidays
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +000089 :type 'sexp
90 :group 'holidays)
91;;;###autoload
92(put 'holiday-oriental-holidays 'risky-local-variable t)
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +000093
94;;;###autoload
95(defcustom holiday-local-holidays nil
96 "Local holidays.
97See the documentation for `calendar-holidays' for details."
98 :type 'sexp
99 :group 'holidays)
100;;;###autoload
101(put 'holiday-local-holidays 'risky-local-variable t)
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000102
103;;;###autoload
104(defcustom holiday-other-holidays nil
105 "User defined holidays.
106See the documentation for `calendar-holidays' for details."
107 :type 'sexp
108 :group 'holidays)
109;;;###autoload
110(put 'holiday-other-holidays 'risky-local-variable t)
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000111
112;;;###autoload
d463476b Glenn Morris2008-04-11 03:49:39 +0000113(defcustom holiday-hebrew-holidays
1e8780b1 Dan Nicolaescu2009-11-06 05:16:23 +0000114 (mapcar 'purecopy
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000115 '((holiday-hebrew-passover)
116 (holiday-hebrew-rosh-hashanah)
117 (holiday-hebrew-hanukkah)
118 (if calendar-hebrew-all-holidays-flag
119 (append
120 (holiday-hebrew-tisha-b-av)
1e8780b1 Dan Nicolaescu2009-11-06 05:16:23 +0000121 (holiday-hebrew-misc)))))
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000122 "Jewish holidays.
123See the documentation for `calendar-holidays' for details."
124 :type 'sexp
125 :version "23.1" ; removed dependency on hebrew-holidays-N
126 :group 'holidays)
127;;;###autoload
128(put 'holiday-hebrew-holidays 'risky-local-variable t)
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000129
130;;;###autoload
131(defcustom holiday-christian-holidays
1e8780b1 Dan Nicolaescu2009-11-06 05:16:23 +0000132 (mapcar 'purecopy
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000133 '((holiday-easter-etc) ; respects calendar-christian-all-holidays-flag
134 (holiday-fixed 12 25 "Christmas")
135 (if calendar-christian-all-holidays-flag
136 (append
137 (holiday-fixed 1 6 "Epiphany")
b6683353 Glenn Morris2012-08-29 21:18:41 -0400138 (holiday-julian 12 25 "Christmas (Julian calendar)")
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000139 (holiday-greek-orthodox-easter)
140 (holiday-fixed 8 15 "Assumption")
1e8780b1 Dan Nicolaescu2009-11-06 05:16:23 +0000141 (holiday-advent 0 "Advent")))))
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000142 "Christian holidays.
143See the documentation for `calendar-holidays' for details."
144 :type 'sexp
145 :group 'holidays)
146;;;###autoload
147(put 'holiday-christian-holidays 'risky-local-variable t)
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000148
149;;;###autoload
150(defcustom holiday-islamic-holidays
1e8780b1 Dan Nicolaescu2009-11-06 05:16:23 +0000151 (mapcar 'purecopy
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000152 '((holiday-islamic-new-year)
153 (holiday-islamic 9 1 "Ramadan Begins")
154 (if calendar-islamic-all-holidays-flag
155 (append
156 (holiday-islamic 1 10 "Ashura")
157 (holiday-islamic 3 12 "Mulad-al-Nabi")
158 (holiday-islamic 7 26 "Shab-e-Mi'raj")
159 (holiday-islamic 8 15 "Shab-e-Bara't")
160 (holiday-islamic 9 27 "Shab-e Qadr")
161 (holiday-islamic 10 1 "Id-al-Fitr")
1e8780b1 Dan Nicolaescu2009-11-06 05:16:23 +0000162 (holiday-islamic 12 10 "Id-al-Adha")))))
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000163 "Islamic holidays.
164See the documentation for `calendar-holidays' for details."
165 :type 'sexp
166 :group 'holidays)
167;;;###autoload
168(put 'holiday-islamic-holidays 'risky-local-variable t)
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000169
170;;;###autoload
171(defcustom holiday-bahai-holidays
1e8780b1 Dan Nicolaescu2009-11-06 05:16:23 +0000172 (mapcar 'purecopy
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000173 '((holiday-bahai-new-year)
174 (holiday-bahai-ridvan) ; respects calendar-bahai-all-holidays-flag
6818b449
GM
Glenn Morris2012-02-17 22:08:15 -0500175 (holiday-fixed 5 23 "Declaration of the Báb")
176 (holiday-fixed 5 29 "Ascension of Bahá'u'lláh")
177 (holiday-fixed 7 9 "Martyrdom of the Báb")
178 (holiday-fixed 10 20 "Birth of the Báb")
179 (holiday-fixed 11 12 "Birth of Bahá'u'lláh")
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000180 (if calendar-bahai-all-holidays-flag
181 (append
182 (holiday-fixed 11 26 "Day of the Covenant")
6818b449
GM
Glenn Morris2012-02-17 22:08:15 -0500183 (holiday-fixed 11 28 "Ascension of `Abdu'l-Bahá")))))
184 "Bahá'í holidays.
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000185See the documentation for `calendar-holidays' for details."
186 :type 'sexp
187 :group 'holidays)
188;;;###autoload
189(put 'holiday-bahai-holidays 'risky-local-variable t)
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000190
191;;;###autoload
192(defcustom holiday-solar-holidays
1e8780b1 Dan Nicolaescu2009-11-06 05:16:23 +0000193 (mapcar 'purecopy
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000194 '((solar-equinoxes-solstices)
195 (holiday-sexp calendar-daylight-savings-starts
196 (format "Daylight Saving Time Begins %s"
197 (solar-time-string
198 (/ calendar-daylight-savings-starts-time (float 60))
199 calendar-standard-time-zone-name)))
200 (holiday-sexp calendar-daylight-savings-ends
201 (format "Daylight Saving Time Ends %s"
202 (solar-time-string
203 (/ calendar-daylight-savings-ends-time (float 60))
1e8780b1 Dan Nicolaescu2009-11-06 05:16:23 +0000204 calendar-daylight-time-zone-name)))))
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000205 "Sun-related holidays.
206See the documentation for `calendar-holidays' for details."
207 :type 'sexp
208 :group 'holidays)
209;;;###autoload
210(put 'holiday-solar-holidays 'risky-local-variable t)
d463476b Glenn Morris2008-04-11 03:49:39 +0000211
64b7c58a
GM
Glenn Morris2009-04-02 06:34:21 +0000212;; This one should not be autoloaded, else .emacs changes of
213;; holiday-general-holidays etc have no effect.
214;; FIXME should have some :set-after.
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000215(defcustom calendar-holidays
216 (append holiday-general-holidays holiday-local-holidays
217 holiday-other-holidays holiday-christian-holidays
218 holiday-hebrew-holidays holiday-islamic-holidays
219 holiday-bahai-holidays holiday-oriental-holidays
220 holiday-solar-holidays)
221 "List of notable days for the command \\[holidays].
222
223Additional holidays are easy to add to the list, just put them in the
865fe16f Chong Yidong2012-09-17 13:41:04 +0800224list `holiday-other-holidays' in your init file. Similarly, by setting
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000225any of `holiday-general-holidays', `holiday-local-holidays',
226`holiday-christian-holidays', `holiday-hebrew-holidays',
227`holiday-islamic-holidays', `holiday-bahai-holidays',
228`holiday-oriental-holidays', or `holiday-solar-holidays' to nil in your
865fe16f Chong Yidong2012-09-17 13:41:04 +0800229init file, you can eliminate unwanted categories of holidays.
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000230
231The aforementioned variables control the holiday choices offered
232by the function `holiday-list' when it is called interactively.
233
234They also initialize the default value of `calendar-holidays',
235which is the default list of holidays used by the function
236`holiday-list' in the non-interactive case. Note that these
237variables have no effect on `calendar-holidays' after it has been
238set (e.g. after the calendar is loaded). In that case, customize
239`calendar-holidays' directly.
240
241The intention is that (in the US) `holiday-local-holidays' be set in
242site-init.el and `holiday-other-holidays' be set by the user.
243
244Entries on the list are expressions that return (possibly empty) lists of
245items of the form ((month day year) string) of a holiday in the
246three-month period centered around `displayed-month' of `displayed-year'.
247Several basic functions are provided for this purpose:
248
249 (holiday-fixed MONTH DAY STRING) is a fixed date on the Gregorian calendar
19b1a5bc
GM
Glenn Morris2008-08-26 05:39:53 +0000250 (holiday-float MONTH DAYNAME K STRING &optional DAY) is the Kth DAYNAME
251 (0 for Sunday, etc.) after/before Gregorian
252 MONTH DAY. K<0 means count back from the end
253 of the month. Optional DAY defaults to 1 if
254 K>0, and MONTH's last day otherwise.
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000255 (holiday-hebrew MONTH DAY STRING) a fixed date on the Hebrew calendar
256 (holiday-islamic MONTH DAY STRING) a fixed date on the Islamic calendar
6818b449 Glenn Morris2012-02-17 22:08:15 -0500257 (holiday-bahai MONTH DAY STRING) a fixed date on the Bahá'í calendar
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000258 (holiday-julian MONTH DAY STRING) a fixed date on the Julian calendar
259 (holiday-sexp SEXP STRING) SEXP is a Gregorian-date-valued expression
260 in the variable `year'; if it evaluates to
261 a visible date, that's the holiday; if it
262 evaluates to nil, there's no holiday. STRING
263 is an expression in the variable `date'.
264
265For example, to add Bastille Day, celebrated in France on July 14, add
266
267 (holiday-fixed 7 14 \"Bastille Day\")
268
269to the list. To add Hurricane Supplication Day, celebrated in the Virgin
270Islands on the fourth Monday in August, add
271
272 (holiday-float 8 1 4 \"Hurricane Supplication Day\")
273
274to the list (the last Monday would be specified with `-1' instead of `4').
275To add the last day of Hanukkah to the list, use
276
277 (holiday-hebrew 10 2 \"Last day of Hanukkah\")
278
279since the Hebrew months are numbered with 1 starting from Nisan.
280To add the Islamic feast celebrating Mohammed's birthday, use
281
282 (holiday-islamic 3 12 \"Mohammed's Birthday\")
283
284since the Islamic months are numbered from 1 starting with Muharram.
6818b449 Glenn Morris2012-02-17 22:08:15 -0500285To add an entry for the Bahá'í festival of Ridvan, use
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000286
287 (holiday-bahai 2 13 \"Festival of Ridvan\")
288
6818b449 Glenn Morris2012-02-17 22:08:15 -0500289since the Bahá'í months are numbered from 1 starting with Bahá.
d463476b
GM
Glenn Morris2008-04-11 03:49:39 +0000290To add Thomas Jefferson's birthday, April 2, 1743 (Julian), use
291
292 (holiday-julian 4 2 \"Jefferson's Birthday\")
293
294To include a holiday conditionally, use the sexp form or a conditional. For
295example, to include American presidential elections, which occur on the first
296Tuesday after the first Monday in November of years divisible by 4, add
297
298 (holiday-sexp
299 '(if (zerop (% year 4))
300 (calendar-gregorian-from-absolute
301 (1+ (calendar-dayname-on-or-before
302 1 (+ 6 (calendar-absolute-from-gregorian
303 (list 11 1 year)))))))
304 \"US Presidential Election\")
305
306or
307
308 (if (zerop (% displayed-year 4))
309 (holiday-fixed 11
310 (calendar-extract-day
311 (calendar-gregorian-from-absolute
312 (1+ (calendar-dayname-on-or-before
313 1 (+ 6 (calendar-absolute-from-gregorian
314 (list 11 1 displayed-year)))))))
315 \"US Presidential Election\"))
316
317to the list. To include the phases of the moon, add
318
319 (lunar-phases)
320
321to the holiday list, where `lunar-phases' is an Emacs-Lisp function that
322you've written to return a (possibly empty) list of the relevant VISIBLE dates
323with descriptive strings such as
324
325 (((2 6 1989) \"New Moon\") ((2 12 1989) \"First Quarter Moon\") ... )."
326 :type 'sexp
327 :group 'holidays)
328;;;###autoload
329(put 'calendar-holidays 'risky-local-variable t)
330
331;;; End of user options.
332
333
d92bcf94 Glenn Morris2008-04-08 07:08:24 +0000334;; FIXME name that makes sense
71855cc5
GM
Glenn Morris2008-03-14 07:05:10 +0000335;;;###diary-autoload
336(defun calendar-holiday-list ()
337 "Form the list of holidays that occur on dates in the calendar window.
338The holidays are those in the list `calendar-holidays'."
32757648 Glenn Morris2012-08-20 14:13:03 -0400339 (let (res h err)
1dbf6332
GM
Glenn Morris2008-04-03 04:10:43 +0000340 (sort
341 (dolist (p calendar-holidays res)
342 (if (setq h (if calendar-debug-sexp
4d2d1ccd Glenn Morris2011-04-16 19:11:49 -0700343 (let ((debug-on-error t))
1dbf6332 Glenn Morris2008-04-03 04:10:43 +0000344 (eval p))
32757648 Glenn Morris2012-08-20 14:13:03 -0400345 (condition-case err
1dbf6332 Glenn Morris2008-04-03 04:10:43 +0000346 (eval p)
32757648
GM
Glenn Morris2012-08-20 14:13:03 -0400347 (error
348 (display-warning
349 :error
350 (format "Bad holiday list item: %s\nError: %s\n"
351 p err))
352 nil))))
1dbf6332
GM
Glenn Morris2008-04-03 04:10:43 +0000353 (setq res (append h res))))
354 'calendar-date-compare)))
71855cc5 Glenn Morris2008-03-14 07:05:10 +0000355
e803eab7 Glenn Morris2008-04-07 01:59:37 +0000356(defvar displayed-month) ; from calendar-generate
125001e9
GM
Glenn Morris2008-03-15 02:55:45 +0000357(defvar displayed-year)
358
d92bcf94 Glenn Morris2008-04-08 07:08:24 +0000359;; FIXME name that makes sense
71855cc5 Glenn Morris2008-03-14 07:05:10 +0000360;;;###cal-autoload
436b840d Glenn Morris2009-01-10 22:00:14 +0000361(defun calendar-list-holidays (&optional event)
71855cc5 Glenn Morris2008-03-14 07:05:10 +0000362 "Create a buffer containing the holidays for the current calendar window.
d600b865 Glenn Morris2008-04-01 02:47:40 +0000363The holidays are those in the list `calendar-notable-days'.
436b840d
GM
Glenn Morris2009-01-10 22:00:14 +0000364Returns non-nil if any holidays are found.
365If EVENT is non-nil, it's an event indicating the buffer position to
366use instead of point."
367 (interactive (list last-nonmenu-event))
368 ;; If called from a menu, with the calendar window not selected.
369 (with-current-buffer
370 (if event (window-buffer (posn-window (event-start event)))
371 (current-buffer))
372 (message "Looking up holidays...")
373 (let ((holiday-list (calendar-holiday-list))
374 (m1 displayed-month)
375 (y1 displayed-year)
376 (m2 displayed-month)
377 (y2 displayed-year))
378 (if (not holiday-list)
379 (message "Looking up holidays...none found")
380 (calendar-in-read-only-buffer holiday-buffer
381 (calendar-increment-month m1 y1 -1)
382 (calendar-increment-month m2 y2 1)
383 (calendar-set-mode-line
384 (if (= y1 y2)
385 (format "Notable Dates from %s to %s, %d%%-"
386 (calendar-month-name m1) (calendar-month-name m2) y2)
387 (format "Notable Dates from %s, %d to %s, %d%%-"
388 (calendar-month-name m1) y1 (calendar-month-name m2) y2)))
389 (insert
390 (mapconcat
391 (lambda (x) (concat (calendar-date-string (car x))
392 ": " (cadr x)))
393 holiday-list "\n")))
394 (message "Looking up holidays...done"))
395 holiday-list)))
71855cc5 Glenn Morris2008-03-14 07:05:10 +0000396
c8224de6 Eli Zaretskii2001-05-09 15:13:33 +0000397;;;###autoload
7e1dae73 Jim Blandy1992-08-12 12:50:10 +0000398(defun holidays (&optional arg)
1802278a Jim Blandy1991-08-23 03:01:50 +0000399 "Display the holidays for last month, this month, and next month.
68707926 Glenn Morris2008-03-08 21:09:29 +0000400If called with an optional prefix argument ARG, prompts for month and year.
865fe16f Chong Yidong2012-09-17 13:41:04 +0800401This function is suitable for execution in a init file."
7e1dae73 Jim Blandy1992-08-12 12:50:10 +0000402 (interactive "P")
1802278a Jim Blandy1991-08-23 03:01:50 +0000403 (save-excursion
7e1dae73 Jim Blandy1992-08-12 12:50:10 +0000404 (let* ((completion-ignore-case t)
71855cc5 Glenn Morris2008-03-14 07:05:10 +0000405 (date (if arg (calendar-read-date t)
c99d4526 Edward M. Reingold1994-10-26 15:31:27 +0000406 (calendar-current-date)))
e803eab7
GM
Glenn Morris2008-04-07 01:59:37 +0000407 (displayed-month (calendar-extract-month date))
408 (displayed-year (calendar-extract-year date)))
2317a7cf Stefan Monnier2007-09-07 02:53:10 +0000409 (calendar-list-holidays))))
1802278a Jim Blandy1991-08-23 03:01:50 +0000410
5fceaf9c
GM
Glenn Morris2007-09-15 19:59:25 +0000411;; rms: "Emacs commands to display a list of something generally start
412;; with `list-'. Please make `list-holidays' the principal name."
40b14a0c Richard M. Stallman1997-04-11 06:35:54 +0000413;;;###autoload
96ffea61 Stefan Monnier2008-03-26 03:43:43 +0000414(defun list-holidays (y1 &optional y2 l label)
056a21c4 Richard M. Stallman1997-04-11 02:38:51 +0000415 "Display holidays for years Y1 to Y2 (inclusive).
f97492e5
GM
Glenn Morris2008-03-27 07:59:33 +0000416Y2 defaults to Y1. The optional list of holidays L defaults to
417`calendar-holidays'. If you want to control what holidays are
418displayed, use a different list. For example,
29c83850 Eli Zaretskii2006-03-11 12:16:32 +0000419
5fceaf9c Glenn Morris2007-09-15 19:59:25 +0000420 (list-holidays 2006 2006
e803eab7 Glenn Morris2008-04-07 01:59:37 +0000421 (append holiday-general-holidays holiday-local-holidays))
29c83850 Eli Zaretskii2006-03-11 12:16:32 +0000422
e803eab7 Glenn Morris2008-04-07 01:59:37 +0000423will display holidays for the year 2006 defined in the two
29c83850
EZ
Eli Zaretskii2006-03-11 12:16:32 +0000424mentioned lists, and nothing else.
425
cae09dea Glenn Morris2006-03-10 08:04:27 +0000426When called interactively, this command offers a choice of
e803eab7 Glenn Morris2008-04-07 01:59:37 +0000427holidays, based on the variables `holiday-solar-holidays' etc. See the
cae09dea
GM
Glenn Morris2006-03-10 08:04:27 +0000428documentation of `calendar-holidays' for a list of the variables
429that control the choices, as well as a description of the format
430of a holiday list.
056a21c4
RS
Richard M. Stallman1997-04-11 02:38:51 +0000431
432The optional LABEL is used to label the buffer created."
433 (interactive
434 (let* ((start-year (calendar-read
435 "Starting year of holidays (>0): "
b3a6c0ca Glenn Morris2008-03-08 03:48:33 +0000436 (lambda (x) (> x 0))
d92bcf94 Glenn Morris2008-04-08 07:08:24 +0000437 (number-to-string (calendar-extract-year
056a21c4
RS
Richard M. Stallman1997-04-11 02:38:51 +0000438 (calendar-current-date)))))
439 (end-year (calendar-read
71855cc5
GM
Glenn Morris2008-03-14 07:05:10 +0000440 (format "Ending year (inclusive) of holidays (>=%s): "
441 start-year)
442 (lambda (x) (>= x start-year))
d92bcf94 Glenn Morris2008-04-08 07:08:24 +0000443 (number-to-string start-year)))
056a21c4
RS
Richard M. Stallman1997-04-11 02:38:51 +0000444 (completion-ignore-case t)
445 (lists
446 (list
447 (cons "All" calendar-holidays)
7d58cf63
GM
Glenn Morris2008-03-26 03:14:13 +0000448 (cons "Equinoxes/Solstices"
449 (list (list 'solar-equinoxes-solstices)))
e803eab7
GM
Glenn Morris2008-04-07 01:59:37 +0000450 (if holiday-general-holidays
451 (cons "General" holiday-general-holidays))
452 (if holiday-local-holidays
453 (cons "Local" holiday-local-holidays))
454 (if holiday-other-holidays
455 (cons "Other" holiday-other-holidays))
456 (if holiday-christian-holidays
457 (cons "Christian" holiday-christian-holidays))
458 (if holiday-hebrew-holidays
459 (cons "Hebrew" holiday-hebrew-holidays))
460 (if holiday-islamic-holidays
461 (cons "Islamic" holiday-islamic-holidays))
462 (if holiday-bahai-holidays
6818b449 Glenn Morris2012-02-17 22:08:15 -0500463 (cons "Bahá'í" holiday-bahai-holidays))
e803eab7
GM
Glenn Morris2008-04-07 01:59:37 +0000464 (if holiday-oriental-holidays
465 (cons "Oriental" holiday-oriental-holidays))
466 (if holiday-solar-holidays
467 (cons "Solar" holiday-solar-holidays))
056a21c4
RS
Richard M. Stallman1997-04-11 02:38:51 +0000468 (cons "Ask" nil)))
469 (choice (capitalize
470 (completing-read "List (TAB for choices): " lists nil t)))
471 (which (if (string-equal choice "Ask")
472 (eval (read-variable "Enter list name: "))
473 (cdr (assoc choice lists))))
474 (name (if (string-equal choice "Equinoxes/Solstices")
475 choice
ebad70de Richard M. Stallman1997-05-04 16:02:44 +0000476 (if (member choice '("Ask" ""))
a1506d29 Juanma Barranquero2003-02-04 13:24:35 +0000477 "Holidays"
056a21c4
RS
Richard M. Stallman1997-04-11 02:38:51 +0000478 (format "%s Holidays" choice)))))
479 (list start-year end-year which name)))
96ffea61 Stefan Monnier2008-03-26 03:43:43 +0000480 (unless y2 (setq y2 y1))
056a21c4 Richard M. Stallman1997-04-11 02:38:51 +0000481 (message "Computing holidays...")
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000482 (let ((calendar-holidays (or l calendar-holidays))
483 (title (or label "Holidays"))
484 (s (calendar-absolute-from-gregorian (list 2 1 y1)))
485 (e (calendar-absolute-from-gregorian (list 11 1 y2)))
486 (displayed-month 2)
487 (displayed-year y1)
488 holiday-list)
489 (while (<= s e)
490 (setq holiday-list (append holiday-list (calendar-holiday-list)))
e803eab7 Glenn Morris2008-04-07 01:59:37 +0000491 (calendar-increment-month displayed-month displayed-year 3)
d600b865 Glenn Morris2008-04-01 02:47:40 +0000492 (setq s (calendar-absolute-from-gregorian
056a21c4 Richard M. Stallman1997-04-11 02:38:51 +0000493 (list displayed-month 1 displayed-year))))
ebad70de Richard M. Stallman1997-05-04 16:02:44 +0000494 (save-excursion
9449f9eb
GM
Glenn Morris2008-03-17 02:20:49 +0000495 (calendar-in-read-only-buffer holiday-buffer
496 (calendar-set-mode-line
497 (if (= y1 y2)
498 (format "%s for %s" title y1)
499 (format "%s for %s-%s" title y1 y2)))
500 (insert
501 (mapconcat
502 (lambda (x) (concat (calendar-date-string (car x))
503 ": " (cadr x)))
504 holiday-list "\n")))
ebad70de
RS
Richard M. Stallman1997-05-04 16:02:44 +0000505 (message "Computing holidays...done"))))
506
c0dac68f Glenn Morris2007-11-22 04:16:40 +0000507;;;###autoload
5fceaf9c Glenn Morris2007-09-15 19:59:25 +0000508(defalias 'holiday-list 'list-holidays)
056a21c4 Richard M. Stallman1997-04-11 02:38:51 +0000509
4ca17d75 Glenn Morris2008-03-13 05:54:06 +0000510;;;###diary-autoload
2317a7cf Stefan Monnier2007-09-07 02:53:10 +0000511(defun calendar-check-holidays (date)
1802278a Jim Blandy1991-08-23 03:01:50 +0000512 "Check the list of holidays for any that occur on DATE.
bdfa5dd2
GM
Glenn Morris2011-10-04 13:26:55 -0400513DATE is a list (month day year). This function considers the
514holidays from the list `calendar-holidays', and returns a list of
0c2014a3 Glenn Morris2012-04-09 00:11:39 -0700515strings describing those holidays that apply on DATE, or nil if none do."
e803eab7
GM
Glenn Morris2008-04-07 01:59:37 +0000516 (let ((displayed-month (calendar-extract-month date))
517 (displayed-year (calendar-extract-year date))
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000518 holiday-list)
519 (dolist (h (calendar-holiday-list) holiday-list)
2317a7cf Stefan Monnier2007-09-07 02:53:10 +0000520 (if (calendar-date-equal date (car h))
d600b865 Glenn Morris2008-04-01 02:47:40 +0000521 (setq holiday-list (append holiday-list (cdr h)))))))
1802278a Jim Blandy1991-08-23 03:01:50 +0000522
a43f98b3
GM
Glenn Morris2012-05-05 13:58:14 -0700523
524;; Formerly cal-tex-list-holidays.
525(defun holiday-in-range (d1 d2)
526 "Generate a list of all holidays in range from absolute date D1 to D2."
527 (let* ((start (calendar-gregorian-from-absolute d1))
528 (displayed-month (calendar-extract-month start))
529 (displayed-year (calendar-extract-year start))
530 (end (calendar-gregorian-from-absolute d2))
531 (end-month (calendar-extract-month end))
532 (end-year (calendar-extract-year end))
533 (number-of-intervals
534 (1+ (/ (calendar-interval displayed-month displayed-year
535 end-month end-year)
536 3)))
537 holidays in-range a)
538 (calendar-increment-month displayed-month displayed-year 1)
539 (dotimes (_idummy number-of-intervals)
540 (setq holidays (append holidays (calendar-holiday-list)))
541 (calendar-increment-month displayed-month displayed-year 3))
542 (dolist (hol holidays)
543 (and (car hol)
544 (setq a (calendar-absolute-from-gregorian (car hol)))
545 (and (<= d1 a) (<= a d2))
546 (setq in-range (append (list hol) in-range))))
547 in-range))
548
549
e8a11b22 Glenn Morris2009-11-10 08:11:47 +0000550(declare-function x-popup-menu "menu.c" (position menu))
f2d9c15f Glenn Morris2008-08-11 01:23:07 +0000551
4ca17d75 Glenn Morris2008-03-13 05:54:06 +0000552;;;###cal-autoload
3b7de42e Glenn Morris2008-06-26 04:54:37 +0000553(defun calendar-cursor-holidays (&optional date event)
f1eb28f2
GM
Glenn Morris2008-06-18 02:55:32 +0000554 "Find holidays for the date specified by the cursor in the calendar window.
555Optional DATE is a list (month day year) to use instead of the
3b7de42e
GM
Glenn Morris2008-06-26 04:54:37 +0000556cursor position. EVENT specifies a buffer position to use for a date."
557 (interactive (list nil last-nonmenu-event))
1802278a Jim Blandy1991-08-23 03:01:50 +0000558 (message "Checking holidays...")
3b7de42e
GM
Glenn Morris2008-06-26 04:54:37 +0000559 (or date (setq date (calendar-cursor-to-date t event)))
560 (let ((date-string (calendar-date-string date))
561 (holiday-list (calendar-check-holidays date))
562 selection msg)
563 (if (mouse-event-p event)
564 (and (setq selection (cal-menu-x-popup-menu event
565 (format "Holidays for %s" date-string)
566 (if holiday-list
567 (mapcar 'list holiday-list)
568 '("None"))))
569 (call-interactively selection))
1802278a
JB
Jim Blandy1991-08-23 03:01:50 +0000570 (if (not holiday-list)
571 (message "No holidays known for %s" date-string)
3b7de42e
GM
Glenn Morris2008-06-26 04:54:37 +0000572 (if (<= (length (setq msg
573 (format "%s: %s" date-string
574 (mapconcat 'identity holiday-list "; "))))
575 (frame-width))
eec5a2e4 Karl Heuer1996-01-25 00:54:50 +0000576 (message "%s" msg)
9449f9eb
GM
Glenn Morris2008-03-17 02:20:49 +0000577 (calendar-in-read-only-buffer holiday-buffer
578 (calendar-set-mode-line date-string)
579 (insert (mapconcat 'identity holiday-list "\n")))
3b7de42e Glenn Morris2008-06-26 04:54:37 +0000580 (message "Checking holidays...done"))))))
1802278a Jim Blandy1991-08-23 03:01:50 +0000581
d92bcf94 Glenn Morris2008-04-08 07:08:24 +0000582;; FIXME move to calendar?
4ca17d75 Glenn Morris2008-03-13 05:54:06 +0000583;;;###cal-autoload
436b840d
GM
Glenn Morris2009-01-10 22:00:14 +0000584(defun calendar-mark-holidays (&optional event)
585 "Mark notable days in the calendar window.
586If EVENT is non-nil, it's an event indicating the buffer position to
587use instead of point."
588 (interactive (list last-nonmenu-event))
589 ;; If called from a menu, with the calendar window not selected.
590 (with-current-buffer
591 (if event (window-buffer (posn-window (event-start event)))
592 (current-buffer))
593 (setq calendar-mark-holidays-flag t)
594 (message "Marking holidays...")
595 (dolist (holiday (calendar-holiday-list))
596 (calendar-mark-visible-date (car holiday) calendar-holiday-marker))
597 (message "Marking holidays...done")))
1802278a Jim Blandy1991-08-23 03:01:50 +0000598
1802278a Jim Blandy1991-08-23 03:01:50 +0000599;; Below are the functions that calculate the dates of holidays; these
8ec105a0
JB
Jim Blandy1993-06-22 03:24:23 +0000600;; are eval'ed in the function calendar-holiday-list. If you
601;; write other such functions, be sure to imitate the style used below.
602;; Remember that each function must return a list of items of the form
603;; ((month day year) string) of VISIBLE dates in the calendar window.
604
605(defun holiday-fixed (month day string)
606 "Holiday on MONTH, DAY (Gregorian) called STRING.
607If MONTH, DAY is visible, the value returned is the list (((MONTH DAY year)
608STRING)). Returns nil if it is not visible in the current calendar window."
c8a54cf1
GM
Glenn Morris2008-03-31 01:36:40 +0000609 ;; This determines whether a given month is visible in the calendar.
610 ;; cf calendar-date-is-visible-p (which also checks the year part).
611 ;; The day is irrelevant since only full months are displayed.
612 ;; Since the calendar displays three months at a time, month N
613 ;; is visible if displayed-month = N-1, N, N+1.
614 ;; In particular, November is visible if d-m = 10, 11, 12.
615 ;; This is useful, because we can do a one-sided test:
616 ;; November is visible if d-m > 9. (Similarly, February is visible if
617 ;; d-m < 4.)
618 ;; To determine if December is visible, we can shift the calendar
619 ;; back a month and ask if November is visible; to determine if
620 ;; October is visible, we can shift it forward a month and ask if
621 ;; November is visible; etc.
8ec105a0
JB
Jim Blandy1993-06-22 03:24:23 +0000622 (let ((m displayed-month)
623 (y displayed-year))
e803eab7 Glenn Morris2008-04-07 01:59:37 +0000624 (calendar-increment-month m y (- 11 month))
6196cffe Paul Eggert2011-12-21 01:58:39 -0800625 (if (> m 9) ; Is November visible?
71855cc5 Glenn Morris2008-03-14 07:05:10 +0000626 (list (list (list month day y) string)))))
1802278a Jim Blandy1991-08-23 03:01:50 +0000627
8ec105a0 Jim Blandy1993-06-22 03:24:23 +0000628(defun holiday-float (month dayname n string &optional day)
5d595461
GM
Glenn Morris2008-04-29 03:35:08 +0000629 "Holiday called STRING on the Nth DAYNAME after/before MONTH DAY.
630DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on.
631If N>0, use the Nth DAYNAME after MONTH DAY.
632If N<0, use the Nth DAYNAME before MONTH DAY.
633DAY defaults to 1 if N>0, and MONTH's last day otherwise.
634If the holiday is visible in the calendar window, returns a
635list (((month day year) STRING)). Otherwise returns nil."
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000636 ;; This is messy because the holiday may be visible, while the date
637 ;; on which it is based is not. For example, the first Monday after
638 ;; December 30 may be visible when January is not. For large values
639 ;; of |n| the problem is more grotesque. If we didn't have to worry
640 ;; about such cases, we could just use the original version of this
641 ;; function:
71855cc5
GM
Glenn Morris2008-03-14 07:05:10 +0000642 ;; (let ((m displayed-month)
643 ;; (y displayed-year))
e803eab7 Glenn Morris2008-04-07 01:59:37 +0000644 ;; (calendar-increment-month m y (- 11 month))
71855cc5
GM
Glenn Morris2008-03-14 07:05:10 +0000645 ;; (if (> m 9); month in year y is visible
646 ;; (list (list (calendar-nth-named-day n dayname month y day) string)))))
151eeaa7
RS
Richard M. Stallman1997-05-20 05:17:49 +0000647 (let* ((m1 displayed-month)
648 (y1 displayed-year)
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000649 (m2 displayed-month)
650 (y2 displayed-year)
651 (d1 (progn ; first possible base date for holiday
e803eab7 Glenn Morris2008-04-07 01:59:37 +0000652 (calendar-increment-month m1 y1 -1)
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000653 (+ (calendar-nth-named-absday 1 dayname m1 y1)
654 (* -7 n)
655 (if (> n 0) 1 -7))))
656 (d2 ; last possible base date for holiday
657 (progn
e803eab7 Glenn Morris2008-04-07 01:59:37 +0000658 (calendar-increment-month m2 y2 1)
151eeaa7
RS
Richard M. Stallman1997-05-20 05:17:49 +0000659 (+ (calendar-nth-named-absday -1 dayname m2 y2)
660 (* -7 n)
d600b865 Glenn Morris2008-04-01 02:47:40 +0000661 (if (> n 0) 7 -1))))
e803eab7
GM
Glenn Morris2008-04-07 01:59:37 +0000662 (y1 (calendar-extract-year (calendar-gregorian-from-absolute d1)))
663 (y2 (calendar-extract-year (calendar-gregorian-from-absolute d2)))
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000664 (y ; year of base date
665 (if (or (= y1 y2) (> month 9))
666 y1
667 y2))
668 (d ; day of base date
669 (or day (if (> n 0)
670 1
671 (calendar-last-day-of-month month y))))
672 (date ; base date for holiday
673 (calendar-absolute-from-gregorian (list month d y))))
674 (and (<= d1 date) (<= date d2)
675 (list (list (calendar-nth-named-day n dayname month y d)
676 string)))))
8ec105a0 Jim Blandy1993-06-22 03:24:23 +0000677
1dbf6332
GM
Glenn Morris2008-04-03 04:10:43 +0000678(defun holiday-filter-visible-calendar (hlist)
679 "Filter list of holidays HLIST, and return only the visible ones.
680HLIST is a list of elements of the form (DATE) TEXT."
681 (delq nil (mapcar (lambda (p)
682 (and (car p) (calendar-date-is-visible-p (car p)) p))
683 hlist)))
71855cc5 Glenn Morris2008-03-14 07:05:10 +0000684
8ec105a0 Jim Blandy1993-06-22 03:24:23 +0000685(defun holiday-sexp (sexp string)
7e1dae73 Jim Blandy1992-08-12 12:50:10 +0000686 "Sexp holiday for dates in the calendar window.
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000687SEXP is an expression in variable `year' that is evaluated to
688give `date'. STRING is an expression in `date' that evaluates to
689the holiday description of `date'. If `date' is visible in the
690calendar window, the holiday STRING is on that date. If date is
691nil, or if the date is not visible, there is no holiday."
7e1dae73 Jim Blandy1992-08-12 12:50:10 +0000692 (let ((m displayed-month)
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000693 (y displayed-year)
694 year date)
e803eab7 Glenn Morris2008-04-07 01:59:37 +0000695 (calendar-increment-month m y -1)
2317a7cf
SM
Stefan Monnier2007-09-07 02:53:10 +0000696 (holiday-filter-visible-calendar
697 (list
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000698 (progn
699 (setq year y
700 date (eval sexp))
701 (list date (if date (eval string))))
702 (progn
703 (setq year (1+ y)
704 date (eval sexp))
705 (list date (if date (eval string))))))))
706
8ec105a0 Jim Blandy1993-06-22 03:24:23 +0000707
92dd6c93
GM
Glenn Morris2004-12-07 00:58:02 +0000708(defun holiday-advent (&optional n string)
709 "Date of Nth day after advent (named STRING), if visible in calendar window.
710Negative values of N are interpreted as days before advent.
711STRING is used purely for display purposes. The return value has
712the form ((MONTH DAY YEAR) STRING), where the date is that of the
713Nth day before or after advent.
714
8dad6f62 Glenn Morris2004-12-07 12:22:19 +0000715For backwards compatibility, if this function is called with no
92dd6c93 Glenn Morris2004-12-07 00:58:02 +0000716arguments, then it returns the value appropriate for advent itself."
8dad6f62 Glenn Morris2004-12-07 12:22:19 +0000717 ;; Backwards compatibility layer.
92dd6c93
GM
Glenn Morris2004-12-07 00:58:02 +0000718 (if (not n)
719 (holiday-advent 0 "Advent")
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000720 (let* ((year displayed-year)
721 (month displayed-month)
722 (advent (progn
e803eab7 Glenn Morris2008-04-07 01:59:37 +0000723 (calendar-increment-month month year -1)
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000724 (calendar-gregorian-from-absolute
725 (+ n
726 (calendar-dayname-on-or-before
727 0
728 (calendar-absolute-from-gregorian
729 (list 12 3 year))))))))
730 (if (calendar-date-is-visible-p advent)
731 (list (list advent string))))))
1a499493 Glenn Morris2004-09-22 23:19:58 +0000732
3cd74de7
GM
Glenn Morris2004-12-07 00:46:08 +0000733(defun holiday-easter-etc (&optional n string)
734 "Date of Nth day after Easter (named STRING), if visible in calendar window.
735Negative values of N are interpreted as days before Easter.
736STRING is used purely for display purposes. The return value has
737the form ((MONTH DAY YEAR) STRING), where the date is that of the
738Nth day before or after Easter.
739
8dad6f62 Glenn Morris2004-12-07 12:22:19 +0000740For backwards compatibility, if this function is called with no
3cd74de7 Glenn Morris2004-12-07 00:46:08 +0000741arguments, then it returns a list of \"standard\" Easter-related
1c76c939 Glenn Morris2008-04-04 04:38:58 +0000742holidays (with more entries if `calendar-christian-all-holidays-flag'
3cd74de7 Glenn Morris2004-12-07 00:46:08 +0000743is non-nil)."
8dad6f62 Glenn Morris2004-12-07 12:22:19 +0000744 ;; Backwards compatibility layer.
3cd74de7 Glenn Morris2004-12-07 00:46:08 +0000745 (if (not n)
1dbf6332
GM
Glenn Morris2008-04-03 04:10:43 +0000746 (apply 'append
747 (mapcar (lambda (e)
748 (apply 'holiday-easter-etc e))
749 ;; The combined list is not in order.
750 (append
1c76c939 Glenn Morris2008-04-04 04:38:58 +0000751 (if calendar-christian-all-holidays-flag
1dbf6332
GM
Glenn Morris2008-04-03 04:10:43 +0000752 '((-63 "Septuagesima Sunday")
753 (-56 "Sexagesima Sunday")
754 (-49 "Shrove Sunday")
755 (-48 "Shrove Monday")
756 (-47 "Shrove Tuesday")
757 (-14 "Passion Sunday")
758 (-7 "Palm Sunday")
759 (-3 "Maundy Thursday")
760 (35 "Rogation Sunday")
761 (39 "Ascension Day")
762 (49 "Pentecost (Whitsunday)")
763 (50 "Whitmonday")
764 (56 "Trinity Sunday")
765 (60 "Corpus Christi")))
766 '((-46 "Ash Wednesday")
767 (-2 "Good Friday")
768 (0 "Easter Sunday")))))
3cd74de7 Glenn Morris2004-12-07 00:46:08 +0000769 (let* ((century (1+ (/ displayed-year 100)))
7e2f1bb5 Glenn Morris2008-03-08 21:07:21 +0000770 (shifted-epact ; age of moon for April 5...
125001e9 Glenn Morris2008-03-15 02:55:45 +0000771 (% (+ 14 (* 11 (% displayed-year 19)) ; ...by Nicaean rule
7e2f1bb5 Glenn Morris2008-03-08 21:07:21 +0000772 (- ; ...corrected for the Gregorian century rule
3cd74de7 Glenn Morris2004-12-07 00:46:08 +0000773 (/ (* 3 century) 4))
71855cc5 Glenn Morris2008-03-14 07:05:10 +0000774 (/ ; ...corrected for Metonic cycle inaccuracy
3cd74de7 Glenn Morris2004-12-07 00:46:08 +0000775 (+ 5 (* 8 century)) 25)
125001e9 Glenn Morris2008-03-15 02:55:45 +0000776 (* 30 century)) ; keeps value positive
3cd74de7 Glenn Morris2004-12-07 00:46:08 +0000777 30))
125001e9 Glenn Morris2008-03-15 02:55:45 +0000778 (adjusted-epact ; adjust for 29.5 day month
3cd74de7
GM
Glenn Morris2004-12-07 00:46:08 +0000779 (if (or (zerop shifted-epact)
780 (and (= shifted-epact 1) (< 10 (% displayed-year 19))))
781 (1+ shifted-epact)
782 shifted-epact))
7e2f1bb5 Glenn Morris2008-03-08 21:07:21 +0000783 (paschal-moon ; day after the full moon on or after March 21
3cd74de7
GM
Glenn Morris2004-12-07 00:46:08 +0000784 (- (calendar-absolute-from-gregorian (list 4 19 displayed-year))
785 adjusted-epact))
1dbf6332
GM
Glenn Morris2008-04-03 04:10:43 +0000786 (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))
787 (greg (calendar-gregorian-from-absolute (+ abs-easter n))))
788 (if (calendar-date-is-visible-p greg)
789 (list (list greg string))))))
1802278a Jim Blandy1991-08-23 03:01:50 +0000790
cfe199f6 Glenn Morris2007-11-27 04:17:22 +0000791;; Prior call to calendar-julian-from-absolute will autoload cal-julian.
5c645a20 Glenn Morris2008-04-04 07:06:53 +0000792(declare-function calendar-julian-to-absolute "cal-julian" (date))
cfe199f6 Glenn Morris2007-11-27 04:17:22 +0000793
8ec105a0
JB
Jim Blandy1993-06-22 03:24:23 +0000794(defun holiday-greek-orthodox-easter ()
795 "Date of Easter according to the rule of the Council of Nicaea."
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000796 (let* ((m displayed-month)
797 (y displayed-year)
798 (julian-year (progn
e803eab7
GM
Glenn Morris2008-04-07 01:59:37 +0000799 (calendar-increment-month m y 1)
800 (calendar-extract-year
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000801 (calendar-julian-from-absolute
802 (calendar-absolute-from-gregorian
803 (list m (calendar-last-day-of-month m y) y))))))
804 (shifted-epact ; age of moon for April 5
805 (% (+ 14
806 (* 11 (% julian-year 19)))
807 30))
808 (paschal-moon ; day after full moon on or after March 21
5c645a20 Glenn Morris2008-04-04 07:06:53 +0000809 (- (calendar-julian-to-absolute (list 4 19 julian-year))
d600b865
GM
Glenn Morris2008-04-01 02:47:40 +0000810 shifted-epact))
811 (nicaean-easter ; Sunday following the Paschal moon
812 (calendar-gregorian-from-absolute
813 (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))))
814 (if (calendar-date-is-visible-p nicaean-easter)
815 (list (list nicaean-easter "Pascha (Greek Orthodox Easter)")))))
7e1dae73 Jim Blandy1992-08-12 12:50:10 +0000816
49116ac0
JB
Jim Blandy1992-03-16 20:39:07 +0000817(provide 'holidays)
818
6818b449
GM
Glenn Morris2012-02-17 22:08:15 -0500819;; Local Variables:
820;; coding: utf-8
821;; End:
822
1a06eabd Eric S. Raymond1992-05-30 23:12:08 +0000823;;; holidays.el ends here