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