1 ;;; cal-hebrew.el --- calendar functions for the Hebrew calendar
3 ;; Copyright (C) 1995, 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008 Free Software Foundation, Inc.
6 ;; Author: Nachum Dershowitz <nachum@cs.uiuc.edu>
7 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
8 ;; Maintainer: Glenn Morris <rgm@gnu.org>
10 ;; Human-Keywords: Hebrew calendar, calendar, diary
12 ;; This file is part of GNU Emacs.
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, or (at your option)
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.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
37 (defun hebrew-calendar-leap-year-p (year)
38 "Non-nil if YEAR is a Hebrew calendar leap year."
39 (< (%
(1+ (* 7 year
)) 19) 7))
41 (defun hebrew-calendar-last-month-of-year (year)
42 "The last month of the Hebrew calendar YEAR."
43 (if (hebrew-calendar-leap-year-p year
)
47 (defun hebrew-calendar-elapsed-days (year)
48 "Days to mean conjunction of Tishri of Hebrew YEAR.
49 Measured from Sunday before start of Hebrew calendar."
50 (let* ((months-elapsed
51 (+ (* 235 (/ (1- year
) 19)) ; months in complete cycles so far
52 (* 12 (%
(1- year
) 19)) ; regular months in this cycle
53 (/ (1+ (* 7 (%
(1- year
) 19))) 19))) ; leap months this cycle
54 (parts-elapsed (+ 204 (* 793 (% months-elapsed
1080))))
57 (* 793 (/ months-elapsed
1080))
58 (/ parts-elapsed
1080)))
59 (parts ; conjunction parts
60 (+ (* 1080 (% hours-elapsed
24)) (% parts-elapsed
1080)))
61 (day ; conjunction day
62 (+ 1 (* 29 months-elapsed
) (/ hours-elapsed
24)))
64 (if (or (>= parts
19440) ; if the new moon is at or after midday
65 (and (= (% day
7) 2) ; ...or is on a Tuesday...
66 (>= parts
9924) ; at 9 hours, 204 parts or later...
67 ;; of a common year...
68 (not (hebrew-calendar-leap-year-p year
)))
69 (and (= (% day
7) 1) ; ...or is on a Monday...
70 (>= parts
16789) ; at 15 hours, 589 parts or later...
71 ;; at the end of a leap year.
72 (hebrew-calendar-leap-year-p (1- year
))))
73 ;; Then postpone Rosh HaShanah one day.
77 ;; If Rosh HaShanah would occur on Sunday, Wednesday, or Friday
78 (if (memq (% alternative-day
7) (list 0 3 5))
79 ;; Then postpone it one (more) day and return.
84 (defun hebrew-calendar-days-in-year (year)
85 "Number of days in Hebrew YEAR."
86 (- (hebrew-calendar-elapsed-days (1+ year
))
87 (hebrew-calendar-elapsed-days year
)))
89 (defun hebrew-calendar-long-heshvan-p (year)
90 "Non-nil if Heshvan is long in Hebrew YEAR."
91 (= (%
(hebrew-calendar-days-in-year year
) 10) 5))
93 (defun hebrew-calendar-short-kislev-p (year)
94 "Non-nil if Kislev is short in Hebrew YEAR."
95 (= (%
(hebrew-calendar-days-in-year year
) 10) 3))
97 (defun hebrew-calendar-last-day-of-month (month year
)
98 "The last day of MONTH in YEAR."
99 (if (or (memq month
(list 2 4 6 10 13))
100 (and (= month
12) (not (hebrew-calendar-leap-year-p year
)))
101 (and (= month
8) (not (hebrew-calendar-long-heshvan-p year
)))
102 (and (= month
9) (hebrew-calendar-short-kislev-p year
)))
106 (defun calendar-absolute-from-hebrew (date)
107 "Absolute date of Hebrew DATE.
108 The absolute date is the number of days elapsed since the (imaginary)
109 Gregorian date Sunday, December 31, 1 BC."
110 (let ((month (extract-calendar-month date
))
111 (day (extract-calendar-day date
))
112 (year (extract-calendar-year date
)))
113 (+ day
; days so far this month
114 (if (< month
7) ; before Tishri
115 ;; Then add days in prior months this year before and after Nisan.
117 m
7 (<= m
(hebrew-calendar-last-month-of-year year
))
118 (hebrew-calendar-last-day-of-month m year
))
121 (hebrew-calendar-last-day-of-month m year
)))
122 ;; Else add days in prior months this year.
125 (hebrew-calendar-last-day-of-month m year
)))
126 (hebrew-calendar-elapsed-days year
) ; days in prior years
127 -
1373429))) ; days elapsed before absolute date 1
129 (defun calendar-hebrew-from-absolute (date)
130 "Compute the Hebrew date (month day year) corresponding to absolute DATE.
131 The absolute date is the number of days elapsed since the (imaginary)
132 Gregorian date Sunday, December 31, 1 BC."
133 (let* ((greg-date (calendar-gregorian-from-absolute date
))
134 (year (+ 3760 (extract-calendar-year greg-date
)))
135 (month (aref [9 10 11 12 1 2 3 4 7 7 7 8]
136 (1- (extract-calendar-month greg-date
))))
138 (while (>= date
(calendar-absolute-from-hebrew
139 (list 7 1 (1+ year
))))
140 (setq year
(1+ year
)))
141 (hebrew-calendar-last-month-of-year year
)))
144 (calendar-absolute-from-hebrew
146 (hebrew-calendar-last-day-of-month month year
)
148 (setq month
(1+ (% month length
))))
150 (- date
(calendar-absolute-from-hebrew (list month
1 year
)))))
151 (list month day year
)))
153 (defconst calendar-hebrew-month-name-array-common-year
154 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri"
155 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar"]
156 "Array of strings giving the names of the Hebrew months in a common year.")
158 (defconst calendar-hebrew-month-name-array-leap-year
159 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri"
160 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar I" "Adar II"]
161 "Array of strings giving the names of the Hebrew months in a leap year.")
164 (defun calendar-hebrew-date-string (&optional date
)
165 "String of Hebrew date before sunset of Gregorian DATE.
166 Defaults to today's date if DATE is not given.
167 Driven by the variable `calendar-date-display-form'."
168 (let* ((hebrew-date (calendar-hebrew-from-absolute
169 (calendar-absolute-from-gregorian
170 (or date
(calendar-current-date)))))
171 (calendar-month-name-array
172 (if (hebrew-calendar-leap-year-p (extract-calendar-year hebrew-date
))
173 calendar-hebrew-month-name-array-leap-year
174 calendar-hebrew-month-name-array-common-year
)))
175 (calendar-date-string hebrew-date nil t
)))
178 (defun calendar-print-hebrew-date ()
179 "Show the Hebrew calendar equivalent of the date under the cursor."
181 (message "Hebrew date (until sunset): %s"
182 (calendar-hebrew-date-string (calendar-cursor-to-date t
))))
184 (defun hebrew-calendar-yahrzeit (death-date year
)
185 "Absolute date of the anniversary of Hebrew DEATH-DATE in Hebrew YEAR."
186 (let ((death-day (extract-calendar-day death-date
))
187 (death-month (extract-calendar-month death-date
))
188 (death-year (extract-calendar-year death-date
)))
190 ;; If it's Heshvan 30 it depends on the first anniversary; if
191 ;; that was not Heshvan 30, use the day before Kislev 1.
192 ((and (= death-month
8)
194 (not (hebrew-calendar-long-heshvan-p (1+ death-year
))))
195 (1- (calendar-absolute-from-hebrew (list 9 1 year
))))
196 ;; If it's Kislev 30 it depends on the first anniversary; if that
197 ;; was not Kislev 30, use the day before Teveth 1.
198 ((and (= death-month
9)
200 (hebrew-calendar-short-kislev-p (1+ death-year
)))
201 (1- (calendar-absolute-from-hebrew (list 10 1 year
))))
202 ;; If it's Adar II, use the same day in last month of year (Adar
205 (calendar-absolute-from-hebrew
206 (list (hebrew-calendar-last-month-of-year year
) death-day year
)))
207 ;; If it's the 30th in Adar I and year is not a leap year (so
208 ;; Adar has only 29 days), use the last day in Shevat.
209 ((and (= death-day
30)
211 (not (hebrew-calendar-leap-year-p year
)))
212 (calendar-absolute-from-hebrew (list 11 30 year
)))
213 ;; In all other cases, use the normal anniversary of the date of death.
214 (t (calendar-absolute-from-hebrew
215 (list death-month death-day year
))))))
217 (defun calendar-hebrew-read-date ()
218 "Interactively read the arguments for a Hebrew date command.
219 Reads a year, month, and day."
220 (let* ((today (calendar-current-date))
222 "Hebrew calendar year (>3760): "
223 (lambda (x) (> x
3760))
225 (extract-calendar-year
226 (calendar-hebrew-from-absolute
227 (calendar-absolute-from-gregorian today
))))))
228 (month-array (if (hebrew-calendar-leap-year-p year
)
229 calendar-hebrew-month-name-array-leap-year
230 calendar-hebrew-month-name-array-common-year
))
231 (completion-ignore-case t
)
232 (month (cdr (assoc-string
234 "Hebrew calendar month name: "
235 (mapcar 'list
(append month-array nil
))
241 (calendar-make-alist month-array
)
244 (calendar-absolute-from-hebrew
246 (hebrew-calendar-last-day-of-month
250 (calendar-make-alist month-array
1) t
)))
251 (last (hebrew-calendar-last-day-of-month month year
))
252 (first (if (and (= year
3761) (= month
10))
255 (format "Hebrew calendar day (%d-%d): "
257 (lambda (x) (and (<= first x
) (<= x last
))))))
258 (list (list month day year
))))
261 (defun calendar-goto-hebrew-date (date &optional noecho
)
262 "Move cursor to Hebrew DATE; echo Hebrew date unless NOECHO is non-nil."
263 (interactive (calendar-hebrew-read-date))
264 (calendar-goto-date (calendar-gregorian-from-absolute
265 (calendar-absolute-from-hebrew date
)))
266 (or noecho
(calendar-print-hebrew-date)))
268 (defvar displayed-month
) ; from generate-calendar
270 (defun calendar-hebrew-date-is-visible-p (month day
)
271 "Return non-nil if Hebrew MONTH DAY is visible in the calendar window.
272 Returns the corresponding Gregorian date."
273 ;; This test is only to speed things up a bit; it works fine without it.
274 (if (memq displayed-month
275 ;; What this is doing is equivalent to +1,2,3,4,5 modulo 12, ie:
276 ;; (mapcar (lambda (n) (let ((x (mod n 12)))
279 ;; (number-sequence (1+ month) (+ 5 month)))
280 ;; Ie it makes a list:
281 ;; 2 3 4 5 6 when month = 1
282 ;; 3 4 5 6 7 when month = 2
284 ;; 8 9 10 11 12 when month = 7
285 ;; 9 10 11 12 1 when month = 8
287 ;; 12 1 2 3 4 when month = 11
288 ;; 1 2 3 4 5 when month = 12
289 ;; This implies that hebrew month N cannot occur outside
290 ;; Gregorian months N:N+6 (the calendar shows
291 ;; displayed-month +/- 1 at any time).
292 ;; So to put it another way:
293 ;; (calendar-interval month 1 displayed-month
294 ;; (if (> month displayed-month) 2 1))
295 ;; must be >= 1 and <= 5. This could be expanded to:
296 ;; (if (> month displayed-month) (+ 12 (- displayed-month month))
297 ;; (- displayed-month month)
299 (if (< 11 month
) (- month
11) (+ month
1))
300 (if (< 10 month
) (- month
10) (+ month
2))
301 (if (< 9 month
) (- month
9) (+ month
3))
302 (if (< 8 month
) (- month
8) (+ month
4))
303 (if (< 7 month
) (- month
7) (+ month
5))))
304 (calendar-nongregorian-visible-p
305 month day
'calendar-absolute-from-hebrew
306 'calendar-hebrew-from-absolute
307 ;; Hebrew new year is start of month 7.
308 ;; If hmonth >= 7, choose the higher year.
309 (lambda (m) (> m
6)))))
311 ;;;###holiday-autoload
312 (defun holiday-hebrew (month day string
)
313 "Holiday on MONTH, DAY (Hebrew) called STRING.
314 If MONTH, DAY (Hebrew) is visible, the value returned is corresponding
315 Gregorian date in the form of the list (((month day year) STRING)). Returns
316 nil if it is not visible in the current calendar window."
317 (let ((gdate (calendar-hebrew-date-is-visible-p month day
)))
318 (if gdate
(list (list gdate string
)))))
320 ;; h-r-h-e should be called from holidays code.
321 (declare-function holiday-filter-visible-calendar
"holidays" (l))
323 (defvar displayed-year
)
325 ;;;###holiday-autoload
326 (defun holiday-rosh-hashanah-etc ()
327 "List of dates related to Rosh Hashanah, as visible in calendar window."
328 (unless (or (< displayed-month
8) ; none of the dates is visible
329 (> displayed-month
11))
330 (let* ((abs-r-h (calendar-absolute-from-hebrew
331 (list 7 1 (+ displayed-year
3761))))
334 (list (calendar-gregorian-from-absolute abs-r-h
)
335 (format "Rosh HaShanah %d" (+ 3761 displayed-year
)))
336 (list (calendar-gregorian-from-absolute (+ abs-r-h
9))
338 (list (calendar-gregorian-from-absolute (+ abs-r-h
14))
340 (list (calendar-gregorian-from-absolute (+ abs-r-h
21))
342 (list (calendar-gregorian-from-absolute (+ abs-r-h
22))
346 (list (calendar-gregorian-from-absolute
347 (calendar-dayname-on-or-before 6 (- abs-r-h
4)))
349 (list (calendar-gregorian-from-absolute (1- abs-r-h
))
350 "Erev Rosh HaShanah")
351 (list (calendar-gregorian-from-absolute (1+ abs-r-h
))
352 "Rosh HaShanah (second day)")
353 (list (calendar-gregorian-from-absolute
354 (if (= (% abs-r-h
7) 4) (+ abs-r-h
3) (+ abs-r-h
2)))
356 (list (calendar-gregorian-from-absolute
357 (calendar-dayname-on-or-before 6 (+ 7 abs-r-h
)))
359 (list (calendar-gregorian-from-absolute (+ abs-r-h
8))
361 (list (calendar-gregorian-from-absolute (+ abs-r-h
13))
363 (list (calendar-gregorian-from-absolute (+ abs-r-h
15))
364 "Sukkot (second day)")
365 (list (calendar-gregorian-from-absolute (+ abs-r-h
16))
366 "Hol Hamoed Sukkot (first day)")
367 (list (calendar-gregorian-from-absolute (+ abs-r-h
17))
368 "Hol Hamoed Sukkot (second day)")
369 (list (calendar-gregorian-from-absolute (+ abs-r-h
18))
370 "Hol Hamoed Sukkot (third day)")
371 (list (calendar-gregorian-from-absolute (+ abs-r-h
19))
372 "Hol Hamoed Sukkot (fourth day)")
373 (list (calendar-gregorian-from-absolute (+ abs-r-h
20))
376 (holiday-filter-visible-calendar mandatory
)))
377 (if all-hebrew-calendar-holidays
380 (holiday-filter-visible-calendar optional
)
384 ;;;###holiday-autoload
385 (defun holiday-hanukkah ()
386 "List of dates related to Hanukkah, as visible in calendar window."
387 ;; This test is only to speed things up a bit, it works fine without it.
388 (if (memq displayed-month
390 (let* ((m displayed-month
)
393 (increment-calendar-month m y
1)
394 (extract-calendar-year
395 (calendar-hebrew-from-absolute
396 (calendar-absolute-from-gregorian
397 (list m
(calendar-last-day-of-month m y
) y
))))))
398 (abs-h (calendar-absolute-from-hebrew (list 9 25 h-y
))))
399 (holiday-filter-visible-calendar
401 (list (calendar-gregorian-from-absolute (1- abs-h
))
403 (list (calendar-gregorian-from-absolute abs-h
)
404 "Hanukkah (first day)")
405 (list (calendar-gregorian-from-absolute (1+ abs-h
))
406 "Hanukkah (second day)")
407 (list (calendar-gregorian-from-absolute (+ abs-h
2))
408 "Hanukkah (third day)")
409 (list (calendar-gregorian-from-absolute (+ abs-h
3))
410 "Hanukkah (fourth day)")
411 (list (calendar-gregorian-from-absolute (+ abs-h
4))
412 "Hanukkah (fifth day)")
413 (list (calendar-gregorian-from-absolute (+ abs-h
5))
414 "Hanukkah (sixth day)")
415 (list (calendar-gregorian-from-absolute (+ abs-h
6))
416 "Hanukkah (seventh day)")
417 (list (calendar-gregorian-from-absolute (+ abs-h
7))
418 "Hanukkah (eighth day)"))))))
420 ;;;###holiday-autoload
421 (defun holiday-passover-etc ()
422 "List of dates related to Passover, as visible in calendar window."
423 (unless (< 7 displayed-month
) ; none of the dates is visible
424 (let* ((abs-p (calendar-absolute-from-hebrew
425 (list 1 15 (+ displayed-year
3760))))
428 (list (calendar-gregorian-from-absolute abs-p
)
430 (list (calendar-gregorian-from-absolute (+ abs-p
50))
434 (list (calendar-gregorian-from-absolute
435 (calendar-dayname-on-or-before 6 (- abs-p
43)))
437 (list (calendar-gregorian-from-absolute
438 (calendar-dayname-on-or-before 6 (- abs-p
30)))
440 (list (calendar-gregorian-from-absolute
441 (if (= (% abs-p
7) 2) (- abs-p
33) (- abs-p
31)))
443 (list (calendar-gregorian-from-absolute (- abs-p
31))
445 (list (calendar-gregorian-from-absolute (- abs-p
30))
447 (list (calendar-gregorian-from-absolute
448 (if (zerop (% abs-p
7)) (- abs-p
28) (- abs-p
29)))
450 (list (calendar-gregorian-from-absolute
451 (- (calendar-dayname-on-or-before 6 (- abs-p
14)) 7))
453 (list (calendar-gregorian-from-absolute
454 (calendar-dayname-on-or-before 6 (- abs-p
14)))
456 (list (calendar-gregorian-from-absolute
457 (calendar-dayname-on-or-before 6 (1- abs-p
)))
459 (list (calendar-gregorian-from-absolute (1- abs-p
))
461 (list (calendar-gregorian-from-absolute (1+ abs-p
))
462 "Passover (second day)")
463 (list (calendar-gregorian-from-absolute (+ abs-p
2))
464 "Hol Hamoed Passover (first day)")
465 (list (calendar-gregorian-from-absolute (+ abs-p
3))
466 "Hol Hamoed Passover (second day)")
467 (list (calendar-gregorian-from-absolute (+ abs-p
4))
468 "Hol Hamoed Passover (third day)")
469 (list (calendar-gregorian-from-absolute (+ abs-p
5))
470 "Hol Hamoed Passover (fourth day)")
471 (list (calendar-gregorian-from-absolute (+ abs-p
6))
472 "Passover (seventh day)")
473 (list (calendar-gregorian-from-absolute (+ abs-p
7))
474 "Passover (eighth day)")
475 (list (calendar-gregorian-from-absolute
476 (if (zerop (%
(+ abs-p
12) 7))
480 (list (calendar-gregorian-from-absolute
481 (if (zerop (% abs-p
7))
483 (if (= (% abs-p
7) 6)
487 (list (calendar-gregorian-from-absolute (+ abs-p
33))
489 (list (calendar-gregorian-from-absolute (+ abs-p
43))
491 (list (calendar-gregorian-from-absolute (+ abs-p
49))
493 (list (calendar-gregorian-from-absolute (+ abs-p
51))
494 "Shavuot (second day)")))
496 (holiday-filter-visible-calendar mandatory
)))
497 (if all-hebrew-calendar-holidays
500 (holiday-filter-visible-calendar optional
)
504 ;;;###holiday-autoload
505 (defun holiday-tisha-b-av-etc ()
506 "List of dates around Tisha B'Av, as visible in calendar window."
507 (unless (or (< displayed-month
5) ; none of the dates is visible
508 (> displayed-month
9))
509 (let ((abs-t-a (calendar-absolute-from-hebrew
510 (list 5 9 (+ displayed-year
3760)))))
511 (holiday-filter-visible-calendar
513 (list (calendar-gregorian-from-absolute
514 (if (= (% abs-t-a
7) 6) (- abs-t-a
20) (- abs-t-a
21)))
516 (list (calendar-gregorian-from-absolute
517 (calendar-dayname-on-or-before 6 abs-t-a
))
519 (list (calendar-gregorian-from-absolute
520 (if (= (% abs-t-a
7) 6) (1+ abs-t-a
) abs-t-a
))
522 (list (calendar-gregorian-from-absolute
523 (calendar-dayname-on-or-before 6 (+ abs-t-a
7)))
524 "Shabbat Nahamu"))))))
526 (autoload 'diary-list-entries-1
"diary-lib")
529 (defun list-hebrew-diary-entries ()
530 "Add any Hebrew date entries from the diary file to `diary-entries-list'.
531 Hebrew date diary entries must be prefaced by `hebrew-diary-entry-symbol'
532 \(normally an `H'). The same diary date forms govern the style
533 of the Hebrew calendar entries, except that the Hebrew month
534 names cannot be abbreviated. The Hebrew months are numbered
535 from 1 to 13 with Nisan being 1, 12 being Adar I and 13 being
536 Adar II; you must use `Adar I' if you want Adar of a common
537 Hebrew year. If a Hebrew date diary entry begins with
538 `diary-nonmarking-symbol', the entry will appear in the diary
539 listing, but will not be marked in the calendar. This function
540 is provided for use with `nongregorian-diary-listing-hook'."
541 (diary-list-entries-1 calendar-hebrew-month-name-array-leap-year
542 hebrew-diary-entry-symbol
543 'calendar-hebrew-from-absolute
))
545 (autoload 'calendar-mark-complex
"diary-lib")
548 (defun mark-hebrew-calendar-date-pattern (month day year
&optional color
)
549 "Mark dates in calendar window that conform to Hebrew date MONTH/DAY/YEAR.
550 A value of 0 in any position is a wildcard. Optional argument COLOR is
551 passed to `mark-visible-calendar-date' as MARK."
552 ;; FIXME not the same as the Bahai and Islamic cases, so can't use
555 (set-buffer calendar-buffer
)
556 (if (and (not (zerop month
)) (not (zerop day
)))
557 (if (not (zerop year
))
558 ;; Fully specified Hebrew date.
559 (let ((date (calendar-gregorian-from-absolute
560 (calendar-absolute-from-hebrew
561 (list month day year
)))))
562 (if (calendar-date-is-visible-p date
)
563 (mark-visible-calendar-date date color
)))
564 ;; Month and day in any year.
565 (let ((gdate (calendar-hebrew-date-is-visible-p month day
)))
566 (if gdate
(mark-visible-calendar-date gdate color
))))
567 (calendar-mark-complex month day year
568 'calendar-hebrew-from-absolute color
))))
570 (autoload 'diary-mark-entries-1
"diary-lib")
573 (defun mark-hebrew-diary-entries ()
574 "Mark days in the calendar window that have Hebrew date diary entries.
575 Marks each entry in `diary-file' (or included files) visible in the calendar
576 window. See `list-hebrew-diary-entries' for more information."
577 (diary-mark-entries-1 'mark-hebrew-calendar-date-pattern
578 calendar-hebrew-month-name-array-leap-year
579 hebrew-diary-entry-symbol
580 'calendar-hebrew-from-absolute
))
583 (autoload 'diary-insert-entry-1
"diary-lib")
586 (defun insert-hebrew-diary-entry (arg)
587 "Insert a diary entry.
588 For the Hebrew date corresponding to the date indicated by point.
589 Prefix argument ARG makes the entry nonmarking."
591 (diary-insert-entry-1 nil arg calendar-hebrew-month-name-array-leap-year
592 hebrew-diary-entry-symbol
593 'calendar-hebrew-from-absolute
))
596 (defun insert-monthly-hebrew-diary-entry (arg)
597 "Insert a monthly diary entry.
598 For the day of the Hebrew month corresponding to the date indicated by point.
599 Prefix argument ARG makes the entry nonmarking."
601 (diary-insert-entry-1 'monthly arg calendar-hebrew-month-name-array-leap-year
602 hebrew-diary-entry-symbol
603 'calendar-hebrew-from-absolute
))
606 (defun insert-yearly-hebrew-diary-entry (arg)
607 "Insert an annual diary entry.
608 For the day of the Hebrew year corresponding to the date indicated by point.
609 Prefix argument ARG makes the entry nonmarking."
611 (diary-insert-entry-1 'yearly arg calendar-hebrew-month-name-array-leap-year
612 hebrew-diary-entry-symbol
613 'calendar-hebrew-from-absolute
))
616 (defun list-yahrzeit-dates (death-date start-year end-year
)
617 "List Yahrzeit dates for *Gregorian* DEATH-DATE from START-YEAR to END-YEAR.
618 When called interactively from the calendar window, the date of death is taken
619 from the cursor position."
622 (if (equal (current-buffer) (get-buffer calendar-buffer
))
623 (calendar-cursor-to-date)
624 (let* ((today (calendar-current-date))
626 "Year of death (>0): "
628 (int-to-string (extract-calendar-year today
))))
629 (month-array calendar-month-name-array
)
630 (completion-ignore-case t
)
631 (month (cdr (assoc-string
633 "Month of death (name): "
634 (mapcar 'list
(append month-array nil
))
636 (calendar-make-alist month-array
1) t
)))
637 (last (calendar-last-day-of-month month year
))
639 (format "Day of death (1-%d): " last
)
640 (lambda (x) (and (< 0 x
) (<= x last
))))))
641 (list month day year
))))
642 (death-year (extract-calendar-year death-date
))
643 (start-year (calendar-read
644 (format "Starting year of Yahrzeit table (>%d): "
646 (lambda (x) (> x death-year
))
647 (int-to-string (1+ death-year
))))
648 (end-year (calendar-read
649 (format "Ending year of Yahrzeit table (>=%d): "
651 (lambda (x) (>= x start-year
)))))
652 (list death-date start-year end-year
)))
653 (message "Computing Yahrzeits...")
654 (let* ((h-date (calendar-hebrew-from-absolute
655 (calendar-absolute-from-gregorian death-date
)))
656 (h-month (extract-calendar-month h-date
))
657 (h-day (extract-calendar-day h-date
))
658 (h-year (extract-calendar-year h-date
)))
659 (calendar-in-read-only-buffer cal-hebrew-yahrzeit-buffer
660 (calendar-set-mode-line
661 (format "Yahrzeit dates for %s = %s"
662 (calendar-date-string death-date
)
663 (let ((calendar-month-name-array
664 (if (hebrew-calendar-leap-year-p h-year
)
665 calendar-hebrew-month-name-array-leap-year
666 calendar-hebrew-month-name-array-common-year
)))
667 (calendar-date-string h-date nil t
))))
668 (calendar-for-loop i from start-year to end-year do
670 (calendar-date-string
671 (calendar-gregorian-from-absolute
672 (hebrew-calendar-yahrzeit
674 (extract-calendar-year
675 (calendar-hebrew-from-absolute
676 (calendar-absolute-from-gregorian (list 1 1 i
))))))) "\n")))
677 (message "Computing Yahrzeits...done")))
681 ;; To be called from list-sexp-diary-entries, where DATE is bound.
683 (defun diary-hebrew-date ()
684 "Hebrew calendar equivalent of date diary entry."
685 (format "Hebrew date (until sunset): %s" (calendar-hebrew-date-string date
)))
688 (defun diary-omer (&optional mark
)
689 "Omer count diary entry.
690 Entry applies if date is within 50 days after Passover.
692 An optional parameter MARK specifies a face or single-character string to
693 use when highlighting the day in the calendar."
695 (calendar-absolute-from-hebrew
696 (list 1 15 (+ (extract-calendar-year date
) 3760))))
697 (omer (- (calendar-absolute-from-gregorian date
) passover
))
700 (if (and (> omer
0) (< omer
50))
702 (format "Day %d%s of the omer (until sunset)"
706 (format ", that is, %d week%s%s"
708 (if (= week
1) "" "s")
711 (format " and %d day%s"
712 day
(if (= day
1) "" "s"))))))))))
716 (autoload 'diary-make-date
"diary-lib")
719 (defun diary-yahrzeit (death-month death-day death-year
&optional mark
)
720 "Yahrzeit diary entry--entry applies if date is Yahrzeit or the day before.
721 Parameters are DEATH-MONTH, DEATH-DAY, DEATH-YEAR; the diary
722 entry is assumed to be the name of the person. Although the date
723 of death is specified by the civil calendar, the proper Hebrew
724 calendar Yahrzeit is determined.
726 The order of the input parameters changes according to `calendar-date-style'
727 \(e.g. to DEATH-DAY, DEATH-MONTH, DEATH-YEAR in the European style).
729 An optional parameter MARK specifies a face or single-character string to
730 use when highlighting the day in the calendar."
731 (let* ((h-date (calendar-hebrew-from-absolute
732 (calendar-absolute-from-gregorian
733 (diary-make-date death-month death-day death-year
))))
734 (h-month (extract-calendar-month h-date
))
735 (h-day (extract-calendar-day h-date
))
736 (h-year (extract-calendar-year h-date
))
737 (d (calendar-absolute-from-gregorian date
))
738 (yr (extract-calendar-year (calendar-hebrew-from-absolute d
)))
740 (y (hebrew-calendar-yahrzeit h-date yr
)))
741 (if (and (> diff
0) (or (= y d
) (= y
(1+ d
))))
743 (format "Yahrzeit of %s%s: %d%s anniversary"
745 (if (= y d
) "" " (evening)")
747 (cond ((= (% diff
10) 1) "st")
748 ((= (% diff
10) 2) "nd")
749 ((= (% diff
10) 3) "rd")
753 (defun diary-rosh-hodesh (&optional mark
)
754 "Rosh Hodesh diary entry.
755 Entry applies if date is Rosh Hodesh, the day before, or the Saturday before.
757 An optional parameter MARK specifies a face or single-character string to
758 use when highlighting the day in the calendar."
759 (let* ((d (calendar-absolute-from-gregorian date
))
760 (h-date (calendar-hebrew-from-absolute d
))
761 (h-month (extract-calendar-month h-date
))
762 (h-day (extract-calendar-day h-date
))
763 (h-year (extract-calendar-year h-date
))
764 (leap-year (hebrew-calendar-leap-year-p h-year
))
765 (last-day (hebrew-calendar-last-day-of-month h-month h-year
))
768 calendar-hebrew-month-name-array-leap-year
769 calendar-hebrew-month-name-array-common-year
))
770 (this-month (aref h-month-names
(1- h-month
)))
771 (h-yesterday (extract-calendar-day
772 (calendar-hebrew-from-absolute (1- d
)))))
773 (if (or (= h-day
30) (and (= h-day
1) (/= h-month
7)))
780 ;; Next month must be in the same year since this
781 ;; month can't be the last month of the year since
783 (aref h-month-names h-month
))
784 (if (= h-yesterday
30)
785 (format "%s (second day)" this-month
)
787 (if (= (% d
7) 6) ; Saturday--check for Shabbat Mevarchim
789 (cond ((and (> h-day
22) (/= h-month
6) (= 29 last-day
))
790 (format "Mevarchim Rosh Hodesh %s (%s)"
793 (hebrew-calendar-last-month-of-year
796 (aref calendar-day-name-array
(- 29 h-day
))))
797 ((and (< h-day
30) (> h-day
22) (= 30 last-day
))
798 (format "Mevarchim Rosh Hodesh %s (%s-%s)"
799 (aref h-month-names h-month
)
802 (aref calendar-day-name-array
(- 29 h-day
)))
803 (aref calendar-day-name-array
804 (%
(- 30 h-day
) 7))))))
805 (if (and (= h-day
29) (/= h-month
6))
807 (format "Erev Rosh Hodesh %s"
810 (hebrew-calendar-last-month-of-year
814 (defconst hebrew-calendar-parashiot-names
815 ["Bereshith" "Noah" "Lech L'cha" "Vayera" "Hayei Sarah" "Toledoth"
816 "Vayetze" "Vayishlah" "Vayeshev" "Mikketz" "Vayiggash" "Vayhi"
817 "Shemoth" "Vaera" "Bo" "Beshallah" "Yithro" "Mishpatim"
818 "Terumah" "Tetzavveh" "Ki Tissa" "Vayakhel" "Pekudei" "Vayikra"
819 "Tzav" "Shemini" "Tazria" "Metzora" "Aharei Moth" "Kedoshim"
820 "Emor" "Behar" "Behukkotai" "Bemidbar" "Naso" "Behaalot'cha"
821 "Shelah L'cha" "Korah" "Hukkath" "Balak" "Pinhas" "Mattoth"
822 "Masei" "Devarim" "Vaethanan" "Ekev" "Reeh" "Shofetim"
823 "Ki Tetze" "Ki Tavo" "Nitzavim" "Vayelech" "Haazinu"]
824 "The names of the parashiot in the Torah.")
826 (defun hebrew-calendar-parasha-name (p)
827 "Name(s) corresponding to parasha P."
828 (if (arrayp p
) ; combined parasha
830 (aref hebrew-calendar-parashiot-names
(aref p
0))
831 (aref hebrew-calendar-parashiot-names
(aref p
1)))
832 (aref hebrew-calendar-parashiot-names p
)))
834 ;; Following 14 constants are used in diary-parasha (intern).
836 ;; The seven ordinary year types (keviot).
837 (defconst hebrew-calendar-year-Saturday-incomplete-Sunday
838 [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]
839 23 24 nil
25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
840 43 44 45 46 47 48 49 50]
841 "The structure of the parashiot.
842 Hebrew year starts on Saturday, is `incomplete' (Heshvan and Kislev each have
843 29 days), and has Passover start on Sunday.")
845 (defconst hebrew-calendar-year-Saturday-complete-Tuesday
846 [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]
847 23 24 nil
25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
848 43 44 45 46 47 48 49 [50 51]]
849 "The structure of the parashiot.
850 Hebrew year that starts on Saturday, is `complete' (Heshvan and Kislev each
851 have 30 days), and has Passover start on Tuesday.")
853 (defconst hebrew-calendar-year-Monday-incomplete-Tuesday
854 [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]
855 23 24 nil
25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
856 43 44 45 46 47 48 49 [50 51]]
857 "The structure of the parashiot.
858 Hebrew year that starts on Monday, is `incomplete' (Heshvan and Kislev each
859 have 29 days), and has Passover start on Tuesday.")
861 (defconst hebrew-calendar-year-Monday-complete-Thursday
862 [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]
863 23 24 nil
25 [26 27] [28 29] 30 [31 32] 33 (nil .
34) (34 .
35) (35 .
36)
864 (36 .
37) (37 .
38) ([38 39] .
39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
865 "The structure of the parashiot.
866 Hebrew year that starts on Monday, is `complete' (Heshvan and Kislev each have
867 30 days), and has Passover start on Thursday.")
869 (defconst hebrew-calendar-year-Tuesday-regular-Thursday
870 [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]
871 23 24 nil
25 [26 27] [28 29] 30 [31 32] 33 (nil .
34) (34 .
35) (35 .
36)
872 (36 .
37) (37 .
38) ([38 39] .
39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
873 "The structure of the parashiot.
874 Hebrew year that starts on Tuesday, is `regular' (Heshvan has 29 days and
875 Kislev has 30 days), and has Passover start on Thursday.")
877 (defconst hebrew-calendar-year-Thursday-regular-Saturday
878 [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
879 24 nil
(nil .
25) (25 .
[26 27]) ([26 27] .
[28 29]) ([28 29] .
30)
880 (30 .
31) ([31 32] .
32) 33 34 35 36 37 38 39 40 [41 42] 43 44 45 46 47 48
882 "The structure of the parashiot.
883 Hebrew year that starts on Thursday, is `regular' (Heshvan has 29 days and
884 Kislev has 30 days), and has Passover start on Saturday.")
886 (defconst hebrew-calendar-year-Thursday-complete-Sunday
887 [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
888 23 24 nil
25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
889 43 44 45 46 47 48 49 50]
890 "The structure of the parashiot.
891 Hebrew year that starts on Thursday, is `complete' (Heshvan and Kislev each
892 have 30 days), and has Passover start on Sunday.")
894 ;; The seven leap year types (keviot).
895 (defconst hebrew-calendar-year-Saturday-incomplete-Tuesday
896 [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
897 23 24 25 26 27 nil
28 29 30 31 32 33 34 35 36 37 38 39 40 [41 42]
898 43 44 45 46 47 48 49 [50 51]]
899 "The structure of the parashiot.
900 Hebrew year that starts on Saturday, is `incomplete' (Heshvan and Kislev each
901 have 29 days), and has Passover start on Tuesday.")
903 (defconst hebrew-calendar-year-Saturday-complete-Thursday
904 [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
905 23 24 25 26 27 nil
28 29 30 31 32 33 (nil .
34) (34 .
35) (35 .
36)
906 (36 .
37) (37 .
38) ([38 39] .
39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
907 "The structure of the parashiot.
908 Hebrew year that starts on Saturday, is `complete' (Heshvan and Kislev each
909 have 30 days), and has Passover start on Thursday.")
911 (defconst hebrew-calendar-year-Monday-incomplete-Thursday
912 [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
913 23 24 25 26 27 nil
28 29 30 31 32 33 (nil .
34) (34 .
35) (35 .
36)
914 (36 .
37) (37 .
38) ([38 39] .
39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
915 "The structure of the parashiot.
916 Hebrew year that starts on Monday, is `incomplete' (Heshvan and Kislev each
917 have 29 days), and has Passover start on Thursday.")
919 (defconst hebrew-calendar-year-Monday-complete-Saturday
920 [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
921 23 24 25 26 27 nil
(nil .
28) (28 .
29) (29 .
30) (30 .
31) (31 .
32)
922 (32 .
33) (33 .
34) (34 .
35) (35 .
36) (36 .
37) (37 .
38) (38 .
39)
923 (39 .
40) (40 .
41) ([41 42] .
42) 43 44 45 46 47 48 49 50]
924 "The structure of the parashiot.
925 Hebrew year that starts on Monday, is `complete' (Heshvan and Kislev each have
926 30 days), and has Passover start on Saturday.")
928 (defconst hebrew-calendar-year-Tuesday-regular-Saturday
929 [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
930 23 24 25 26 27 nil
(nil .
28) (28 .
29) (29 .
30) (30 .
31) (31 .
32)
931 (32 .
33) (33 .
34) (34 .
35) (35 .
36) (36 .
37) (37 .
38) (38 .
39)
932 (39 .
40) (40 .
41) ([41 42] .
42) 43 44 45 46 47 48 49 50]
933 "The structure of the parashiot.
934 Hebrew year that starts on Tuesday, is `regular' (Heshvan has 29 days and
935 Kislev has 30 days), and has Passover start on Saturday.")
937 (defconst hebrew-calendar-year-Thursday-incomplete-Sunday
938 [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
939 23 24 25 26 27 28 nil
29 30 31 32 33 34 35 36 37 38 39 40 41 42
940 43 44 45 46 47 48 49 50]
941 "The structure of the parashiot.
942 Hebrew year that starts on Thursday, is `incomplete' (Heshvan and Kislev both
943 have 29 days), and has Passover start on Sunday.")
945 (defconst hebrew-calendar-year-Thursday-complete-Tuesday
946 [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
947 23 24 25 26 27 28 nil
29 30 31 32 33 34 35 36 37 38 39 40 41 42
948 43 44 45 46 47 48 49 [50 51]]
949 "The structure of the parashiot.
950 Hebrew year that starts on Thursday, is `complete' (Heshvan and Kislev both
951 have 30 days), and has Passover start on Tuesday.")
954 (defun diary-parasha (&optional mark
)
955 "Parasha diary entry--entry applies if date is a Saturday.
956 An optional parameter MARK specifies a face or single-character string to
957 use when highlighting the day in the calendar."
958 (let ((d (calendar-absolute-from-gregorian date
)))
959 (if (= (% d
7) 6) ; Saturday
960 (let* ((h-year (extract-calendar-year
961 (calendar-hebrew-from-absolute d
)))
963 (calendar-absolute-from-hebrew (list 7 1 h-year
)))
965 (calendar-absolute-from-hebrew (list 1 15 h-year
)))
967 (aref calendar-day-name-array
(% rosh-hashanah
7)))
969 (aref calendar-day-name-array
(% passover
7)))
970 (long-h (hebrew-calendar-long-heshvan-p h-year
))
971 (short-k (hebrew-calendar-short-kislev-p h-year
))
972 (type (cond ((and long-h
(not short-k
)) "complete")
973 ((and (not long-h
) short-k
) "incomplete")
977 (intern (format "hebrew-calendar-year-%s-%s-%s" ; keviah
978 rosh-hashanah-day type passover-day
))))
979 (first-saturday ; of Hebrew year
980 (calendar-dayname-on-or-before 6 (+ 6 rosh-hashanah
)))
981 (saturday ; which Saturday of the Hebrew year
982 (/ (- d first-saturday
) 7))
983 (parasha (aref year-format saturday
)))
988 (if (listp parasha
) ; Israel differs from diaspora
990 (format "%s (diaspora), %s (Israel)"
991 (hebrew-calendar-parasha-name
993 (hebrew-calendar-parasha-name
995 (format "%s (Israel)"
996 (hebrew-calendar-parasha-name
998 (hebrew-calendar-parasha-name parasha
)))))))))
1000 (provide 'cal-hebrew
)
1002 ;; arch-tag: aaab6718-7712-42ac-a32d-28fe1f944f3c
1003 ;;; cal-hebrew.el ends here