Commit | Line | Data |
---|---|---|
e708e9d9 | 1 | ;;; cal-bahai.el --- calendar functions for the Bahá'í calendar. |
811a8484 | 2 | |
8b72699e | 3 | ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
a20b3848 | 4 | ;; Free Software Foundation, Inc. |
811a8484 JW |
5 | |
6 | ;; Author: John Wiegley <johnw@gnu.org> | |
7 | ;; Keywords: calendar | |
305c237c | 8 | ;; Human-Keywords: Bahá'í calendar, Bahá'í, Baha'i, Bahai, calendar, diary |
811a8484 JW |
9 | |
10 | ;; This file is part of GNU Emacs. | |
11 | ||
12 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 | ;; it under the terms of the GNU General Public License as published by | |
075969b4 | 14 | ;; the Free Software Foundation; either version 3, or (at your option) |
811a8484 JW |
15 | ;; any later version. |
16 | ||
17 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;; GNU General Public License for more details. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
23 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
3a35cf56 LK |
24 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 | ;; Boston, MA 02110-1301, USA. | |
811a8484 JW |
26 | |
27 | ;;; Commentary: | |
28 | ||
29 | ;; This collection of functions implements the features of calendar.el | |
305c237c | 30 | ;; and diary.el that deal with the Bahá'í calendar. |
811a8484 | 31 | |
305c237c | 32 | ;; The Bahá'í (http://www.bahai.org) calendar system is based on a |
811a8484 | 33 | ;; solar cycle of 19 months with 19 days each. The four remaining |
305c237c | 34 | ;; "intercalary" days are called the Ayyám-i-Há (days of Há), and are |
811a8484 JW |
35 | ;; placed between the 18th and 19th months. They are meant as a time |
36 | ;; of festivals preceding the 19th month, which is the month of | |
305c237c | 37 | ;; fasting. In Gregorian leap years, there are 5 of these days (Há |
811a8484 JW |
38 | ;; has the numerical value of 5 in the arabic abjad, or |
39 | ;; letter-to-number, reckoning). | |
40 | ||
41 | ;; Each month is named after an attribute of God, as are the 19 days | |
42 | ;; -- which have the same names as the months. There is also a name | |
43 | ;; for each year in every 19 year cycle. These cycles are called | |
305c237c | 44 | ;; Váhids. A cycle of 19 Váhids (361 years) is called a Kullu-Shay, |
811a8484 JW |
45 | ;; which means "all things". |
46 | ||
305c237c | 47 | ;; The calendar was named the "Badí` calendar" by its author, the Báb. |
811a8484 JW |
48 | ;; It uses a week of seven days, corresponding to the Gregorian week, |
49 | ;; each of which has its own name, again patterned after the | |
50 | ;; attributes of God. | |
51 | ||
305c237c | 52 | ;; Note: The days of Ayyám-i-Há are encoded as zero and negative |
811a8484 | 53 | ;; offsets from the first day of the final month. So, (19 -3 157) is |
305c237c | 54 | ;; the first day of Ayyám-i-Há, in the year 157 BE. |
811a8484 JW |
55 | |
56 | ;;; Code: | |
57 | ||
58 | (require 'cal-julian) | |
59 | ||
e4e1cf95 | 60 | (defconst calendar-bahai-month-name-array |
305c237c JW |
61 | ["Bahá" "Jalál" "Jamál" "`Azamat" "Núr" "Rahmat" "Kalimát" "Kamál" |
62 | "Asmá" "`Izzat" "Mashiyyat" "`Ilm" "Qudrat" "Qawl" "Masá'il" | |
63 | "Sharaf" "Sultán" "Mulk" "`Alá"]) | |
811a8484 | 64 | |
e4e1cf95 | 65 | (defconst calendar-bahai-epoch (calendar-absolute-from-gregorian '(3 21 1844)) |
305c237c | 66 | "Absolute date of start of Bahá'í calendar = March 19, 622 A.D. (Julian).") |
811a8484 | 67 | |
e4e1cf95 | 68 | (defun calendar-bahai-leap-year-p (year) |
305c237c | 69 | "True if YEAR is a leap year on the Bahá'í calendar." |
811a8484 JW |
70 | (calendar-leap-year-p (+ year 1844))) |
71 | ||
e4e1cf95 | 72 | (defconst calendar-bahai-leap-base |
811a8484 JW |
73 | (+ (/ 1844 4) (- (/ 1844 100)) (/ 1844 400))) |
74 | ||
75 | (defun calendar-absolute-from-bahai (date) | |
305c237c | 76 | "Compute absolute date from Bahá'í date DATE. |
811a8484 JW |
77 | The absolute date is the number of days elapsed since the (imaginary) |
78 | Gregorian date Sunday, December 31, 1 BC." | |
79 | (let* ((month (extract-calendar-month date)) | |
80 | (day (extract-calendar-day date)) | |
81 | (year (extract-calendar-year date)) | |
82 | (prior-years (+ (1- year) 1844)) | |
f1209c4f | 83 | (leap-days (- (+ (/ prior-years 4) ; leap days in prior years |
811a8484 JW |
84 | (- (/ prior-years 100)) |
85 | (/ prior-years 400)) | |
e4e1cf95 | 86 | calendar-bahai-leap-base))) |
f1209c4f GM |
87 | (+ (1- calendar-bahai-epoch) ; days before epoch |
88 | (* 365 (1- year)) ; days in prior years | |
811a8484 JW |
89 | leap-days |
90 | (calendar-sum m 1 (< m month) 19) | |
91 | (if (= month 19) 4 0) | |
f1209c4f | 92 | day))) ; days so far this month |
811a8484 JW |
93 | |
94 | (defun calendar-bahai-from-absolute (date) | |
305c237c | 95 | "Bahá'í year corresponding to the absolute DATE." |
811a8484 | 96 | (if (< date calendar-bahai-epoch) |
f1209c4f | 97 | (list 0 0 0) ; pre-Bahá'í date |
811a8484 JW |
98 | (let* ((greg (calendar-gregorian-from-absolute date)) |
99 | (year (+ (- (extract-calendar-year greg) 1844) | |
100 | (if (or (> (extract-calendar-month greg) 3) | |
101 | (and (= (extract-calendar-month greg) 3) | |
102 | (>= (extract-calendar-day greg) 21))) | |
103 | 1 0))) | |
f1209c4f | 104 | (month ; search forward from Baha |
811a8484 JW |
105 | (1+ (calendar-sum m 1 |
106 | (> date | |
107 | (calendar-absolute-from-bahai | |
108 | (list m 19 year))) | |
109 | 1))) | |
f1209c4f | 110 | (day ; calculate the day by subtraction |
811a8484 JW |
111 | (- date |
112 | (1- (calendar-absolute-from-bahai (list month 1 year)))))) | |
113 | (list month day year)))) | |
114 | ||
dedac6ab | 115 | ;;;###cal-autoload |
811a8484 | 116 | (defun calendar-bahai-date-string (&optional date) |
305c237c | 117 | "String of Bahá'í date of Gregorian DATE. |
811a8484 JW |
118 | Defaults to today's date if DATE is not given." |
119 | (let* ((bahai-date (calendar-bahai-from-absolute | |
120 | (calendar-absolute-from-gregorian | |
121 | (or date (calendar-current-date))))) | |
122 | (y (extract-calendar-year bahai-date)) | |
123 | (m (extract-calendar-month bahai-date)) | |
124 | (d (extract-calendar-day bahai-date))) | |
125 | (let ((monthname | |
126 | (if (and (= m 19) | |
127 | (<= d 0)) | |
305c237c | 128 | "Ayyám-i-Há" |
e4e1cf95 | 129 | (aref calendar-bahai-month-name-array (1- m)))) |
811a8484 JW |
130 | (day (int-to-string |
131 | (if (<= d 0) | |
e4e1cf95 | 132 | (if (calendar-bahai-leap-year-p y) |
811a8484 JW |
133 | (+ d 5) |
134 | (+ d 4)) | |
135 | d))) | |
136 | (dayname nil) | |
137 | (month (int-to-string m)) | |
138 | (year (int-to-string y))) | |
139 | (mapconcat 'eval calendar-date-display-form "")))) | |
140 | ||
dedac6ab | 141 | ;;;###cal-autoload |
03368919 | 142 | (defun calendar-bahai-print-date () |
305c237c | 143 | "Show the Bahá'í calendar equivalent of the selected date." |
811a8484 | 144 | (interactive) |
305c237c | 145 | (message "Bahá'í date: %s" |
811a8484 JW |
146 | (calendar-bahai-date-string (calendar-cursor-to-date t)))) |
147 | ||
dedac6ab | 148 | ;;;###cal-autoload |
03368919 | 149 | (defun calendar-bahai-goto-date (date &optional noecho) |
305c237c JW |
150 | "Move cursor to Bahá'í date DATE. |
151 | Echo Bahá'í date unless NOECHO is t." | |
e4e1cf95 | 152 | (interactive (calendar-bahai-prompt-for-date)) |
811a8484 JW |
153 | (calendar-goto-date (calendar-gregorian-from-absolute |
154 | (calendar-absolute-from-bahai date))) | |
03368919 | 155 | (or noecho (calendar-bahai-print-date))) |
811a8484 | 156 | |
e4e1cf95 | 157 | (defun calendar-bahai-prompt-for-date () |
305c237c | 158 | "Ask for a Bahá'í date." |
811a8484 JW |
159 | (let* ((today (calendar-current-date)) |
160 | (year (calendar-read | |
305c237c | 161 | "Bahá'í calendar year (not 0): " |
9b6c7da9 | 162 | (lambda (x) (not (zerop x))) |
811a8484 JW |
163 | (int-to-string |
164 | (extract-calendar-year | |
165 | (calendar-bahai-from-absolute | |
166 | (calendar-absolute-from-gregorian today)))))) | |
167 | (completion-ignore-case t) | |
168 | (month (cdr (assoc | |
169 | (completing-read | |
305c237c | 170 | "Bahá'í calendar month name: " |
811a8484 | 171 | (mapcar 'list |
e4e1cf95 | 172 | (append calendar-bahai-month-name-array nil)) |
811a8484 | 173 | nil t) |
e4e1cf95 | 174 | (calendar-make-alist calendar-bahai-month-name-array |
811a8484 | 175 | 1)))) |
305c237c | 176 | (day (calendar-read "Bahá'í calendar day (1-19): " |
e708e9d9 | 177 | (lambda (x) (and (< 0 x) (<= x 19)))))) |
811a8484 JW |
178 | (list (list month day year)))) |
179 | ||
dedac6ab GM |
180 | (defvar displayed-month) |
181 | (defvar displayed-year) | |
811a8484 | 182 | |
dedac6ab | 183 | ;;;###holiday-autoload |
811a8484 | 184 | (defun holiday-bahai (month day string) |
305c237c JW |
185 | "Holiday on MONTH, DAY (Bahá'í) called STRING. |
186 | If MONTH, DAY (Bahá'í) is visible, the value returned is corresponding | |
811a8484 JW |
187 | Gregorian date in the form of the list (((month day year) STRING)). Returns |
188 | nil if it is not visible in the current calendar window." | |
189 | (let* ((bahai-date (calendar-bahai-from-absolute | |
190 | (calendar-absolute-from-gregorian | |
191 | (list displayed-month 15 displayed-year)))) | |
192 | (m (extract-calendar-month bahai-date)) | |
193 | (y (extract-calendar-year bahai-date)) | |
194 | (date)) | |
195 | (if (< m 1) | |
f1209c4f | 196 | nil ; Bahá'í calendar doesn't apply |
811a8484 | 197 | (increment-calendar-month m y (- 10 month)) |
f1209c4f | 198 | (if (> m 7) ; Bahá'í date might be visible |
811a8484 JW |
199 | (let ((date (calendar-gregorian-from-absolute |
200 | (calendar-absolute-from-bahai (list month day y))))) | |
201 | (if (calendar-date-is-visible-p date) | |
202 | (list (list date string)))))))) | |
203 | ||
dedac6ab GM |
204 | (defvar number) |
205 | (defvar original-date) | |
206 | ||
6df98952 GM |
207 | ;; d-b-l-e should be called from diary code. |
208 | (declare-function add-to-diary-list "diary-lib" | |
209 | (date string specifier &optional marker globcolor literal)) | |
210 | ||
dedac6ab | 211 | ;;;###diary-autoload |
03368919 | 212 | (defun diary-bahai-list-entries () |
305c237c JW |
213 | "Add any Bahá'í date entries from the diary file to `diary-entries-list'. |
214 | Bahá'í date diary entries must be prefaced by an | |
811a8484 | 215 | `bahai-diary-entry-symbol' (normally a `B'). The same diary date |
305c237c JW |
216 | forms govern the style of the Bahá'í calendar entries, except that the |
217 | Bahá'í month names must be given numerically. The Bahá'í months are | |
218 | numbered from 1 to 19 with Bahá being 1 and 19 being `Alá. If a | |
219 | Bahá'í date diary entry begins with a `diary-nonmarking-symbol', the | |
811a8484 JW |
220 | entry will appear in the diary listing, but will not be marked in the |
221 | calendar. This function is provided for use with the | |
222 | `nongregorian-diary-listing-hook'." | |
223 | (if (< 0 number) | |
224 | (let ((buffer-read-only nil) | |
225 | (diary-modified (buffer-modified-p)) | |
226 | (gdate original-date) | |
227 | (mark (regexp-quote diary-nonmarking-symbol))) | |
d7489fd9 GM |
228 | (dotimes (idummy number) |
229 | (let* ((d diary-date-forms) | |
230 | (bdate (calendar-bahai-from-absolute | |
231 | (calendar-absolute-from-gregorian gdate))) | |
232 | (month (extract-calendar-month bdate)) | |
233 | (day (extract-calendar-day bdate)) | |
234 | (year (extract-calendar-year bdate))) | |
235 | (while d | |
236 | (let* | |
237 | ((date-form (if (equal (car (car d)) 'backup) | |
238 | (cdr (car d)) | |
239 | (car d))) | |
240 | (backup (equal (car (car d)) 'backup)) | |
241 | (dayname | |
242 | (concat | |
243 | (calendar-day-name gdate) "\\|" | |
244 | (substring (calendar-day-name gdate) 0 3) ".?")) | |
245 | (calendar-month-name-array | |
e4e1cf95 | 246 | calendar-bahai-month-name-array) |
d7489fd9 GM |
247 | (monthname |
248 | (concat | |
249 | "\\*\\|" | |
250 | (calendar-month-name month))) | |
251 | (month (concat "\\*\\|0*" (int-to-string month))) | |
252 | (day (concat "\\*\\|0*" (int-to-string day))) | |
253 | (year | |
254 | (concat | |
255 | "\\*\\|0*" (int-to-string year) | |
256 | (if abbreviated-calendar-year | |
257 | (concat "\\|" (int-to-string (% year 100))) | |
258 | ""))) | |
259 | (regexp | |
260 | (concat | |
261 | "\\(\\`\\|\^M\\|\n\\)" mark "?" | |
262 | (regexp-quote bahai-diary-entry-symbol) | |
263 | "\\(" | |
264 | (mapconcat 'eval date-form "\\)\\(") | |
265 | "\\)")) | |
266 | (case-fold-search t)) | |
267 | (goto-char (point-min)) | |
268 | (while (re-search-forward regexp nil t) | |
269 | (if backup (re-search-backward "\\<" nil t)) | |
270 | (if (and (or (char-equal (preceding-char) ?\^M) | |
271 | (char-equal (preceding-char) ?\n)) | |
272 | (not (looking-at " \\|\^I"))) | |
f1209c4f | 273 | ;; Diary entry that consists only of date. |
d7489fd9 | 274 | (backward-char 1) |
f1209c4f GM |
275 | ;; Found a nonempty diary entry--make it visible and |
276 | ;; add it to the list. | |
d7489fd9 GM |
277 | (let ((entry-start (point)) |
278 | (date-start)) | |
279 | (re-search-backward "\^M\\|\n\\|\\`") | |
280 | (setq date-start (point)) | |
281 | (re-search-forward "\^M\\|\n" nil t 2) | |
282 | (while (looking-at " \\|\^I") | |
283 | (re-search-forward "\^M\\|\n" nil t)) | |
284 | (backward-char 1) | |
285 | (subst-char-in-region date-start (point) ?\^M ?\n t) | |
286 | (add-to-diary-list | |
287 | gdate | |
288 | (buffer-substring-no-properties entry-start (point)) | |
289 | (buffer-substring-no-properties | |
290 | (1+ date-start) (1- entry-start))))))) | |
291 | (setq d (cdr d)))) | |
292 | (setq gdate | |
293 | (calendar-gregorian-from-absolute | |
294 | (1+ (calendar-absolute-from-gregorian gdate))))) | |
295 | (set-buffer-modified-p diary-modified)) | |
296 | (goto-char (point-min)))) | |
811a8484 | 297 | |
6df98952 GM |
298 | (declare-function diary-name-pattern "diary-lib" |
299 | (string-array &optional abbrev-array paren)) | |
300 | ||
301 | (declare-function mark-calendar-days-named "diary-lib" | |
302 | (dayname &optional color)) | |
303 | ||
dedac6ab | 304 | ;;;###diary-autoload |
e4e1cf95 | 305 | (defun diary-bahai-mark-entries () |
305c237c | 306 | "Mark days in the calendar window that have Bahá'í date diary entries. |
2c4abeb8 GM |
307 | Each entry in `diary-file' (or included files) visible in the calendar |
308 | window is marked. Bahá'í date entries are prefaced by | |
309 | `bahai-diary-entry-symbol' (normally a \"B\"). The same | |
310 | `diary-date-forms' govern the style of the Bahá'í calendar entries, | |
305c237c JW |
311 | except that the Bahá'í month names must be spelled in full. The |
312 | Bahá'í months are numbered from 1 to 12 with Bahá being 1 and 12 being | |
2c4abeb8 GM |
313 | `Alá. Bahá'í date diary entries that begin with `diary-nonmarking-symbol' |
314 | will not be marked in the calendar. This function is provided for use as | |
315 | part of `nongregorian-diary-marking-hook'." | |
811a8484 JW |
316 | (let ((d diary-date-forms)) |
317 | (while d | |
318 | (let* | |
319 | ((date-form (if (equal (car (car d)) 'backup) | |
320 | (cdr (car d)) | |
f1209c4f | 321 | (car d))) ; ignore 'backup directive |
811a8484 JW |
322 | (dayname (diary-name-pattern calendar-day-name-array)) |
323 | (monthname | |
324 | (concat | |
e4e1cf95 | 325 | (diary-name-pattern calendar-bahai-month-name-array t) |
811a8484 JW |
326 | "\\|\\*")) |
327 | (month "[0-9]+\\|\\*") | |
328 | (day "[0-9]+\\|\\*") | |
329 | (year "[0-9]+\\|\\*") | |
330 | (l (length date-form)) | |
331 | (d-name-pos (- l (length (memq 'dayname date-form)))) | |
332 | (d-name-pos (if (/= l d-name-pos) (+ 2 d-name-pos))) | |
333 | (m-name-pos (- l (length (memq 'monthname date-form)))) | |
334 | (m-name-pos (if (/= l m-name-pos) (+ 2 m-name-pos))) | |
335 | (d-pos (- l (length (memq 'day date-form)))) | |
336 | (d-pos (if (/= l d-pos) (+ 2 d-pos))) | |
337 | (m-pos (- l (length (memq 'month date-form)))) | |
338 | (m-pos (if (/= l m-pos) (+ 2 m-pos))) | |
339 | (y-pos (- l (length (memq 'year date-form)))) | |
340 | (y-pos (if (/= l y-pos) (+ 2 y-pos))) | |
341 | (regexp | |
342 | (concat | |
343 | "\\(\\`\\|\^M\\|\n\\)" | |
344 | (regexp-quote bahai-diary-entry-symbol) | |
345 | "\\(" | |
346 | (mapconcat 'eval date-form "\\)\\(") | |
347 | "\\)")) | |
348 | (case-fold-search t)) | |
349 | (goto-char (point-min)) | |
350 | (while (re-search-forward regexp nil t) | |
351 | (let* ((dd-name | |
352 | (if d-name-pos | |
353 | (buffer-substring | |
354 | (match-beginning d-name-pos) | |
355 | (match-end d-name-pos)))) | |
356 | (mm-name | |
357 | (if m-name-pos | |
358 | (buffer-substring | |
359 | (match-beginning m-name-pos) | |
360 | (match-end m-name-pos)))) | |
027a4b6b | 361 | (mm (string-to-number |
811a8484 JW |
362 | (if m-pos |
363 | (buffer-substring | |
364 | (match-beginning m-pos) | |
365 | (match-end m-pos)) | |
366 | ""))) | |
027a4b6b | 367 | (dd (string-to-number |
811a8484 JW |
368 | (if d-pos |
369 | (buffer-substring | |
370 | (match-beginning d-pos) | |
371 | (match-end d-pos)) | |
372 | ""))) | |
373 | (y-str (if y-pos | |
374 | (buffer-substring | |
375 | (match-beginning y-pos) | |
376 | (match-end y-pos)))) | |
377 | (yy (if (not y-str) | |
378 | 0 | |
379 | (if (and (= (length y-str) 2) | |
380 | abbreviated-calendar-year) | |
381 | (let* ((current-y | |
382 | (extract-calendar-year | |
383 | (calendar-bahai-from-absolute | |
384 | (calendar-absolute-from-gregorian | |
385 | (calendar-current-date))))) | |
027a4b6b | 386 | (y (+ (string-to-number y-str) |
811a8484 JW |
387 | (* 100 (/ current-y 100))))) |
388 | (if (> (- y current-y) 50) | |
389 | (- y 100) | |
390 | (if (> (- current-y y) 50) | |
391 | (+ y 100) | |
392 | y))) | |
027a4b6b | 393 | (string-to-number y-str))))) |
811a8484 JW |
394 | (if dd-name |
395 | (mark-calendar-days-named | |
59d8fe2e JB |
396 | (cdr (assoc-string (substring dd-name 0 3) |
397 | (calendar-make-alist | |
398 | calendar-day-name-array | |
399 | 0 | |
e708e9d9 | 400 | (lambda (x) (substring x 0 3))) |
59d8fe2e | 401 | t))) |
811a8484 JW |
402 | (if mm-name |
403 | (if (string-equal mm-name "*") | |
404 | (setq mm 0) | |
405 | (setq mm | |
59d8fe2e | 406 | (cdr (assoc-string |
811a8484 JW |
407 | mm-name |
408 | (calendar-make-alist | |
e4e1cf95 | 409 | calendar-bahai-month-name-array) |
59d8fe2e | 410 | t))))) |
e4e1cf95 | 411 | (calendar-bahai-mark-date-pattern mm dd yy))))) |
811a8484 JW |
412 | (setq d (cdr d))))) |
413 | ||
dedac6ab | 414 | ;;;###diary-autoload |
e4e1cf95 | 415 | (defun calendar-bahai-mark-date-pattern (month day year) |
305c237c | 416 | "Mark dates in calendar window that conform to Bahá'í date MONTH/DAY/YEAR. |
811a8484 JW |
417 | A value of 0 in any position is a wildcard." |
418 | (save-excursion | |
419 | (set-buffer calendar-buffer) | |
9b6c7da9 GM |
420 | (if (and (not (zerop month)) (not (zerop day))) |
421 | (if (not (zerop year)) | |
305c237c | 422 | ;; Fully specified Bahá'í date. |
811a8484 JW |
423 | (let ((date (calendar-gregorian-from-absolute |
424 | (calendar-absolute-from-bahai | |
425 | (list month day year))))) | |
426 | (if (calendar-date-is-visible-p date) | |
427 | (mark-visible-calendar-date date))) | |
428 | ;; Month and day in any year--this taken from the holiday stuff. | |
429 | (let* ((bahai-date (calendar-bahai-from-absolute | |
430 | (calendar-absolute-from-gregorian | |
431 | (list displayed-month 15 displayed-year)))) | |
432 | (m (extract-calendar-month bahai-date)) | |
433 | (y (extract-calendar-year bahai-date)) | |
434 | (date)) | |
435 | (if (< m 1) | |
f1209c4f | 436 | nil ; Bahá'í calendar doesn't apply |
811a8484 | 437 | (increment-calendar-month m y (- 10 month)) |
f1209c4f | 438 | (if (> m 7) ; Bahá'í date might be visible |
811a8484 JW |
439 | (let ((date (calendar-gregorian-from-absolute |
440 | (calendar-absolute-from-bahai | |
441 | (list month day y))))) | |
442 | (if (calendar-date-is-visible-p date) | |
443 | (mark-visible-calendar-date date))))))) | |
444 | ;; Not one of the simple cases--check all visible dates for match. | |
445 | ;; Actually, the following code takes care of ALL of the cases, but | |
446 | ;; it's much too slow to be used for the simple (common) cases. | |
447 | (let ((m displayed-month) | |
448 | (y displayed-year) | |
449 | (first-date) | |
450 | (last-date)) | |
451 | (increment-calendar-month m y -1) | |
452 | (setq first-date | |
453 | (calendar-absolute-from-gregorian | |
454 | (list m 1 y))) | |
455 | (increment-calendar-month m y 2) | |
456 | (setq last-date | |
457 | (calendar-absolute-from-gregorian | |
458 | (list m (calendar-last-day-of-month m y) y))) | |
459 | (calendar-for-loop date from first-date to last-date do | |
460 | (let* ((b-date (calendar-bahai-from-absolute date)) | |
461 | (i-month (extract-calendar-month b-date)) | |
462 | (i-day (extract-calendar-day b-date)) | |
463 | (i-year (extract-calendar-year b-date))) | |
464 | (and (or (zerop month) | |
465 | (= month i-month)) | |
466 | (or (zerop day) | |
467 | (= day i-day)) | |
468 | (or (zerop year) | |
469 | (= year i-year)) | |
470 | (mark-visible-calendar-date | |
471 | (calendar-gregorian-from-absolute date))))))))) | |
472 | ||
dedac6ab | 473 | ;;;###cal-autoload |
03368919 | 474 | (defun diary-bahai-insert-entry (arg) |
811a8484 | 475 | "Insert a diary entry. |
305c237c | 476 | For the Bahá'í date corresponding to the date indicated by point. |
2c4abeb8 | 477 | Prefix argument ARG makes the entry nonmarking." |
811a8484 | 478 | (interactive "P") |
e4e1cf95 | 479 | (let* ((calendar-month-name-array calendar-bahai-month-name-array)) |
811a8484 JW |
480 | (make-diary-entry |
481 | (concat | |
482 | bahai-diary-entry-symbol | |
916f8173 | 483 | (calendar-date-string |
811a8484 JW |
484 | (calendar-bahai-from-absolute |
485 | (calendar-absolute-from-gregorian | |
486 | (calendar-cursor-to-date t))) | |
487 | nil t)) | |
488 | arg))) | |
489 | ||
dedac6ab | 490 | ;;;###cal-autoload |
e4e1cf95 | 491 | (defun diary-bahai-insert-monthly-entry (arg) |
811a8484 | 492 | "Insert a monthly diary entry. |
305c237c | 493 | For the day of the Bahá'í month corresponding to the date indicated by point. |
2c4abeb8 | 494 | Prefix argument ARG makes the entry nonmarking." |
811a8484 JW |
495 | (interactive "P") |
496 | (let* ((calendar-date-display-form | |
497 | (if european-calendar-style '(day " * ") '("* " day ))) | |
e4e1cf95 | 498 | (calendar-month-name-array calendar-bahai-month-name-array)) |
811a8484 JW |
499 | (make-diary-entry |
500 | (concat | |
501 | bahai-diary-entry-symbol | |
916f8173 | 502 | (calendar-date-string |
811a8484 JW |
503 | (calendar-bahai-from-absolute |
504 | (calendar-absolute-from-gregorian | |
505 | (calendar-cursor-to-date t))))) | |
506 | arg))) | |
507 | ||
dedac6ab | 508 | ;;;###cal-autoload |
e4e1cf95 | 509 | (defun diary-bahai-insert-yearly-entry (arg) |
811a8484 | 510 | "Insert an annual diary entry. |
305c237c | 511 | For the day of the Bahá'í year corresponding to the date indicated by point. |
2c4abeb8 | 512 | Prefix argument ARG will make the entry nonmarking." |
811a8484 JW |
513 | (interactive "P") |
514 | (let* ((calendar-date-display-form | |
515 | (if european-calendar-style | |
516 | '(day " " monthname) | |
517 | '(monthname " " day))) | |
e4e1cf95 | 518 | (calendar-month-name-array calendar-bahai-month-name-array)) |
811a8484 JW |
519 | (make-diary-entry |
520 | (concat | |
521 | bahai-diary-entry-symbol | |
916f8173 | 522 | (calendar-date-string |
811a8484 JW |
523 | (calendar-bahai-from-absolute |
524 | (calendar-absolute-from-gregorian | |
525 | (calendar-cursor-to-date t))))) | |
526 | arg))) | |
527 | ||
dedac6ab GM |
528 | (defvar date) |
529 | ||
530 | ;; To be called from list-sexp-diary-entries, where DATE is bound. | |
531 | ;;;###diary-autoload | |
532 | (defun diary-bahai-date () | |
533 | "Bahá'í calendar equivalent of date diary entry." | |
534 | (format "Bahá'í date: %s" (calendar-bahai-date-string date))) | |
535 | ||
536 | ||
e4e1cf95 SM |
537 | ;; Backward compatibility. |
538 | (define-obsolete-function-alias | |
03368919 | 539 | 'list-bahai-diary-entries 'diary-bahai-list-entries "23.1") |
e4e1cf95 | 540 | (define-obsolete-function-alias |
03368919 | 541 | 'mark-bahai-diary-entries 'diary-bahai-mark-entries "23.1") |
e4e1cf95 | 542 | (define-obsolete-function-alias |
03368919 | 543 | 'insert-bahai-diary-entry 'diary-bahai-insert-entry "23.1") |
e4e1cf95 | 544 | (define-obsolete-function-alias |
92186479 | 545 | 'insert-monthly-bahai-diary-entry 'diary-bahai-insert-monthly-entry "23.1") |
e4e1cf95 | 546 | (define-obsolete-function-alias |
92186479 | 547 | 'insert-yearly-bahai-diary-entry 'diary-bahai-insert-yearly-entry "23.1") |
e4e1cf95 SM |
548 | (define-obsolete-function-alias |
549 | 'mark-bahai-calendar-date-pattern 'calendar-bahai-mark-date-pattern "23.1") | |
03368919 SM |
550 | (define-obsolete-function-alias |
551 | 'calendar-goto-bahai-date 'calendar-bahai-goto-date "23.1") | |
552 | (define-obsolete-function-alias | |
553 | 'calendar-print-bahai-date 'calendar-bahai-print-date "23.1") | |
e4e1cf95 | 554 | |
811a8484 JW |
555 | (provide 'cal-bahai) |
556 | ||
e708e9d9 GM |
557 | ;; Local Variables: |
558 | ;; coding: utf-8 | |
e708e9d9 GM |
559 | ;; End: |
560 | ||
e4e1cf95 | 561 | ;; arch-tag: c1cb1d67-862a-4264-a01c-41cb4df01f14 |
811a8484 | 562 | ;;; cal-bahai.el ends here |