cal-hebrew.el 54 KB

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