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 (&optional all
)
327 "List of dates related to Rosh Hashanah, as visible in calendar window.
328 Shows only the major holidays, unless `calendar-hebrew-all-holidays-flag'
330 (when (memq displayed-month
'(8 9 10 11))
331 (let ((abs-r-h (calendar-absolute-from-hebrew
332 (list 7 1 (+ displayed-year
3761)))))
333 (holiday-filter-visible-calendar
336 (list (calendar-gregorian-from-absolute abs-r-h
)
337 (format "Rosh HaShanah %d" (+ 3761 displayed-year
)))
338 (list (calendar-gregorian-from-absolute (+ abs-r-h
9))
340 (list (calendar-gregorian-from-absolute (+ abs-r-h
14))
342 (list (calendar-gregorian-from-absolute (+ abs-r-h
21))
344 (list (calendar-gregorian-from-absolute (+ abs-r-h
22))
346 (when (or all calendar-hebrew-all-holidays-flag
)
348 (list (calendar-gregorian-from-absolute
349 (calendar-dayname-on-or-before 6 (- abs-r-h
4)))
351 (list (calendar-gregorian-from-absolute (1- abs-r-h
))
352 "Erev Rosh HaShanah")
353 (list (calendar-gregorian-from-absolute (1+ abs-r-h
))
354 "Rosh HaShanah (second day)")
355 (list (calendar-gregorian-from-absolute
356 (if (= (% abs-r-h
7) 4) (+ abs-r-h
3) (+ abs-r-h
2)))
358 (list (calendar-gregorian-from-absolute
359 (calendar-dayname-on-or-before 6 (+ 7 abs-r-h
)))
361 (list (calendar-gregorian-from-absolute (+ abs-r-h
8))
363 (list (calendar-gregorian-from-absolute (+ abs-r-h
13))
365 (list (calendar-gregorian-from-absolute (+ abs-r-h
15))
366 "Sukkot (second day)")
367 (list (calendar-gregorian-from-absolute (+ abs-r-h
16))
368 "Hol Hamoed Sukkot (first day)")
369 (list (calendar-gregorian-from-absolute (+ abs-r-h
17))
370 "Hol Hamoed Sukkot (second day)")
371 (list (calendar-gregorian-from-absolute (+ abs-r-h
18))
372 "Hol Hamoed Sukkot (third day)")
373 (list (calendar-gregorian-from-absolute (+ abs-r-h
19))
374 "Hol Hamoed Sukkot (fourth day)")
375 (list (calendar-gregorian-from-absolute (+ abs-r-h
20))
376 "Hoshanah Rabbah"))))))))
378 ;;;###holiday-autoload
379 (defun holiday-hanukkah (&optional all
)
380 "List of dates related to Hanukkah, as visible in calendar window.
381 Shows only Hanukkah, unless `calendar-hebrew-all-holidays-flag' or ALL
383 ;; This test is only to speed things up a bit, it works fine without it.
384 (when (memq displayed-month
'(10 11 12 1 2))
385 (let* ((m displayed-month
)
388 (increment-calendar-month m y
1)
389 (extract-calendar-year
390 (calendar-hebrew-from-absolute
391 (calendar-absolute-from-gregorian
392 (list m
(calendar-last-day-of-month m y
) y
))))))
393 (abs-h (calendar-absolute-from-hebrew (list 9 25 h-y
)))
394 (ord ["first" "second" "third" "fourth" "fifth" "sixth"
397 (holiday-filter-visible-calendar
398 (if (or all calendar-hebrew-all-holidays-flag
)
401 (list (calendar-gregorian-from-absolute (1- abs-h
))
403 (dotimes (i 8 (nreverse han
))
405 (calendar-gregorian-from-absolute (+ abs-h i
))
406 (format "Hanukkah (%s day)" (aref ord i
)))
408 (list (list (calendar-gregorian-from-absolute abs-h
) "Hanukkah")))))))
410 ;;;###holiday-autoload
411 (defun holiday-passover-etc (&optional all
)
412 "List of dates related to Passover, as visible in calendar window.
413 Shows only the major holidays, unless `calendar-hebrew-all-holidays-flag'
415 (when (< displayed-month
8)
416 (let ((abs-p (calendar-absolute-from-hebrew
417 (list 1 15 (+ displayed-year
3760)))))
418 (holiday-filter-visible-calendar
419 ;; The first two are out of order when the others are added.
422 (list (calendar-gregorian-from-absolute abs-p
) "Passover")
423 (list (calendar-gregorian-from-absolute (+ abs-p
50))
425 (when (or all calendar-hebrew-all-holidays-flag
)
427 (list (calendar-gregorian-from-absolute
428 (calendar-dayname-on-or-before 6 (- abs-p
43)))
430 (list (calendar-gregorian-from-absolute
431 (calendar-dayname-on-or-before 6 (- abs-p
30)))
433 (list (calendar-gregorian-from-absolute
434 (if (= (% abs-p
7) 2) (- abs-p
33) (- abs-p
31)))
436 (list (calendar-gregorian-from-absolute (- abs-p
31))
438 (list (calendar-gregorian-from-absolute (- abs-p
30))
440 (list (calendar-gregorian-from-absolute
441 (if (zerop (% abs-p
7)) (- abs-p
28) (- abs-p
29)))
443 (list (calendar-gregorian-from-absolute
444 (- (calendar-dayname-on-or-before 6 (- abs-p
14)) 7))
446 (list (calendar-gregorian-from-absolute
447 (calendar-dayname-on-or-before 6 (- abs-p
14)))
449 (list (calendar-gregorian-from-absolute
450 (calendar-dayname-on-or-before 6 (1- abs-p
)))
452 (list (calendar-gregorian-from-absolute (1- abs-p
))
454 (list (calendar-gregorian-from-absolute (1+ abs-p
))
455 "Passover (second day)")
456 (list (calendar-gregorian-from-absolute (+ abs-p
2))
457 "Hol Hamoed Passover (first day)")
458 (list (calendar-gregorian-from-absolute (+ abs-p
3))
459 "Hol Hamoed Passover (second day)")
460 (list (calendar-gregorian-from-absolute (+ abs-p
4))
461 "Hol Hamoed Passover (third day)")
462 (list (calendar-gregorian-from-absolute (+ abs-p
5))
463 "Hol Hamoed Passover (fourth day)")
464 (list (calendar-gregorian-from-absolute (+ abs-p
6))
465 "Passover (seventh day)")
466 (list (calendar-gregorian-from-absolute (+ abs-p
7))
467 "Passover (eighth day)")
468 (list (calendar-gregorian-from-absolute
469 (if (zerop (%
(+ abs-p
12) 7))
473 (list (calendar-gregorian-from-absolute
474 (if (zerop (% abs-p
7))
476 (if (= (% abs-p
7) 6)
480 (list (calendar-gregorian-from-absolute (+ abs-p
33))
482 (list (calendar-gregorian-from-absolute (+ abs-p
43))
484 (list (calendar-gregorian-from-absolute (+ abs-p
49))
486 (list (calendar-gregorian-from-absolute (+ abs-p
51))
487 "Shavuot (second day)"))))))))
489 ;;;###holiday-autoload
490 (defun holiday-tisha-b-av-etc ()
491 "List of dates around Tisha B'Av, as visible in calendar window."
492 (when (memq displayed-month
'(5 6 7 8 9))
493 (let ((abs-t-a (calendar-absolute-from-hebrew
494 (list 5 9 (+ displayed-year
3760)))))
495 (holiday-filter-visible-calendar
497 (list (calendar-gregorian-from-absolute
498 (if (= (% abs-t-a
7) 6) (- abs-t-a
20) (- abs-t-a
21)))
500 (list (calendar-gregorian-from-absolute
501 (calendar-dayname-on-or-before 6 abs-t-a
))
503 (list (calendar-gregorian-from-absolute
504 (if (= (% abs-t-a
7) 6) (1+ abs-t-a
) abs-t-a
))
506 (list (calendar-gregorian-from-absolute
507 (calendar-dayname-on-or-before 6 (+ abs-t-a
7)))
508 "Shabbat Nahamu"))))))
510 (autoload 'holiday-julian
"cal-julian")
512 ;;;###holiday-autoload
513 (defun holiday-hebrew-misc ()
514 "Miscellaneous Hebrew holidays, if visible in calendar window.
515 Includes: Tal Umatar, Tzom Teveth, Tu B'Shevat, Shabbat Shirah, and
517 (let ((m displayed-month
)
524 (increment-calendar-month m y -
1)
525 (setq year
(extract-calendar-year
526 (calendar-julian-from-absolute
527 (calendar-absolute-from-gregorian (list m
1 y
)))))
528 (if (zerop (%
(1+ year
) 4))
530 21)) "\"Tal Umatar\" (evening)")
534 (setq h-year
(extract-calendar-year
535 (calendar-hebrew-from-absolute
536 (calendar-absolute-from-gregorian
537 (list displayed-month
28 displayed-year
)))))
538 (if (= 6 (%
(calendar-absolute-from-hebrew (list 10 10 h-year
))
542 (holiday-hebrew 11 15 "Tu B'Shevat")
546 (setq m displayed-month
549 (increment-calendar-month m y
1)
550 (extract-calendar-year
551 (calendar-hebrew-from-absolute
552 (calendar-absolute-from-gregorian
553 (list m
(calendar-last-day-of-month m y
) y
)))))
555 (calendar-hebrew-from-absolute
557 (%
(calendar-absolute-from-hebrew
560 (calendar-dayname-on-or-before
561 6 (calendar-absolute-from-hebrew
562 (list 11 17 h-year
)))
563 (calendar-dayname-on-or-before
564 6 (calendar-absolute-from-hebrew
565 (list 11 16 h-year
))))))
566 (extract-calendar-day s-s
))
569 (setq m displayed-month
572 (increment-calendar-month m y -
1)
573 (extract-calendar-year
574 (calendar-julian-from-absolute
575 (calendar-absolute-from-gregorian (list m
1 y
))))))
577 (holiday-julian 3 26 "Kiddush HaHamah")))))
580 (autoload 'diary-list-entries-1
"diary-lib")
583 (defun list-hebrew-diary-entries ()
584 "Add any Hebrew date entries from the diary file to `diary-entries-list'.
585 Hebrew date diary entries must be prefaced by `hebrew-diary-entry-symbol'
586 \(normally an `H'). The same diary date forms govern the style
587 of the Hebrew calendar entries, except that the Hebrew month
588 names cannot be abbreviated. The Hebrew months are numbered
589 from 1 to 13 with Nisan being 1, 12 being Adar I and 13 being
590 Adar II; you must use `Adar I' if you want Adar of a common
591 Hebrew year. If a Hebrew date diary entry begins with
592 `diary-nonmarking-symbol', the entry will appear in the diary
593 listing, but will not be marked in the calendar. This function
594 is provided for use with `nongregorian-diary-listing-hook'."
595 (diary-list-entries-1 calendar-hebrew-month-name-array-leap-year
596 hebrew-diary-entry-symbol
597 'calendar-hebrew-from-absolute
))
599 (autoload 'calendar-mark-complex
"diary-lib")
602 (defun mark-hebrew-calendar-date-pattern (month day year
&optional color
)
603 "Mark dates in calendar window that conform to Hebrew date MONTH/DAY/YEAR.
604 A value of 0 in any position is a wildcard. Optional argument COLOR is
605 passed to `mark-visible-calendar-date' as MARK."
606 ;; FIXME not the same as the Bahai and Islamic cases, so can't use
609 (set-buffer calendar-buffer
)
610 (if (and (not (zerop month
)) (not (zerop day
)))
611 (if (not (zerop year
))
612 ;; Fully specified Hebrew date.
613 (let ((date (calendar-gregorian-from-absolute
614 (calendar-absolute-from-hebrew
615 (list month day year
)))))
616 (if (calendar-date-is-visible-p date
)
617 (mark-visible-calendar-date date color
)))
618 ;; Month and day in any year.
619 (let ((gdate (calendar-hebrew-date-is-visible-p month day
)))
620 (if gdate
(mark-visible-calendar-date gdate color
))))
621 (calendar-mark-complex month day year
622 'calendar-hebrew-from-absolute color
))))
624 (autoload 'diary-mark-entries-1
"diary-lib")
627 (defun mark-hebrew-diary-entries ()
628 "Mark days in the calendar window that have Hebrew date diary entries.
629 Marks each entry in `diary-file' (or included files) visible in the calendar
630 window. See `list-hebrew-diary-entries' for more information."
631 (diary-mark-entries-1 'mark-hebrew-calendar-date-pattern
632 calendar-hebrew-month-name-array-leap-year
633 hebrew-diary-entry-symbol
634 'calendar-hebrew-from-absolute
))
637 (autoload 'diary-insert-entry-1
"diary-lib")
640 (defun insert-hebrew-diary-entry (arg)
641 "Insert a diary entry.
642 For the Hebrew date corresponding to the date indicated by point.
643 Prefix argument ARG makes the entry nonmarking."
645 (diary-insert-entry-1 nil arg calendar-hebrew-month-name-array-leap-year
646 hebrew-diary-entry-symbol
647 'calendar-hebrew-from-absolute
))
650 (defun insert-monthly-hebrew-diary-entry (arg)
651 "Insert a monthly diary entry.
652 For the day of the Hebrew month corresponding to the date indicated by point.
653 Prefix argument ARG makes the entry nonmarking."
655 (diary-insert-entry-1 'monthly arg calendar-hebrew-month-name-array-leap-year
656 hebrew-diary-entry-symbol
657 'calendar-hebrew-from-absolute
))
660 (defun insert-yearly-hebrew-diary-entry (arg)
661 "Insert an annual diary entry.
662 For the day of the Hebrew year corresponding to the date indicated by point.
663 Prefix argument ARG makes the entry nonmarking."
665 (diary-insert-entry-1 'yearly arg calendar-hebrew-month-name-array-leap-year
666 hebrew-diary-entry-symbol
667 'calendar-hebrew-from-absolute
))
670 (defun list-yahrzeit-dates (death-date start-year end-year
)
671 "List Yahrzeit dates for *Gregorian* DEATH-DATE from START-YEAR to END-YEAR.
672 When called interactively from the calendar window, the date of death is taken
673 from the cursor position."
676 (if (equal (current-buffer) (get-buffer calendar-buffer
))
677 (calendar-cursor-to-date)
678 (let* ((today (calendar-current-date))
680 "Year of death (>0): "
682 (int-to-string (extract-calendar-year today
))))
683 (month-array calendar-month-name-array
)
684 (completion-ignore-case t
)
685 (month (cdr (assoc-string
687 "Month of death (name): "
688 (mapcar 'list
(append month-array nil
))
690 (calendar-make-alist month-array
1) t
)))
691 (last (calendar-last-day-of-month month year
))
693 (format "Day of death (1-%d): " last
)
694 (lambda (x) (and (< 0 x
) (<= x last
))))))
695 (list month day year
))))
696 (death-year (extract-calendar-year death-date
))
697 (start-year (calendar-read
698 (format "Starting year of Yahrzeit table (>%d): "
700 (lambda (x) (> x death-year
))
701 (int-to-string (1+ death-year
))))
702 (end-year (calendar-read
703 (format "Ending year of Yahrzeit table (>=%d): "
705 (lambda (x) (>= x start-year
)))))
706 (list death-date start-year end-year
)))
707 (message "Computing Yahrzeits...")
708 (let* ((h-date (calendar-hebrew-from-absolute
709 (calendar-absolute-from-gregorian death-date
)))
710 (h-month (extract-calendar-month h-date
))
711 (h-day (extract-calendar-day h-date
))
712 (h-year (extract-calendar-year h-date
))
714 (calendar-in-read-only-buffer cal-hebrew-yahrzeit-buffer
715 (calendar-set-mode-line
716 (format "Yahrzeit dates for %s = %s"
717 (calendar-date-string death-date
)
718 (let ((calendar-month-name-array
719 (if (hebrew-calendar-leap-year-p h-year
)
720 calendar-hebrew-month-name-array-leap-year
721 calendar-hebrew-month-name-array-common-year
)))
722 (calendar-date-string h-date nil t
))))
723 (while (<= (setq i
(1+ i
)) end-year
)
725 (calendar-date-string
726 (calendar-gregorian-from-absolute
727 (hebrew-calendar-yahrzeit
729 (extract-calendar-year
730 (calendar-hebrew-from-absolute
731 (calendar-absolute-from-gregorian (list 1 1 i
))))))) "\n"))))
732 (message "Computing Yahrzeits...done"))
736 ;; To be called from list-sexp-diary-entries, where DATE is bound.
738 (defun diary-hebrew-date ()
739 "Hebrew calendar equivalent of date diary entry."
740 (format "Hebrew date (until sunset): %s" (calendar-hebrew-date-string date
)))
743 (defun diary-omer (&optional mark
)
744 "Omer count diary entry.
745 Entry applies if date is within 50 days after Passover.
747 An optional parameter MARK specifies a face or single-character string to
748 use when highlighting the day in the calendar."
750 (calendar-absolute-from-hebrew
751 (list 1 15 (+ (extract-calendar-year date
) 3760))))
752 (omer (- (calendar-absolute-from-gregorian date
) passover
))
755 (if (and (> omer
0) (< omer
50))
757 (format "Day %d%s of the omer (until sunset)"
761 (format ", that is, %d week%s%s"
763 (if (= week
1) "" "s")
766 (format " and %d day%s"
767 day
(if (= day
1) "" "s"))))))))))
771 (autoload 'diary-make-date
"diary-lib")
774 (defun diary-yahrzeit (death-month death-day death-year
&optional mark
)
775 "Yahrzeit diary entry--entry applies if date is Yahrzeit or the day before.
776 Parameters are DEATH-MONTH, DEATH-DAY, DEATH-YEAR; the diary
777 entry is assumed to be the name of the person. Although the date
778 of death is specified by the civil calendar, the proper Hebrew
779 calendar Yahrzeit is determined.
781 The order of the input parameters changes according to `calendar-date-style'
782 \(e.g. to DEATH-DAY, DEATH-MONTH, DEATH-YEAR in the European style).
784 An optional parameter MARK specifies a face or single-character string to
785 use when highlighting the day in the calendar."
786 (let* ((h-date (calendar-hebrew-from-absolute
787 (calendar-absolute-from-gregorian
788 (diary-make-date death-month death-day death-year
))))
789 (h-month (extract-calendar-month h-date
))
790 (h-day (extract-calendar-day h-date
))
791 (h-year (extract-calendar-year h-date
))
792 (d (calendar-absolute-from-gregorian date
))
793 (yr (extract-calendar-year (calendar-hebrew-from-absolute d
)))
795 (y (hebrew-calendar-yahrzeit h-date yr
)))
796 (if (and (> diff
0) (or (= y d
) (= y
(1+ d
))))
798 (format "Yahrzeit of %s%s: %d%s anniversary"
800 (if (= y d
) "" " (evening)")
802 (cond ((= (% diff
10) 1) "st")
803 ((= (% diff
10) 2) "nd")
804 ((= (% diff
10) 3) "rd")
808 (defun diary-rosh-hodesh (&optional mark
)
809 "Rosh Hodesh diary entry.
810 Entry applies if date is Rosh Hodesh, the day before, or the Saturday before.
812 An optional parameter MARK specifies a face or single-character string to
813 use when highlighting the day in the calendar."
814 (let* ((d (calendar-absolute-from-gregorian date
))
815 (h-date (calendar-hebrew-from-absolute d
))
816 (h-month (extract-calendar-month h-date
))
817 (h-day (extract-calendar-day h-date
))
818 (h-year (extract-calendar-year h-date
))
819 (leap-year (hebrew-calendar-leap-year-p h-year
))
820 (last-day (hebrew-calendar-last-day-of-month h-month h-year
))
823 calendar-hebrew-month-name-array-leap-year
824 calendar-hebrew-month-name-array-common-year
))
825 (this-month (aref h-month-names
(1- h-month
)))
826 (h-yesterday (extract-calendar-day
827 (calendar-hebrew-from-absolute (1- d
)))))
828 (if (or (= h-day
30) (and (= h-day
1) (/= h-month
7)))
835 ;; Next month must be in the same year since this
836 ;; month can't be the last month of the year since
838 (aref h-month-names h-month
))
839 (if (= h-yesterday
30)
840 (format "%s (second day)" this-month
)
842 (if (= (% d
7) 6) ; Saturday--check for Shabbat Mevarchim
844 (cond ((and (> h-day
22) (/= h-month
6) (= 29 last-day
))
845 (format "Mevarchim Rosh Hodesh %s (%s)"
848 (hebrew-calendar-last-month-of-year
851 (aref calendar-day-name-array
(- 29 h-day
))))
852 ((and (< h-day
30) (> h-day
22) (= 30 last-day
))
853 (format "Mevarchim Rosh Hodesh %s (%s-%s)"
854 (aref h-month-names h-month
)
857 (aref calendar-day-name-array
(- 29 h-day
)))
858 (aref calendar-day-name-array
859 (%
(- 30 h-day
) 7))))))
860 (if (and (= h-day
29) (/= h-month
6))
862 (format "Erev Rosh Hodesh %s"
865 (hebrew-calendar-last-month-of-year
869 (defconst hebrew-calendar-parashiot-names
870 ["Bereshith" "Noah" "Lech L'cha" "Vayera" "Hayei Sarah" "Toledoth"
871 "Vayetze" "Vayishlah" "Vayeshev" "Mikketz" "Vayiggash" "Vayhi"
872 "Shemoth" "Vaera" "Bo" "Beshallah" "Yithro" "Mishpatim"
873 "Terumah" "Tetzavveh" "Ki Tissa" "Vayakhel" "Pekudei" "Vayikra"
874 "Tzav" "Shemini" "Tazria" "Metzora" "Aharei Moth" "Kedoshim"
875 "Emor" "Behar" "Behukkotai" "Bemidbar" "Naso" "Behaalot'cha"
876 "Shelah L'cha" "Korah" "Hukkath" "Balak" "Pinhas" "Mattoth"
877 "Masei" "Devarim" "Vaethanan" "Ekev" "Reeh" "Shofetim"
878 "Ki Tetze" "Ki Tavo" "Nitzavim" "Vayelech" "Haazinu"]
879 "The names of the parashiot in the Torah.")
881 (defun hebrew-calendar-parasha-name (p)
882 "Name(s) corresponding to parasha P."
883 (if (arrayp p
) ; combined parasha
885 (aref hebrew-calendar-parashiot-names
(aref p
0))
886 (aref hebrew-calendar-parashiot-names
(aref p
1)))
887 (aref hebrew-calendar-parashiot-names p
)))
889 ;; Following 14 constants are used in diary-parasha (intern).
891 ;; The seven ordinary year types (keviot).
892 (defconst hebrew-calendar-year-Saturday-incomplete-Sunday
893 [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]
894 23 24 nil
25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
895 43 44 45 46 47 48 49 50]
896 "The structure of the parashiot.
897 Hebrew year starts on Saturday, is `incomplete' (Heshvan and Kislev each have
898 29 days), and has Passover start on Sunday.")
900 (defconst hebrew-calendar-year-Saturday-complete-Tuesday
901 [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]
902 23 24 nil
25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
903 43 44 45 46 47 48 49 [50 51]]
904 "The structure of the parashiot.
905 Hebrew year that starts on Saturday, is `complete' (Heshvan and Kislev each
906 have 30 days), and has Passover start on Tuesday.")
908 (defconst hebrew-calendar-year-Monday-incomplete-Tuesday
909 [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]
910 23 24 nil
25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
911 43 44 45 46 47 48 49 [50 51]]
912 "The structure of the parashiot.
913 Hebrew year that starts on Monday, is `incomplete' (Heshvan and Kislev each
914 have 29 days), and has Passover start on Tuesday.")
916 (defconst hebrew-calendar-year-Monday-complete-Thursday
917 [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]
918 23 24 nil
25 [26 27] [28 29] 30 [31 32] 33 (nil .
34) (34 .
35) (35 .
36)
919 (36 .
37) (37 .
38) ([38 39] .
39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
920 "The structure of the parashiot.
921 Hebrew year that starts on Monday, is `complete' (Heshvan and Kislev each have
922 30 days), and has Passover start on Thursday.")
924 (defconst hebrew-calendar-year-Tuesday-regular-Thursday
925 [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]
926 23 24 nil
25 [26 27] [28 29] 30 [31 32] 33 (nil .
34) (34 .
35) (35 .
36)
927 (36 .
37) (37 .
38) ([38 39] .
39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
928 "The structure of the parashiot.
929 Hebrew year that starts on Tuesday, is `regular' (Heshvan has 29 days and
930 Kislev has 30 days), and has Passover start on Thursday.")
932 (defconst hebrew-calendar-year-Thursday-regular-Saturday
933 [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
934 24 nil
(nil .
25) (25 .
[26 27]) ([26 27] .
[28 29]) ([28 29] .
30)
935 (30 .
31) ([31 32] .
32) 33 34 35 36 37 38 39 40 [41 42] 43 44 45 46 47 48
937 "The structure of the parashiot.
938 Hebrew year that starts on Thursday, is `regular' (Heshvan has 29 days and
939 Kislev has 30 days), and has Passover start on Saturday.")
941 (defconst hebrew-calendar-year-Thursday-complete-Sunday
942 [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
943 23 24 nil
25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
944 43 44 45 46 47 48 49 50]
945 "The structure of the parashiot.
946 Hebrew year that starts on Thursday, is `complete' (Heshvan and Kislev each
947 have 30 days), and has Passover start on Sunday.")
949 ;; The seven leap year types (keviot).
950 (defconst hebrew-calendar-year-Saturday-incomplete-Tuesday
951 [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
952 23 24 25 26 27 nil
28 29 30 31 32 33 34 35 36 37 38 39 40 [41 42]
953 43 44 45 46 47 48 49 [50 51]]
954 "The structure of the parashiot.
955 Hebrew year that starts on Saturday, is `incomplete' (Heshvan and Kislev each
956 have 29 days), and has Passover start on Tuesday.")
958 (defconst hebrew-calendar-year-Saturday-complete-Thursday
959 [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
960 23 24 25 26 27 nil
28 29 30 31 32 33 (nil .
34) (34 .
35) (35 .
36)
961 (36 .
37) (37 .
38) ([38 39] .
39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
962 "The structure of the parashiot.
963 Hebrew year that starts on Saturday, is `complete' (Heshvan and Kislev each
964 have 30 days), and has Passover start on Thursday.")
966 (defconst hebrew-calendar-year-Monday-incomplete-Thursday
967 [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
968 23 24 25 26 27 nil
28 29 30 31 32 33 (nil .
34) (34 .
35) (35 .
36)
969 (36 .
37) (37 .
38) ([38 39] .
39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
970 "The structure of the parashiot.
971 Hebrew year that starts on Monday, is `incomplete' (Heshvan and Kislev each
972 have 29 days), and has Passover start on Thursday.")
974 (defconst hebrew-calendar-year-Monday-complete-Saturday
975 [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
976 23 24 25 26 27 nil
(nil .
28) (28 .
29) (29 .
30) (30 .
31) (31 .
32)
977 (32 .
33) (33 .
34) (34 .
35) (35 .
36) (36 .
37) (37 .
38) (38 .
39)
978 (39 .
40) (40 .
41) ([41 42] .
42) 43 44 45 46 47 48 49 50]
979 "The structure of the parashiot.
980 Hebrew year that starts on Monday, is `complete' (Heshvan and Kislev each have
981 30 days), and has Passover start on Saturday.")
983 (defconst hebrew-calendar-year-Tuesday-regular-Saturday
984 [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
985 23 24 25 26 27 nil
(nil .
28) (28 .
29) (29 .
30) (30 .
31) (31 .
32)
986 (32 .
33) (33 .
34) (34 .
35) (35 .
36) (36 .
37) (37 .
38) (38 .
39)
987 (39 .
40) (40 .
41) ([41 42] .
42) 43 44 45 46 47 48 49 50]
988 "The structure of the parashiot.
989 Hebrew year that starts on Tuesday, is `regular' (Heshvan has 29 days and
990 Kislev has 30 days), and has Passover start on Saturday.")
992 (defconst hebrew-calendar-year-Thursday-incomplete-Sunday
993 [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
994 23 24 25 26 27 28 nil
29 30 31 32 33 34 35 36 37 38 39 40 41 42
995 43 44 45 46 47 48 49 50]
996 "The structure of the parashiot.
997 Hebrew year that starts on Thursday, is `incomplete' (Heshvan and Kislev both
998 have 29 days), and has Passover start on Sunday.")
1000 (defconst hebrew-calendar-year-Thursday-complete-Tuesday
1001 [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
1002 23 24 25 26 27 28 nil
29 30 31 32 33 34 35 36 37 38 39 40 41 42
1003 43 44 45 46 47 48 49 [50 51]]
1004 "The structure of the parashiot.
1005 Hebrew year that starts on Thursday, is `complete' (Heshvan and Kislev both
1006 have 30 days), and has Passover start on Tuesday.")
1008 ;;;###diary-autoload
1009 (defun diary-parasha (&optional mark
)
1010 "Parasha diary entry--entry applies if date is a Saturday.
1011 An optional parameter MARK specifies a face or single-character string to
1012 use when highlighting the day in the calendar."
1013 (let ((d (calendar-absolute-from-gregorian date
)))
1014 (if (= (% d
7) 6) ; Saturday
1015 (let* ((h-year (extract-calendar-year
1016 (calendar-hebrew-from-absolute d
)))
1018 (calendar-absolute-from-hebrew (list 7 1 h-year
)))
1020 (calendar-absolute-from-hebrew (list 1 15 h-year
)))
1022 (aref calendar-day-name-array
(% rosh-hashanah
7)))
1024 (aref calendar-day-name-array
(% passover
7)))
1025 (long-h (hebrew-calendar-long-heshvan-p h-year
))
1026 (short-k (hebrew-calendar-short-kislev-p h-year
))
1027 (type (cond ((and long-h
(not short-k
)) "complete")
1028 ((and (not long-h
) short-k
) "incomplete")
1032 (intern (format "hebrew-calendar-year-%s-%s-%s" ; keviah
1033 rosh-hashanah-day type passover-day
))))
1034 (first-saturday ; of Hebrew year
1035 (calendar-dayname-on-or-before 6 (+ 6 rosh-hashanah
)))
1036 (saturday ; which Saturday of the Hebrew year
1037 (/ (- d first-saturday
) 7))
1038 (parasha (aref year-format saturday
)))
1043 (if (listp parasha
) ; Israel differs from diaspora
1045 (format "%s (diaspora), %s (Israel)"
1046 (hebrew-calendar-parasha-name
1048 (hebrew-calendar-parasha-name
1050 (format "%s (Israel)"
1051 (hebrew-calendar-parasha-name
1053 (hebrew-calendar-parasha-name parasha
)))))))))
1055 (provide 'cal-hebrew
)
1057 ;; arch-tag: aaab6718-7712-42ac-a32d-28fe1f944f3c
1058 ;;; cal-hebrew.el ends here