* README: Add a note about ranges in copyright years.
[bpt/emacs.git] / lisp / calendar / cal-hebrew.el
CommitLineData
3afbc435 1;;; cal-hebrew.el --- calendar functions for the Hebrew calendar
4b112ac4 2
0d1bb2ff 3;; Copyright (C) 1995, 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5df4f04c 4;; 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4b112ac4 5
85d0ba86 6;; Author: Nachum Dershowitz <nachum@cs.uiuc.edu>
6b789b4b 7;; Edward M. Reingold <reingold@cs.uiuc.edu>
dbfca9c4 8;; Maintainer: Glenn Morris <rgm@gnu.org>
4b112ac4
ER
9;; Keywords: calendar
10;; Human-Keywords: Hebrew calendar, calendar, diary
bd78fa1d 11;; Package: calendar
4b112ac4
ER
12
13;; This file is part of GNU Emacs.
14
2ed66575 15;; GNU Emacs is free software: you can redistribute it and/or modify
4b112ac4 16;; it under the terms of the GNU General Public License as published by
2ed66575
GM
17;; the Free Software Foundation, either version 3 of the License, or
18;; (at your option) any later version.
4b112ac4
ER
19
20;; GNU Emacs is distributed in the hope that it will be useful,
21;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23;; GNU General Public License for more details.
24
25;; You should have received a copy of the GNU General Public License
2ed66575 26;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
4b112ac4
ER
27
28;;; Commentary:
29
618c03c1 30;; See calendar.el.
a96a5fca 31
4b112ac4
ER
32;;; Code:
33
da3fc020 34(require 'calendar)
4b112ac4 35
1a9f2b77
GM
36(define-obsolete-variable-alias 'diary-sabbath-candles-minutes
37 'diary-hebrew-sabbath-candles-minutes "23.1")
38
87e1e9cd
GM
39(defcustom diary-hebrew-sabbath-candles-minutes 18
40 "Number of minutes before sunset for sabbath candle lighting.
41Used by `diary-hebrew-sabbath-candles'."
42 :group 'diary
43 :type 'integer
44 :version "21.1")
45
87e1e9cd
GM
46;; End of user options.
47
8fc9e5a0 48(defun calendar-hebrew-leap-year-p (year)
6afe7cdd 49 "Non-nil if YEAR is a Hebrew calendar leap year."
4b112ac4
ER
50 (< (% (1+ (* 7 year)) 19) 7))
51
8fc9e5a0 52(defun calendar-hebrew-last-month-of-year (year)
4b112ac4 53 "The last month of the Hebrew calendar YEAR."
8fc9e5a0 54 (if (calendar-hebrew-leap-year-p year)
4b112ac4
ER
55 13
56 12))
57
8fc9e5a0 58(defun calendar-hebrew-elapsed-days (year)
6b789b4b
GM
59 "Days to mean conjunction of Tishri of Hebrew YEAR.
60Measured from Sunday before start of Hebrew calendar."
4b112ac4 61 (let* ((months-elapsed
9c68082d
GM
62 (+ (* 235 (/ (1- year) 19)) ; months in complete cycles so far
63 (* 12 (% (1- year) 19)) ; regular months in this cycle
64 (/ (1+ (* 7 (% (1- year) 19))) 19))) ; leap months this cycle
4b112ac4
ER
65 (parts-elapsed (+ 204 (* 793 (% months-elapsed 1080))))
66 (hours-elapsed (+ 5
67 (* 12 months-elapsed)
68 (* 793 (/ months-elapsed 1080))
69 (/ parts-elapsed 1080)))
71ea27ee 70 (parts ; conjunction parts
4b112ac4 71 (+ (* 1080 (% hours-elapsed 24)) (% parts-elapsed 1080)))
71ea27ee 72 (day ; conjunction day
4b112ac4
ER
73 (+ 1 (* 29 months-elapsed) (/ hours-elapsed 24)))
74 (alternative-day
9c68082d 75 (if (or (>= parts 19440) ; if the new moon is at or after midday
71ea27ee 76 (and (= (% day 7) 2) ; ...or is on a Tuesday...
9c68082d 77 (>= parts 9924) ; at 9 hours, 204 parts or later...
71ea27ee 78 ;; of a common year...
8fc9e5a0 79 (not (calendar-hebrew-leap-year-p year)))
71ea27ee 80 (and (= (% day 7) 1) ; ...or is on a Monday...
9c68082d 81 (>= parts 16789) ; at 15 hours, 589 parts or later...
71ea27ee 82 ;; at the end of a leap year.
8fc9e5a0 83 (calendar-hebrew-leap-year-p (1- year))))
71ea27ee 84 ;; Then postpone Rosh HaShanah one day.
4b112ac4 85 (1+ day)
71ea27ee 86 ;; Else:
4b112ac4 87 day)))
9c68082d
GM
88 ;; If Rosh HaShanah would occur on Sunday, Wednesday, or Friday
89 (if (memq (% alternative-day 7) (list 0 3 5))
71ea27ee 90 ;; Then postpone it one (more) day and return.
4b112ac4 91 (1+ alternative-day)
9c68082d 92 ;; Else return.
4b112ac4
ER
93 alternative-day)))
94
8fc9e5a0 95(defun calendar-hebrew-days-in-year (year)
4b112ac4 96 "Number of days in Hebrew YEAR."
8fc9e5a0
GM
97 (- (calendar-hebrew-elapsed-days (1+ year))
98 (calendar-hebrew-elapsed-days year)))
4b112ac4 99
8fc9e5a0 100(defun calendar-hebrew-long-heshvan-p (year)
6afe7cdd 101 "Non-nil if Heshvan is long in Hebrew YEAR."
8fc9e5a0 102 (= (% (calendar-hebrew-days-in-year year) 10) 5))
4b112ac4 103
8fc9e5a0 104(defun calendar-hebrew-short-kislev-p (year)
6afe7cdd 105 "Non-nil if Kislev is short in Hebrew YEAR."
8fc9e5a0 106 (= (% (calendar-hebrew-days-in-year year) 10) 3))
4b112ac4 107
8fc9e5a0 108(defun calendar-hebrew-last-day-of-month (month year)
da3fc020
GM
109 "The last day of MONTH in YEAR."
110 (if (or (memq month (list 2 4 6 10 13))
8fc9e5a0
GM
111 (and (= month 12) (not (calendar-hebrew-leap-year-p year)))
112 (and (= month 8) (not (calendar-hebrew-long-heshvan-p year)))
113 (and (= month 9) (calendar-hebrew-short-kislev-p year)))
da3fc020
GM
114 29
115 30))
116
8fc9e5a0 117(defun calendar-hebrew-to-absolute (date)
4b112ac4
ER
118 "Absolute date of Hebrew DATE.
119The absolute date is the number of days elapsed since the (imaginary)
120Gregorian date Sunday, December 31, 1 BC."
e803eab7
GM
121 (let ((month (calendar-extract-month date))
122 (day (calendar-extract-day date))
123 (year (calendar-extract-year date)))
71ea27ee
GM
124 (+ day ; days so far this month
125 (if (< month 7) ; before Tishri
126 ;; Then add days in prior months this year before and after Nisan.
4b112ac4 127 (+ (calendar-sum
8fc9e5a0
GM
128 m 7 (<= m (calendar-hebrew-last-month-of-year year))
129 (calendar-hebrew-last-day-of-month m year))
4b112ac4
ER
130 (calendar-sum
131 m 1 (< m month)
8fc9e5a0 132 (calendar-hebrew-last-day-of-month m year)))
71ea27ee 133 ;; Else add days in prior months this year.
4b112ac4
ER
134 (calendar-sum
135 m 7 (< m month)
8fc9e5a0
GM
136 (calendar-hebrew-last-day-of-month m year)))
137 (calendar-hebrew-elapsed-days year) ; days in prior years
71ea27ee 138 -1373429))) ; days elapsed before absolute date 1
4b112ac4 139
8fc9e5a0
GM
140(define-obsolete-function-alias 'calendar-absolute-from-hebrew
141 'calendar-hebrew-to-absolute "23.1")
142
da3fc020
GM
143(defun calendar-hebrew-from-absolute (date)
144 "Compute the Hebrew date (month day year) corresponding to absolute DATE.
145The absolute date is the number of days elapsed since the (imaginary)
146Gregorian date Sunday, December 31, 1 BC."
147 (let* ((greg-date (calendar-gregorian-from-absolute date))
e803eab7 148 (year (+ 3760 (calendar-extract-year greg-date)))
da3fc020 149 (month (aref [9 10 11 12 1 2 3 4 7 7 7 8]
e803eab7 150 (1- (calendar-extract-month greg-date))))
6b789b4b 151 (length (progn
8fc9e5a0 152 (while (>= date (calendar-hebrew-to-absolute
6b789b4b
GM
153 (list 7 1 (1+ year))))
154 (setq year (1+ year)))
8fc9e5a0 155 (calendar-hebrew-last-month-of-year year)))
28c02796 156 day)
6b789b4b 157 (while (> date
8fc9e5a0 158 (calendar-hebrew-to-absolute
6b789b4b 159 (list month
8fc9e5a0 160 (calendar-hebrew-last-day-of-month month year)
6b789b4b
GM
161 year)))
162 (setq month (1+ (% month length))))
da3fc020 163 (setq day (1+
8fc9e5a0 164 (- date (calendar-hebrew-to-absolute (list month 1 year)))))
da3fc020
GM
165 (list month day year)))
166
711d00e7 167(defconst calendar-hebrew-month-name-array-common-year
4b112ac4 168 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri"
da3fc020 169 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar"]
71ea27ee 170 "Array of strings giving the names of the Hebrew months in a common year.")
4b112ac4 171
711d00e7 172(defconst calendar-hebrew-month-name-array-leap-year
4b112ac4 173 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri"
da3fc020 174 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar I" "Adar II"]
71ea27ee 175 "Array of strings giving the names of the Hebrew months in a leap year.")
4b112ac4 176
28b3c0f5 177;;;###cal-autoload
4b112ac4
ER
178(defun calendar-hebrew-date-string (&optional date)
179 "String of Hebrew date before sunset of Gregorian DATE.
180Defaults to today's date if DATE is not given.
181Driven by the variable `calendar-date-display-form'."
182 (let* ((hebrew-date (calendar-hebrew-from-absolute
183 (calendar-absolute-from-gregorian
184 (or date (calendar-current-date)))))
185 (calendar-month-name-array
e803eab7 186 (if (calendar-hebrew-leap-year-p (calendar-extract-year hebrew-date))
4b112ac4
ER
187 calendar-hebrew-month-name-array-leap-year
188 calendar-hebrew-month-name-array-common-year)))
189 (calendar-date-string hebrew-date nil t)))
190
28b3c0f5 191;;;###cal-autoload
8fc9e5a0 192(defun calendar-hebrew-print-date ()
4b112ac4
ER
193 "Show the Hebrew calendar equivalent of the date under the cursor."
194 (interactive)
195 (message "Hebrew date (until sunset): %s"
196 (calendar-hebrew-date-string (calendar-cursor-to-date t))))
197
8fc9e5a0
GM
198(define-obsolete-function-alias 'calendar-print-hebrew-date
199 'calendar-hebrew-print-date "23.1")
200
201(defun calendar-hebrew-yahrzeit (death-date year)
4b112ac4 202 "Absolute date of the anniversary of Hebrew DEATH-DATE in Hebrew YEAR."
e803eab7
GM
203 (let ((death-day (calendar-extract-day death-date))
204 (death-month (calendar-extract-month death-date))
205 (death-year (calendar-extract-year death-date)))
4b112ac4
ER
206 (cond
207 ;; If it's Heshvan 30 it depends on the first anniversary; if
208 ;; that was not Heshvan 30, use the day before Kislev 1.
209 ((and (= death-month 8)
210 (= death-day 30)
8fc9e5a0
GM
211 (not (calendar-hebrew-long-heshvan-p (1+ death-year))))
212 (1- (calendar-hebrew-to-absolute (list 9 1 year))))
9c68082d
GM
213 ;; If it's Kislev 30 it depends on the first anniversary; if that
214 ;; was not Kislev 30, use the day before Teveth 1.
4b112ac4
ER
215 ((and (= death-month 9)
216 (= death-day 30)
8fc9e5a0
GM
217 (calendar-hebrew-short-kislev-p (1+ death-year)))
218 (1- (calendar-hebrew-to-absolute (list 10 1 year))))
9c68082d
GM
219 ;; If it's Adar II, use the same day in last month of year (Adar
220 ;; or Adar II).
4b112ac4 221 ((= death-month 13)
8fc9e5a0
GM
222 (calendar-hebrew-to-absolute
223 (list (calendar-hebrew-last-month-of-year year) death-day year)))
9c68082d
GM
224 ;; If it's the 30th in Adar I and year is not a leap year (so
225 ;; Adar has only 29 days), use the last day in Shevat.
4b112ac4
ER
226 ((and (= death-day 30)
227 (= death-month 12)
8fc9e5a0
GM
228 (not (calendar-hebrew-leap-year-p year)))
229 (calendar-hebrew-to-absolute (list 11 30 year)))
4b112ac4 230 ;; In all other cases, use the normal anniversary of the date of death.
8fc9e5a0 231 (t (calendar-hebrew-to-absolute
4b112ac4
ER
232 (list death-month death-day year))))))
233
8fc9e5a0
GM
234(define-obsolete-function-alias 'hebrew-calendar-yahrzeit
235 'calendar-hebrew-yahrzeit "23.1")
236
42281b7b
GM
237(defun calendar-hebrew-read-date ()
238 "Interactively read the arguments for a Hebrew date command.
239Reads a year, month, and day."
28c02796
GM
240 (let* ((today (calendar-current-date))
241 (year (calendar-read
242 "Hebrew calendar year (>3760): "
243 (lambda (x) (> x 3760))
d92bcf94 244 (number-to-string
e803eab7 245 (calendar-extract-year
28c02796
GM
246 (calendar-hebrew-from-absolute
247 (calendar-absolute-from-gregorian today))))))
8fc9e5a0 248 (month-array (if (calendar-hebrew-leap-year-p year)
28c02796
GM
249 calendar-hebrew-month-name-array-leap-year
250 calendar-hebrew-month-name-array-common-year))
251 (completion-ignore-case t)
252 (month (cdr (assoc-string
253 (completing-read
254 "Hebrew calendar month name: "
255 (mapcar 'list (append month-array nil))
256 (if (= year 3761)
257 (lambda (x)
258 (let ((m (cdr
259 (assoc-string
260 (car x)
261 (calendar-make-alist month-array)
262 t))))
263 (< 0
8fc9e5a0 264 (calendar-hebrew-to-absolute
28c02796 265 (list m
8fc9e5a0 266 (calendar-hebrew-last-day-of-month
28c02796
GM
267 m year)
268 year))))))
269 t)
270 (calendar-make-alist month-array 1) t)))
8fc9e5a0 271 (last (calendar-hebrew-last-day-of-month month year))
28c02796
GM
272 (first (if (and (= year 3761) (= month 10))
273 18 1))
274 (day (calendar-read
275 (format "Hebrew calendar day (%d-%d): "
276 first last)
277 (lambda (x) (and (<= first x) (<= x last))))))
278 (list (list month day year))))
279
28b3c0f5 280;;;###cal-autoload
8fc9e5a0 281(defun calendar-hebrew-goto-date (date &optional noecho)
8f11970d 282 "Move cursor to Hebrew DATE; echo Hebrew date unless NOECHO is non-nil."
42281b7b 283 (interactive (calendar-hebrew-read-date))
4b112ac4 284 (calendar-goto-date (calendar-gregorian-from-absolute
8fc9e5a0
GM
285 (calendar-hebrew-to-absolute date)))
286 (or noecho (calendar-hebrew-print-date)))
287
288(define-obsolete-function-alias 'calendar-goto-hebrew-date
289 'calendar-hebrew-goto-date "23.1")
4b112ac4 290
e803eab7 291(defvar displayed-month) ; from calendar-generate
8f11970d 292
6b789b4b
GM
293(defun calendar-hebrew-date-is-visible-p (month day)
294 "Return non-nil if Hebrew MONTH DAY is visible in the calendar window.
295Returns the corresponding Gregorian date."
9c68082d
GM
296 ;; This test is only to speed things up a bit; it works fine without it.
297 (if (memq displayed-month
1d2a9d53
GM
298 ;; What this is doing is equivalent to +1,2,3,4,5 modulo 12, ie:
299 ;; (mapcar (lambda (n) (let ((x (mod n 12)))
300 ;; (if (zerop x) 12
301 ;; x)))
302 ;; (number-sequence (1+ month) (+ 5 month)))
303 ;; Ie it makes a list:
304 ;; 2 3 4 5 6 when month = 1
305 ;; 3 4 5 6 7 when month = 2
306 ;; ...
307 ;; 8 9 10 11 12 when month = 7
308 ;; 9 10 11 12 1 when month = 8
309 ;; ...
310 ;; 12 1 2 3 4 when month = 11
311 ;; 1 2 3 4 5 when month = 12
312 ;; This implies that hebrew month N cannot occur outside
313 ;; Gregorian months N:N+6 (the calendar shows
314 ;; displayed-month +/- 1 at any time).
315 ;; So to put it another way:
316 ;; (calendar-interval month 1 displayed-month
317 ;; (if (> month displayed-month) 2 1))
318 ;; must be >= 1 and <= 5. This could be expanded to:
319 ;; (if (> month displayed-month) (+ 12 (- displayed-month month))
320 ;; (- displayed-month month)
9c68082d 321 (list
4b112ac4
ER
322 (if (< 11 month) (- month 11) (+ month 1))
323 (if (< 10 month) (- month 10) (+ month 2))
324 (if (< 9 month) (- month 9) (+ month 3))
325 (if (< 8 month) (- month 8) (+ month 4))
326 (if (< 7 month) (- month 7) (+ month 5))))
2f264ff6 327 (calendar-nongregorian-visible-p
8fc9e5a0 328 month day 'calendar-hebrew-to-absolute
2f264ff6
GM
329 'calendar-hebrew-from-absolute
330 ;; Hebrew new year is start of month 7.
331 ;; If hmonth >= 7, choose the higher year.
332 (lambda (m) (> m 6)))))
6b789b4b
GM
333
334;;;###holiday-autoload
335(defun holiday-hebrew (month day string)
336 "Holiday on MONTH, DAY (Hebrew) called STRING.
337If MONTH, DAY (Hebrew) is visible, the value returned is corresponding
338Gregorian date in the form of the list (((month day year) STRING)). Returns
339nil if it is not visible in the current calendar window."
340 (let ((gdate (calendar-hebrew-date-is-visible-p month day)))
341 (if gdate (list (list gdate string)))))
4b112ac4 342
e475d400
GM
343;; h-r-h-e should be called from holidays code.
344(declare-function holiday-filter-visible-calendar "holidays" (l))
345
2f264ff6
GM
346(defvar displayed-year)
347
28b3c0f5 348;;;###holiday-autoload
8fc9e5a0 349(defun holiday-hebrew-rosh-hashanah (&optional all)
f2268dc0 350 "List of dates related to Rosh Hashanah, as visible in calendar window.
1c76c939 351Shows only the major holidays, unless `calendar-hebrew-all-holidays-flag'
f2268dc0
GM
352or ALL is non-nil."
353 (when (memq displayed-month '(8 9 10 11))
8fc9e5a0 354 (let ((abs-r-h (calendar-hebrew-to-absolute
f2268dc0
GM
355 (list 7 1 (+ displayed-year 3761)))))
356 (holiday-filter-visible-calendar
357 (append
358 (list
359 (list (calendar-gregorian-from-absolute abs-r-h)
360 (format "Rosh HaShanah %d" (+ 3761 displayed-year)))
361 (list (calendar-gregorian-from-absolute (+ abs-r-h 9))
362 "Yom Kippur")
363 (list (calendar-gregorian-from-absolute (+ abs-r-h 14))
364 "Sukkot")
365 (list (calendar-gregorian-from-absolute (+ abs-r-h 21))
366 "Shemini Atzeret")
367 (list (calendar-gregorian-from-absolute (+ abs-r-h 22))
368 "Simchat Torah"))
1c76c939 369 (when (or all calendar-hebrew-all-holidays-flag)
f2268dc0
GM
370 (list
371 (list (calendar-gregorian-from-absolute
372 (calendar-dayname-on-or-before 6 (- abs-r-h 4)))
373 "Selichot (night)")
374 (list (calendar-gregorian-from-absolute (1- abs-r-h))
375 "Erev Rosh HaShanah")
376 (list (calendar-gregorian-from-absolute (1+ abs-r-h))
377 "Rosh HaShanah (second day)")
378 (list (calendar-gregorian-from-absolute
85d50db7 379 (+ abs-r-h (if (= (% abs-r-h 7) 4) 3 2)))
f2268dc0
GM
380 "Tzom Gedaliah")
381 (list (calendar-gregorian-from-absolute
382 (calendar-dayname-on-or-before 6 (+ 7 abs-r-h)))
383 "Shabbat Shuvah")
384 (list (calendar-gregorian-from-absolute (+ abs-r-h 8))
385 "Erev Yom Kippur")
386 (list (calendar-gregorian-from-absolute (+ abs-r-h 13))
387 "Erev Sukkot")
388 (list (calendar-gregorian-from-absolute (+ abs-r-h 15))
389 "Sukkot (second day)")
390 (list (calendar-gregorian-from-absolute (+ abs-r-h 16))
391 "Hol Hamoed Sukkot (first day)")
392 (list (calendar-gregorian-from-absolute (+ abs-r-h 17))
393 "Hol Hamoed Sukkot (second day)")
394 (list (calendar-gregorian-from-absolute (+ abs-r-h 18))
395 "Hol Hamoed Sukkot (third day)")
396 (list (calendar-gregorian-from-absolute (+ abs-r-h 19))
397 "Hol Hamoed Sukkot (fourth day)")
398 (list (calendar-gregorian-from-absolute (+ abs-r-h 20))
399 "Hoshanah Rabbah"))))))))
4b112ac4 400
28b3c0f5 401;;;###holiday-autoload
8fc9e5a0
GM
402(define-obsolete-function-alias 'holiday-rosh-hashanah-etc
403 'holiday-hebrew-rosh-hashanah "23.1")
404
405;;;###holiday-autoload
406(defun holiday-hebrew-hanukkah (&optional all)
f2268dc0 407 "List of dates related to Hanukkah, as visible in calendar window.
1c76c939 408Shows only Hanukkah, unless `calendar-hebrew-all-holidays-flag' or ALL
f2268dc0 409is non-nil."
9c68082d 410 ;; This test is only to speed things up a bit, it works fine without it.
f2268dc0
GM
411 (when (memq displayed-month '(10 11 12 1 2))
412 (let* ((m displayed-month)
413 (y displayed-year)
414 (h-y (progn
e803eab7
GM
415 (calendar-increment-month m y 1)
416 (calendar-extract-year
f2268dc0
GM
417 (calendar-hebrew-from-absolute
418 (calendar-absolute-from-gregorian
419 (list m (calendar-last-day-of-month m y) y))))))
8fc9e5a0 420 (abs-h (calendar-hebrew-to-absolute (list 9 25 h-y)))
f2268dc0
GM
421 (ord ["first" "second" "third" "fourth" "fifth" "sixth"
422 "seventh" "eighth"])
423 han)
424 (holiday-filter-visible-calendar
1c76c939 425 (if (or all calendar-hebrew-all-holidays-flag)
f2268dc0
GM
426 (append
427 (list
428 (list (calendar-gregorian-from-absolute (1- abs-h))
429 "Erev Hanukkah"))
430 (dotimes (i 8 (nreverse han))
431 (push (list
432 (calendar-gregorian-from-absolute (+ abs-h i))
433 (format "Hanukkah (%s day)" (aref ord i)))
434 han)))
435 (list (list (calendar-gregorian-from-absolute abs-h) "Hanukkah")))))))
4b112ac4 436
28b3c0f5 437;;;###holiday-autoload
8fc9e5a0
GM
438(define-obsolete-function-alias 'holiday-hanukkah
439 'holiday-hebrew-hanukkah "23.1")
440
441;;;###holiday-autoload
442(defun holiday-hebrew-passover (&optional all)
f2268dc0 443 "List of dates related to Passover, as visible in calendar window.
1c76c939 444Shows only the major holidays, unless `calendar-hebrew-all-holidays-flag'
f2268dc0
GM
445or ALL is non-nil."
446 (when (< displayed-month 8)
8fc9e5a0 447 (let ((abs-p (calendar-hebrew-to-absolute
f2268dc0
GM
448 (list 1 15 (+ displayed-year 3760)))))
449 (holiday-filter-visible-calendar
450 ;; The first two are out of order when the others are added.
451 (append
452 (list
453 (list (calendar-gregorian-from-absolute abs-p) "Passover")
454 (list (calendar-gregorian-from-absolute (+ abs-p 50))
455 "Shavuot"))
1c76c939 456 (when (or all calendar-hebrew-all-holidays-flag)
85d50db7
GM
457 (let ((wday (% abs-p 7)))
458 (list
459 (list (calendar-gregorian-from-absolute
460 (calendar-dayname-on-or-before 6 (- abs-p 43)))
461 "Shabbat Shekalim")
462 (list (calendar-gregorian-from-absolute
463 (calendar-dayname-on-or-before 6 (- abs-p 30)))
464 "Shabbat Zachor")
465 (list (calendar-gregorian-from-absolute
466 (- abs-p (if (= wday 2) 33 31)))
467 "Fast of Esther")
468 (list (calendar-gregorian-from-absolute (- abs-p 31))
469 "Erev Purim")
470 (list (calendar-gregorian-from-absolute (- abs-p 30))
471 "Purim")
472 (list (calendar-gregorian-from-absolute
473 (- abs-p (if (zerop wday) 28 29)))
474 "Shushan Purim")
475 (list (calendar-gregorian-from-absolute
476 (- (calendar-dayname-on-or-before 6 (- abs-p 14)) 7))
477 "Shabbat Parah")
478 (list (calendar-gregorian-from-absolute
479 (calendar-dayname-on-or-before 6 (- abs-p 14)))
480 "Shabbat HaHodesh")
481 (list (calendar-gregorian-from-absolute
482 (calendar-dayname-on-or-before 6 (1- abs-p)))
483 "Shabbat HaGadol")
484 (list (calendar-gregorian-from-absolute (1- abs-p))
485 "Erev Passover")
486 (list (calendar-gregorian-from-absolute (1+ abs-p))
487 "Passover (second day)")
488 (list (calendar-gregorian-from-absolute (+ abs-p 2))
489 "Hol Hamoed Passover (first day)")
490 (list (calendar-gregorian-from-absolute (+ abs-p 3))
491 "Hol Hamoed Passover (second day)")
492 (list (calendar-gregorian-from-absolute (+ abs-p 4))
493 "Hol Hamoed Passover (third day)")
494 (list (calendar-gregorian-from-absolute (+ abs-p 5))
495 "Hol Hamoed Passover (fourth day)")
496 (list (calendar-gregorian-from-absolute (+ abs-p 6))
497 "Passover (seventh day)")
498 (list (calendar-gregorian-from-absolute (+ abs-p 7))
499 "Passover (eighth day)")
500 (list (calendar-gregorian-from-absolute
501 (+ abs-p (if (zerop (% (+ abs-p 12) 7))
502 13
503 12)))
504 "Yom HaShoah")
505 (list (calendar-gregorian-from-absolute
506 (+ abs-p
507 ;; If falls on Sat or Fri, moves to preceding Thurs.
508 ;; If falls on Mon, moves to Tues (since 2004).
509 (cond ((zerop wday) 18) ; Sat
510 ((= wday 6) 19) ; Fri
511 ((= wday 2) 21) ; Mon
512 (t 20))))
513 "Yom HaAtzma'ut")
514 (list (calendar-gregorian-from-absolute (+ abs-p 33))
515 "Lag BaOmer")
516 (list (calendar-gregorian-from-absolute (+ abs-p 43))
517 "Yom Yerushalaim")
518 (list (calendar-gregorian-from-absolute (+ abs-p 49))
519 "Erev Shavuot")
520 (list (calendar-gregorian-from-absolute (+ abs-p 51))
521 "Shavuot (second day)")))))))))
4b112ac4 522
28b3c0f5 523;;;###holiday-autoload
8fc9e5a0
GM
524(define-obsolete-function-alias 'holiday-passover-etc
525 'holiday-hebrew-passover "23.1")
526
527;;;###holiday-autoload
528(defun holiday-hebrew-tisha-b-av ()
4b112ac4 529 "List of dates around Tisha B'Av, as visible in calendar window."
f2268dc0 530 (when (memq displayed-month '(5 6 7 8 9))
85d50db7
GM
531 (let* ((abs-t-a (calendar-hebrew-to-absolute
532 (list 5 9 (+ displayed-year 3760))))
533 (wday (% abs-t-a 7)))
8705f7f3 534 (holiday-filter-visible-calendar
a1506d29 535 (list
4b112ac4 536 (list (calendar-gregorian-from-absolute
85d50db7 537 (- abs-t-a (if (= wday 6) 20 21)))
4b112ac4
ER
538 "Tzom Tammuz")
539 (list (calendar-gregorian-from-absolute
540 (calendar-dayname-on-or-before 6 abs-t-a))
541 "Shabbat Hazon")
542 (list (calendar-gregorian-from-absolute
85d50db7 543 (if (= wday 6) (1+ abs-t-a) abs-t-a))
4b112ac4
ER
544 "Tisha B'Av")
545 (list (calendar-gregorian-from-absolute
546 (calendar-dayname-on-or-before 6 (+ abs-t-a 7)))
547 "Shabbat Nahamu"))))))
548
8fc9e5a0
GM
549;;;###holiday-autoload
550(define-obsolete-function-alias 'holiday-tisha-b-av-etc
551 'holiday-hebrew-tisha-b-av "23.1")
552
f2268dc0
GM
553(autoload 'holiday-julian "cal-julian")
554
555;;;###holiday-autoload
556(defun holiday-hebrew-misc ()
557 "Miscellaneous Hebrew holidays, if visible in calendar window.
558Includes: Tal Umatar, Tzom Teveth, Tu B'Shevat, Shabbat Shirah, and
559Kiddush HaHamah."
560 (let ((m displayed-month)
561 (y displayed-year)
85d50db7 562 year h-year)
f2268dc0
GM
563 (append
564 (holiday-julian
565 11
566 (progn
e803eab7
GM
567 (calendar-increment-month m y -1)
568 (setq year (calendar-extract-year
f2268dc0
GM
569 (calendar-julian-from-absolute
570 (calendar-absolute-from-gregorian (list m 1 y)))))
571 (if (zerop (% (1+ year) 4))
572 22
573 21)) "\"Tal Umatar\" (evening)")
574 (holiday-hebrew
575 10
576 (progn
e803eab7 577 (setq h-year (calendar-extract-year
f2268dc0
GM
578 (calendar-hebrew-from-absolute
579 (calendar-absolute-from-gregorian
580 (list displayed-month 28 displayed-year)))))
8fc9e5a0 581 (if (= 6 (% (calendar-hebrew-to-absolute (list 10 10 h-year))
f2268dc0
GM
582 7))
583 11 10))
584 "Tzom Teveth")
585 (holiday-hebrew 11 15 "Tu B'Shevat")
586 (holiday-hebrew
587 11
588 (progn
589 (setq m displayed-month
590 y displayed-year
591 h-year (progn
e803eab7
GM
592 (calendar-increment-month m y 1)
593 (calendar-extract-year
f2268dc0
GM
594 (calendar-hebrew-from-absolute
595 (calendar-absolute-from-gregorian
85d50db7
GM
596 (list m (calendar-last-day-of-month m y) y))))))
597 (calendar-extract-day
598 (calendar-hebrew-from-absolute
599 (calendar-dayname-on-or-before
600 6 (calendar-hebrew-to-absolute
601 (list 11
602 (if (= 6
603 (% (calendar-hebrew-to-absolute
604 (list 7 1 h-year))
605 7))
606 17 16) h-year))))))
f2268dc0
GM
607 "Shabbat Shirah")
608 (and (progn
609 (setq m displayed-month
610 y displayed-year
611 year (progn
e803eab7
GM
612 (calendar-increment-month m y -1)
613 (calendar-extract-year
f2268dc0
GM
614 (calendar-julian-from-absolute
615 (calendar-absolute-from-gregorian (list m 1 y))))))
616 (= 21 (% year 28)))
617 (holiday-julian 3 26 "Kiddush HaHamah")))))
618
619
711d00e7 620(autoload 'diary-list-entries-1 "diary-lib")
c3efd659 621
28b3c0f5 622;;;###diary-autoload
8fc9e5a0 623(defun diary-hebrew-list-entries ()
4b112ac4 624 "Add any Hebrew date entries from the diary file to `diary-entries-list'.
0e96e25f 625Hebrew date diary entries must be prefaced by `diary-hebrew-entry-symbol'
8f11970d
GM
626\(normally an `H'). The same diary date forms govern the style
627of the Hebrew calendar entries, except that the Hebrew month
872edde5 628names cannot be abbreviated. The Hebrew months are numbered
8f11970d
GM
629from 1 to 13 with Nisan being 1, 12 being Adar I and 13 being
630Adar II; you must use `Adar I' if you want Adar of a common
631Hebrew year. If a Hebrew date diary entry begins with
632`diary-nonmarking-symbol', the entry will appear in the diary
633listing, but will not be marked in the calendar. This function
9ee4e581 634is provided for use with `diary-nongregorian-listing-hook'."
711d00e7 635 (diary-list-entries-1 calendar-hebrew-month-name-array-leap-year
0e96e25f 636 diary-hebrew-entry-symbol
711d00e7 637 'calendar-hebrew-from-absolute))
8fc9e5a0
GM
638;;;###diary-autoload
639(define-obsolete-function-alias 'list-hebrew-diary-entries
640 'diary-hebrew-list-entries "23.1")
4b112ac4 641
28c02796
GM
642(autoload 'calendar-mark-complex "diary-lib")
643
28b3c0f5 644;;;###diary-autoload
8fc9e5a0 645(defun calendar-hebrew-mark-date-pattern (month day year &optional color)
da3fc020 646 "Mark dates in calendar window that conform to Hebrew date MONTH/DAY/YEAR.
28c02796 647A value of 0 in any position is a wildcard. Optional argument COLOR is
e803eab7 648passed to `calendar-mark-visible-date' as MARK."
28c02796
GM
649 ;; FIXME not the same as the Bahai and Islamic cases, so can't use
650 ;; calendar-mark-1.
937e6a56 651 (with-current-buffer calendar-buffer
0d1bb2ff
GM
652 (if (and (not (zerop month)) (not (zerop day)))
653 (if (not (zerop year))
da3fc020
GM
654 ;; Fully specified Hebrew date.
655 (let ((date (calendar-gregorian-from-absolute
8fc9e5a0 656 (calendar-hebrew-to-absolute
da3fc020
GM
657 (list month day year)))))
658 (if (calendar-date-is-visible-p date)
e803eab7 659 (calendar-mark-visible-date date color)))
6b789b4b
GM
660 ;; Month and day in any year.
661 (let ((gdate (calendar-hebrew-date-is-visible-p month day)))
e803eab7 662 (if gdate (calendar-mark-visible-date gdate color))))
28c02796
GM
663 (calendar-mark-complex month day year
664 'calendar-hebrew-from-absolute color))))
da3fc020 665
8fc9e5a0
GM
666;;;###diary-autoload
667(define-obsolete-function-alias 'mark-hebrew-calendar-date-pattern
668 'calendar-hebrew-mark-date-pattern "23.1")
669
711d00e7 670(autoload 'diary-mark-entries-1 "diary-lib")
e475d400 671
28b3c0f5 672;;;###diary-autoload
8fc9e5a0 673(defun diary-hebrew-mark-entries ()
4b112ac4 674 "Mark days in the calendar window that have Hebrew date diary entries.
711d00e7
GM
675Marks each entry in `diary-file' (or included files) visible in the calendar
676window. See `list-hebrew-diary-entries' for more information."
8fc9e5a0 677 (diary-mark-entries-1 'calendar-hebrew-mark-date-pattern
618c03c1 678 calendar-hebrew-month-name-array-leap-year
0e96e25f 679 diary-hebrew-entry-symbol
618c03c1 680 'calendar-hebrew-from-absolute))
4b112ac4 681
8fc9e5a0
GM
682;;;###diary-autoload
683(define-obsolete-function-alias 'mark-hebrew-diary-entries
684 'diary-hebrew-mark-entries "23.1")
f2b46435
GM
685
686(autoload 'diary-insert-entry-1 "diary-lib")
687
28b3c0f5 688;;;###cal-autoload
8fc9e5a0
GM
689(defun diary-hebrew-insert-entry (arg)
690 "Insert a diary entry for the Hebrew date at point.
6afe7cdd 691Prefix argument ARG makes the entry nonmarking."
4b112ac4 692 (interactive "P")
f2b46435 693 (diary-insert-entry-1 nil arg calendar-hebrew-month-name-array-leap-year
0e96e25f 694 diary-hebrew-entry-symbol
f2b46435 695 'calendar-hebrew-from-absolute))
4b112ac4 696
8fc9e5a0
GM
697;;;###diary-autoload
698(define-obsolete-function-alias 'insert-hebrew-diary-entry
699 'diary-hebrew-insert-entry "23.1")
700
28b3c0f5 701;;;###cal-autoload
8fc9e5a0 702(defun diary-hebrew-insert-monthly-entry (arg)
4b112ac4
ER
703 "Insert a monthly diary entry.
704For the day of the Hebrew month corresponding to the date indicated by point.
6afe7cdd 705Prefix argument ARG makes the entry nonmarking."
4b112ac4 706 (interactive "P")
f2b46435 707 (diary-insert-entry-1 'monthly arg calendar-hebrew-month-name-array-leap-year
0e96e25f 708 diary-hebrew-entry-symbol
f2b46435 709 'calendar-hebrew-from-absolute))
8fc9e5a0
GM
710;;;###diary-autoload
711(define-obsolete-function-alias 'insert-monthly-hebrew-diary-entry
712 'diary-hebrew-insert-monthly-entry "23.1")
4b112ac4 713
28b3c0f5 714;;;###cal-autoload
8fc9e5a0 715(defun diary-hebrew-insert-yearly-entry (arg)
4b112ac4
ER
716 "Insert an annual diary entry.
717For the day of the Hebrew year corresponding to the date indicated by point.
6afe7cdd 718Prefix argument ARG makes the entry nonmarking."
4b112ac4 719 (interactive "P")
f2b46435 720 (diary-insert-entry-1 'yearly arg calendar-hebrew-month-name-array-leap-year
0e96e25f 721 diary-hebrew-entry-symbol
f2b46435 722 'calendar-hebrew-from-absolute))
8fc9e5a0
GM
723;;;###diary-autoload
724(define-obsolete-function-alias 'insert-yearly-hebrew-diary-entry
725 'diary-hebrew-insert-yearly-entry "23.1")
4b112ac4
ER
726
727;;;###autoload
4e740fd0 728(defun calendar-hebrew-list-yahrzeits (death-date start-year end-year)
4b112ac4
ER
729 "List Yahrzeit dates for *Gregorian* DEATH-DATE from START-YEAR to END-YEAR.
730When called interactively from the calendar window, the date of death is taken
731from the cursor position."
732 (interactive
733 (let* ((death-date
734 (if (equal (current-buffer) (get-buffer calendar-buffer))
735 (calendar-cursor-to-date)
736 (let* ((today (calendar-current-date))
737 (year (calendar-read
738 "Year of death (>0): "
c645b7bb 739 (lambda (x) (> x 0))
d92bcf94 740 (number-to-string (calendar-extract-year today))))
4b112ac4
ER
741 (month-array calendar-month-name-array)
742 (completion-ignore-case t)
abe4091c 743 (month (cdr (assoc-string
bf7b2caf
RS
744 (completing-read
745 "Month of death (name): "
746 (mapcar 'list (append month-array nil))
747 nil t)
abe4091c 748 (calendar-make-alist month-array 1) t)))
4b112ac4
ER
749 (last (calendar-last-day-of-month month year))
750 (day (calendar-read
751 (format "Day of death (1-%d): " last)
c645b7bb 752 (lambda (x) (and (< 0 x) (<= x last))))))
4b112ac4 753 (list month day year))))
e803eab7 754 (death-year (calendar-extract-year death-date))
4b112ac4
ER
755 (start-year (calendar-read
756 (format "Starting year of Yahrzeit table (>%d): "
757 death-year)
c645b7bb 758 (lambda (x) (> x death-year))
d92bcf94 759 (number-to-string (1+ death-year))))
4b112ac4
ER
760 (end-year (calendar-read
761 (format "Ending year of Yahrzeit table (>=%d): "
762 start-year)
71ea27ee
GM
763 (lambda (x) (>= x start-year)))))
764 (list death-date start-year end-year)))
6afe7cdd 765 (message "Computing Yahrzeits...")
66471e03 766 (let* ((h-date (calendar-hebrew-from-absolute
4b112ac4 767 (calendar-absolute-from-gregorian death-date)))
e803eab7
GM
768 (h-month (calendar-extract-month h-date))
769 (h-day (calendar-extract-day h-date))
770 (h-year (calendar-extract-year h-date))
2d354894 771 (i (1- start-year)))
e803eab7 772 (calendar-in-read-only-buffer calendar-hebrew-yahrzeit-buffer
318a5488
GM
773 (calendar-set-mode-line
774 (format "Yahrzeit dates for %s = %s"
775 (calendar-date-string death-date)
776 (let ((calendar-month-name-array
8fc9e5a0 777 (if (calendar-hebrew-leap-year-p h-year)
318a5488
GM
778 calendar-hebrew-month-name-array-leap-year
779 calendar-hebrew-month-name-array-common-year)))
780 (calendar-date-string h-date nil t))))
2d354894 781 (while (<= (setq i (1+ i)) end-year)
318a5488
GM
782 (insert
783 (calendar-date-string
784 (calendar-gregorian-from-absolute
8fc9e5a0 785 (calendar-hebrew-yahrzeit
318a5488 786 h-date
e803eab7 787 (calendar-extract-year
318a5488 788 (calendar-hebrew-from-absolute
2d354894
GM
789 (calendar-absolute-from-gregorian (list 1 1 i))))))) "\n"))))
790 (message "Computing Yahrzeits...done"))
4b112ac4 791
8fc9e5a0
GM
792;;;###autoload
793(define-obsolete-function-alias 'list-yahrzeit-dates
4e740fd0 794 'calendar-hebrew-list-yahrzeits "23.1")
8fc9e5a0 795
c3efd659
GM
796(defvar date)
797
9ee4e581 798;; To be called from diary-list-sexp-entries, where DATE is bound.
28b3c0f5 799;;;###diary-autoload
4b112ac4
ER
800(defun diary-hebrew-date ()
801 "Hebrew calendar equivalent of date diary entry."
802 (format "Hebrew date (until sunset): %s" (calendar-hebrew-date-string date)))
803
28b3c0f5 804;;;###diary-autoload
8fc9e5a0 805(defun diary-hebrew-omer (&optional mark)
4b112ac4 806 "Omer count diary entry.
9a27723c
RS
807Entry applies if date is within 50 days after Passover.
808
a1506d29 809An optional parameter MARK specifies a face or single-character string to
9a27723c 810use when highlighting the day in the calendar."
4b112ac4 811 (let* ((passover
8fc9e5a0 812 (calendar-hebrew-to-absolute
e803eab7 813 (list 1 15 (+ (calendar-extract-year date) 3760))))
4b112ac4
ER
814 (omer (- (calendar-absolute-from-gregorian date) passover))
815 (week (/ omer 7))
816 (day (% omer 7)))
817 (if (and (> omer 0) (< omer 50))
a1506d29 818 (cons mark
71ea27ee
GM
819 (format "Day %d%s of the omer (until sunset)"
820 omer
821 (if (zerop week)
822 ""
823 (format ", that is, %d week%s%s"
824 week
825 (if (= week 1) "" "s")
826 (if (zerop day)
827 ""
828 (format " and %d day%s"
829 day (if (= day 1) "" "s"))))))))))
8fc9e5a0
GM
830;;;###diary-autoload
831(define-obsolete-function-alias 'diary-omer 'diary-hebrew-omer "23.1")
4b112ac4 832
c3efd659
GM
833(defvar entry)
834
f2b46435
GM
835(autoload 'diary-make-date "diary-lib")
836
b4cb42a4
GM
837(declare-function diary-ordinal-suffix "diary-lib" (n))
838
28b3c0f5 839;;;###diary-autoload
8fc9e5a0 840(defun diary-hebrew-yahrzeit (death-month death-day death-year &optional mark)
6afe7cdd 841 "Yahrzeit diary entry--entry applies if date is Yahrzeit or the day before.
f2b46435
GM
842Parameters are DEATH-MONTH, DEATH-DAY, DEATH-YEAR; the diary
843entry is assumed to be the name of the person. Although the date
844of death is specified by the civil calendar, the proper Hebrew
845calendar Yahrzeit is determined.
846
847The order of the input parameters changes according to `calendar-date-style'
848\(e.g. to DEATH-DAY, DEATH-MONTH, DEATH-YEAR in the European style).
9a27723c 849
a1506d29 850An optional parameter MARK specifies a face or single-character string to
9a27723c 851use when highlighting the day in the calendar."
4b112ac4
ER
852 (let* ((h-date (calendar-hebrew-from-absolute
853 (calendar-absolute-from-gregorian
f2b46435 854 (diary-make-date death-month death-day death-year))))
e803eab7
GM
855 (h-month (calendar-extract-month h-date))
856 (h-day (calendar-extract-day h-date))
857 (h-year (calendar-extract-year h-date))
4b112ac4 858 (d (calendar-absolute-from-gregorian date))
e803eab7 859 (yr (calendar-extract-year (calendar-hebrew-from-absolute d)))
4b112ac4 860 (diff (- yr h-year))
8fc9e5a0 861 (y (calendar-hebrew-yahrzeit h-date yr)))
4b112ac4 862 (if (and (> diff 0) (or (= y d) (= y (1+ d))))
9a27723c 863 (cons mark
71ea27ee
GM
864 (format "Yahrzeit of %s%s: %d%s anniversary"
865 entry
866 (if (= y d) "" " (evening)")
867 diff
4980d28f
GM
868 (diary-ordinal-suffix diff))))))
869
8fc9e5a0
GM
870;;;###diary-autoload
871(define-obsolete-function-alias 'diary-yahrzeit 'diary-hebrew-yahrzeit "23.1")
4b112ac4 872
28b3c0f5 873;;;###diary-autoload
8fc9e5a0 874(defun diary-hebrew-rosh-hodesh (&optional mark)
4b112ac4 875 "Rosh Hodesh diary entry.
9a27723c
RS
876Entry applies if date is Rosh Hodesh, the day before, or the Saturday before.
877
a1506d29 878An optional parameter MARK specifies a face or single-character string to
9a27723c 879use when highlighting the day in the calendar."
4b112ac4
ER
880 (let* ((d (calendar-absolute-from-gregorian date))
881 (h-date (calendar-hebrew-from-absolute d))
e803eab7
GM
882 (h-month (calendar-extract-month h-date))
883 (h-day (calendar-extract-day h-date))
884 (h-year (calendar-extract-year h-date))
8fc9e5a0
GM
885 (leap-year (calendar-hebrew-leap-year-p h-year))
886 (last-day (calendar-hebrew-last-day-of-month h-month h-year))
4b112ac4
ER
887 (h-month-names
888 (if leap-year
889 calendar-hebrew-month-name-array-leap-year
890 calendar-hebrew-month-name-array-common-year))
891 (this-month (aref h-month-names (1- h-month)))
e803eab7 892 (h-yesterday (calendar-extract-day
4b112ac4
ER
893 (calendar-hebrew-from-absolute (1- d)))))
894 (if (or (= h-day 30) (and (= h-day 1) (/= h-month 7)))
a1506d29 895 (cons mark
71ea27ee
GM
896 (format
897 "Rosh Hodesh %s"
898 (if (= h-day 30)
899 (format
900 "%s (first day)"
901 ;; Next month must be in the same year since this
902 ;; month can't be the last month of the year since
903 ;; it has 30 days
904 (aref h-month-names h-month))
905 (if (= h-yesterday 30)
906 (format "%s (second day)" this-month)
907 this-month))))
908 (if (= (% d 7) 6) ; Saturday--check for Shabbat Mevarchim
a1506d29 909 (cons mark
71ea27ee
GM
910 (cond ((and (> h-day 22) (/= h-month 6) (= 29 last-day))
911 (format "Mevarchim Rosh Hodesh %s (%s)"
912 (aref h-month-names
913 (if (= h-month
8fc9e5a0 914 (calendar-hebrew-last-month-of-year
71ea27ee
GM
915 h-year))
916 0 h-month))
917 (aref calendar-day-name-array (- 29 h-day))))
918 ((and (< h-day 30) (> h-day 22) (= 30 last-day))
919 (format "Mevarchim Rosh Hodesh %s (%s-%s)"
920 (aref h-month-names h-month)
921 (if (= h-day 29)
922 "tomorrow"
923 (aref calendar-day-name-array (- 29 h-day)))
924 (aref calendar-day-name-array
925 (% (- 30 h-day) 7))))))
4b112ac4 926 (if (and (= h-day 29) (/= h-month 6))
347a0e23 927 (cons mark
71ea27ee
GM
928 (format "Erev Rosh Hodesh %s"
929 (aref h-month-names
930 (if (= h-month
8fc9e5a0 931 (calendar-hebrew-last-month-of-year
71ea27ee
GM
932 h-year))
933 0 h-month)))))))))
8fc9e5a0
GM
934;;;###diary-autoload
935(define-obsolete-function-alias 'diary-rosh-hodesh
936 'diary-hebrew-rosh-hodesh "23.1")
9a27723c 937
8fc9e5a0 938(defconst calendar-hebrew-parashiot-names
71ea27ee
GM
939 ["Bereshith" "Noah" "Lech L'cha" "Vayera" "Hayei Sarah" "Toledoth"
940 "Vayetze" "Vayishlah" "Vayeshev" "Mikketz" "Vayiggash" "Vayhi"
941 "Shemoth" "Vaera" "Bo" "Beshallah" "Yithro" "Mishpatim"
942 "Terumah" "Tetzavveh" "Ki Tissa" "Vayakhel" "Pekudei" "Vayikra"
943 "Tzav" "Shemini" "Tazria" "Metzora" "Aharei Moth" "Kedoshim"
944 "Emor" "Behar" "Behukkotai" "Bemidbar" "Naso" "Behaalot'cha"
945 "Shelah L'cha" "Korah" "Hukkath" "Balak" "Pinhas" "Mattoth"
946 "Masei" "Devarim" "Vaethanan" "Ekev" "Reeh" "Shofetim"
947 "Ki Tetze" "Ki Tavo" "Nitzavim" "Vayelech" "Haazinu"]
da3fc020
GM
948 "The names of the parashiot in the Torah.")
949
8fc9e5a0 950(defun calendar-hebrew-parasha-name (p)
da3fc020 951 "Name(s) corresponding to parasha P."
71ea27ee 952 (if (arrayp p) ; combined parasha
da3fc020 953 (format "%s/%s"
8fc9e5a0
GM
954 (aref calendar-hebrew-parashiot-names (aref p 0))
955 (aref calendar-hebrew-parashiot-names (aref p 1)))
956 (aref calendar-hebrew-parashiot-names p)))
da3fc020 957
711d00e7 958;; Following 14 constants are used in diary-parasha (intern).
8f11970d 959
9c68082d 960;; The seven ordinary year types (keviot).
8fc9e5a0 961(defconst calendar-hebrew-year-Saturday-incomplete-Sunday
4b112ac4 962 [nil 52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [21 22]
71ea27ee
GM
963 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
964 43 44 45 46 47 48 49 50]
4b112ac4
ER
965 "The structure of the parashiot.
966Hebrew year starts on Saturday, is `incomplete' (Heshvan and Kislev each have
96729 days), and has Passover start on Sunday.")
968
8fc9e5a0 969(defconst calendar-hebrew-year-Saturday-complete-Tuesday
4b112ac4 970 [nil 52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [21 22]
71ea27ee
GM
971 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
972 43 44 45 46 47 48 49 [50 51]]
4b112ac4
ER
973 "The structure of the parashiot.
974Hebrew year that starts on Saturday, is `complete' (Heshvan and Kislev each
975have 30 days), and has Passover start on Tuesday.")
976
8fc9e5a0 977(defconst calendar-hebrew-year-Monday-incomplete-Tuesday
4b112ac4 978 [51 52 nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [21 22]
71ea27ee
GM
979 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
980 43 44 45 46 47 48 49 [50 51]]
4b112ac4
ER
981 "The structure of the parashiot.
982Hebrew year that starts on Monday, is `incomplete' (Heshvan and Kislev each
983have 29 days), and has Passover start on Tuesday.")
984
8fc9e5a0 985(defconst calendar-hebrew-year-Monday-complete-Thursday
4b112ac4 986 [51 52 nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [21 22]
71ea27ee
GM
987 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 (nil . 34) (34 . 35) (35 . 36)
988 (36 . 37) (37 . 38) ([38 39] . 39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
4b112ac4
ER
989 "The structure of the parashiot.
990Hebrew year that starts on Monday, is `complete' (Heshvan and Kislev each have
99130 days), and has Passover start on Thursday.")
992
8fc9e5a0 993(defconst calendar-hebrew-year-Tuesday-regular-Thursday
4b112ac4 994 [51 52 nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [21 22]
71ea27ee
GM
995 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 (nil . 34) (34 . 35) (35 . 36)
996 (36 . 37) (37 . 38) ([38 39] . 39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
4b112ac4
ER
997 "The structure of the parashiot.
998Hebrew year that starts on Tuesday, is `regular' (Heshvan has 29 days and
999Kislev has 30 days), and has Passover start on Thursday.")
1000
8fc9e5a0 1001(defconst calendar-hebrew-year-Thursday-regular-Saturday
4b112ac4 1002 [52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [21 22] 23
71ea27ee
GM
1003 24 nil (nil . 25) (25 . [26 27]) ([26 27] . [28 29]) ([28 29] . 30)
1004 (30 . 31) ([31 32] . 32) 33 34 35 36 37 38 39 40 [41 42] 43 44 45 46 47 48
1005 49 50]
4b112ac4
ER
1006 "The structure of the parashiot.
1007Hebrew year that starts on Thursday, is `regular' (Heshvan has 29 days and
1008Kislev has 30 days), and has Passover start on Saturday.")
1009
8fc9e5a0 1010(defconst calendar-hebrew-year-Thursday-complete-Sunday
4b112ac4 1011 [52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
71ea27ee
GM
1012 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
1013 43 44 45 46 47 48 49 50]
4b112ac4
ER
1014 "The structure of the parashiot.
1015Hebrew year that starts on Thursday, is `complete' (Heshvan and Kislev each
1016have 30 days), and has Passover start on Sunday.")
1017
9c68082d 1018;; The seven leap year types (keviot).
8fc9e5a0 1019(defconst calendar-hebrew-year-Saturday-incomplete-Tuesday
4b112ac4 1020 [nil 52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
71ea27ee
GM
1021 23 24 25 26 27 nil 28 29 30 31 32 33 34 35 36 37 38 39 40 [41 42]
1022 43 44 45 46 47 48 49 [50 51]]
4b112ac4
ER
1023 "The structure of the parashiot.
1024Hebrew year that starts on Saturday, is `incomplete' (Heshvan and Kislev each
1025have 29 days), and has Passover start on Tuesday.")
1026
8fc9e5a0 1027(defconst calendar-hebrew-year-Saturday-complete-Thursday
4b112ac4 1028 [nil 52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
71ea27ee
GM
1029 23 24 25 26 27 nil 28 29 30 31 32 33 (nil . 34) (34 . 35) (35 . 36)
1030 (36 . 37) (37 . 38) ([38 39] . 39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
4b112ac4
ER
1031 "The structure of the parashiot.
1032Hebrew year that starts on Saturday, is `complete' (Heshvan and Kislev each
1033have 30 days), and has Passover start on Thursday.")
1034
8fc9e5a0 1035(defconst calendar-hebrew-year-Monday-incomplete-Thursday
4b112ac4 1036 [51 52 nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
71ea27ee
GM
1037 23 24 25 26 27 nil 28 29 30 31 32 33 (nil . 34) (34 . 35) (35 . 36)
1038 (36 . 37) (37 . 38) ([38 39] . 39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
4b112ac4
ER
1039 "The structure of the parashiot.
1040Hebrew year that starts on Monday, is `incomplete' (Heshvan and Kislev each
1041have 29 days), and has Passover start on Thursday.")
1042
8fc9e5a0 1043(defconst calendar-hebrew-year-Monday-complete-Saturday
4b112ac4 1044 [51 52 nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
71ea27ee
GM
1045 23 24 25 26 27 nil (nil . 28) (28 . 29) (29 . 30) (30 . 31) (31 . 32)
1046 (32 . 33) (33 . 34) (34 . 35) (35 . 36) (36 . 37) (37 . 38) (38 . 39)
1047 (39 . 40) (40 . 41) ([41 42] . 42) 43 44 45 46 47 48 49 50]
4b112ac4
ER
1048 "The structure of the parashiot.
1049Hebrew year that starts on Monday, is `complete' (Heshvan and Kislev each have
105030 days), and has Passover start on Saturday.")
1051
8fc9e5a0 1052(defconst calendar-hebrew-year-Tuesday-regular-Saturday
4b112ac4 1053 [51 52 nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
71ea27ee
GM
1054 23 24 25 26 27 nil (nil . 28) (28 . 29) (29 . 30) (30 . 31) (31 . 32)
1055 (32 . 33) (33 . 34) (34 . 35) (35 . 36) (36 . 37) (37 . 38) (38 . 39)
1056 (39 . 40) (40 . 41) ([41 42] . 42) 43 44 45 46 47 48 49 50]
4b112ac4
ER
1057 "The structure of the parashiot.
1058Hebrew year that starts on Tuesday, is `regular' (Heshvan has 29 days and
1059Kislev has 30 days), and has Passover start on Saturday.")
1060
8fc9e5a0 1061(defconst calendar-hebrew-year-Thursday-incomplete-Sunday
4b112ac4 1062 [52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
71ea27ee
GM
1063 23 24 25 26 27 28 nil 29 30 31 32 33 34 35 36 37 38 39 40 41 42
1064 43 44 45 46 47 48 49 50]
4b112ac4
ER
1065 "The structure of the parashiot.
1066Hebrew year that starts on Thursday, is `incomplete' (Heshvan and Kislev both
1067have 29 days), and has Passover start on Sunday.")
1068
8fc9e5a0 1069(defconst calendar-hebrew-year-Thursday-complete-Tuesday
4b112ac4 1070 [52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
71ea27ee
GM
1071 23 24 25 26 27 28 nil 29 30 31 32 33 34 35 36 37 38 39 40 41 42
1072 43 44 45 46 47 48 49 [50 51]]
4b112ac4
ER
1073 "The structure of the parashiot.
1074Hebrew year that starts on Thursday, is `complete' (Heshvan and Kislev both
1075have 30 days), and has Passover start on Tuesday.")
1076
711d00e7 1077;;;###diary-autoload
8fc9e5a0 1078(defun diary-hebrew-parasha (&optional mark)
711d00e7
GM
1079 "Parasha diary entry--entry applies if date is a Saturday.
1080An optional parameter MARK specifies a face or single-character string to
1081use when highlighting the day in the calendar."
1082 (let ((d (calendar-absolute-from-gregorian date)))
1083 (if (= (% d 7) 6) ; Saturday
e803eab7 1084 (let* ((h-year (calendar-extract-year
711d00e7
GM
1085 (calendar-hebrew-from-absolute d)))
1086 (rosh-hashanah
8fc9e5a0 1087 (calendar-hebrew-to-absolute (list 7 1 h-year)))
711d00e7 1088 (passover
8fc9e5a0 1089 (calendar-hebrew-to-absolute (list 1 15 h-year)))
711d00e7
GM
1090 (rosh-hashanah-day
1091 (aref calendar-day-name-array (% rosh-hashanah 7)))
1092 (passover-day
1093 (aref calendar-day-name-array (% passover 7)))
8fc9e5a0
GM
1094 (long-h (calendar-hebrew-long-heshvan-p h-year))
1095 (short-k (calendar-hebrew-short-kislev-p h-year))
711d00e7
GM
1096 (type (cond ((and long-h (not short-k)) "complete")
1097 ((and (not long-h) short-k) "incomplete")
1098 (t "regular")))
1099 (year-format
1100 (symbol-value
8fc9e5a0 1101 (intern (format "calendar-hebrew-year-%s-%s-%s" ; keviah
711d00e7
GM
1102 rosh-hashanah-day type passover-day))))
1103 (first-saturday ; of Hebrew year
1104 (calendar-dayname-on-or-before 6 (+ 6 rosh-hashanah)))
1105 (saturday ; which Saturday of the Hebrew year
1106 (/ (- d first-saturday) 7))
1107 (parasha (aref year-format saturday)))
1108 (if parasha
1109 (cons mark
1110 (format
1111 "Parashat %s"
1112 (if (listp parasha) ; Israel differs from diaspora
1113 (if (car parasha)
1114 (format "%s (diaspora), %s (Israel)"
8fc9e5a0 1115 (calendar-hebrew-parasha-name
711d00e7 1116 (car parasha))
8fc9e5a0 1117 (calendar-hebrew-parasha-name
711d00e7
GM
1118 (cdr parasha)))
1119 (format "%s (Israel)"
8fc9e5a0 1120 (calendar-hebrew-parasha-name
711d00e7 1121 (cdr parasha))))
8fc9e5a0
GM
1122 (calendar-hebrew-parasha-name parasha)))))))))
1123
1124(define-obsolete-function-alias 'diary-parasha 'diary-hebrew-parasha "23.1")
711d00e7 1125
87e1e9cd
GM
1126
1127(declare-function solar-setup "solar" ())
1128(declare-function solar-sunrise-sunset "solar" (date))
1129(defvar calendar-latitude)
1130(defvar calendar-longitude)
1131(defvar calendar-time-zone)
1132
1133
9ee4e581 1134;; To be called from diary-list-sexp-entries, where DATE is bound.
87e1e9cd
GM
1135;;;###diary-autoload
1136(defun diary-hebrew-sabbath-candles (&optional mark)
1137 "Local time of candle lighting diary entry--applies if date is a Friday.
1138No diary entry if there is no sunset on that date. Uses
1139`diary-hebrew-sabbath-candles-minutes'.
1140
1141An optional parameter MARK specifies a face or single-character string to
1142use when highlighting the day in the calendar."
1143 (require 'solar)
1144 (or (and calendar-latitude calendar-longitude calendar-time-zone)
1145 (solar-setup))
1146 (if (= (% (calendar-absolute-from-gregorian date) 7) 5) ; Friday
d347df4f 1147 (let ((sunset (cadr (solar-sunrise-sunset date))))
87e1e9cd 1148 (if sunset
d347df4f
GM
1149 (cons mark (format
1150 "%s Sabbath candle lighting"
1151 (apply 'solar-time-string
1152 (cons (- (car sunset)
1153 (/ diary-hebrew-sabbath-candles-minutes
1154 60.0))
1155 (cdr sunset)))))))))
87e1e9cd
GM
1156
1157;;;###diary-autoload
1158(define-obsolete-function-alias 'diary-sabbath-candles
1159 'diary-hebrew-sabbath-candles "23.1")
1160
1161
4b112ac4
ER
1162(provide 'cal-hebrew)
1163
1164;;; cal-hebrew.el ends here