comparison lisp/calendar/cal-bahai.el @ 82787:03ac28e9a566

2007-08-23 John Wiegley <johnw@newartisans.com> * calendar/cal-bahai.el: Added in the diacriticals that were missing for many of the month names.
author John Wiegley <johnw@newartisans.com>
date Thu, 23 Aug 2007 18:37:08 +0000
parents f673ee49d36e
children 8c8c5e6ccef2
comparison
equal deleted inserted replaced
82786:9968ecc9655b 82787:03ac28e9a566
1 ;;; cal-bahai.el --- calendar functions for the Baha'i calendar. 1 ;;; cal-bahai.el --- calendar functions for the Bahá'í calendar.
2 2
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 ;; Free Software Foundation, Inc. 4 ;; Free Software Foundation, Inc.
5 5
6 ;; Author: John Wiegley <johnw@gnu.org> 6 ;; Author: John Wiegley <johnw@gnu.org>
7 ;; Keywords: calendar 7 ;; Keywords: calendar
8 ;; Human-Keywords: Baha'i calendar, Baha'i, Bahai, calendar, diary 8 ;; Human-Keywords: Bahá'í calendar, Bahá'í, Baha'i, Bahai, calendar, diary
9 9
10 ;; This file is part of GNU Emacs. 10 ;; This file is part of GNU Emacs.
11 11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify 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 13 ;; it under the terms of the GNU General Public License as published by
25 ;; Boston, MA 02110-1301, USA. 25 ;; Boston, MA 02110-1301, USA.
26 26
27 ;;; Commentary: 27 ;;; Commentary:
28 28
29 ;; This collection of functions implements the features of calendar.el 29 ;; This collection of functions implements the features of calendar.el
30 ;; and diary.el that deal with the Baha'i calendar. 30 ;; and diary.el that deal with the Bahá'í calendar.
31 31
32 ;; The Baha'i (http://www.bahai.org) calendar system is based on a 32 ;; The Bahá'í (http://www.bahai.org) calendar system is based on a
33 ;; solar cycle of 19 months with 19 days each. The four remaining 33 ;; solar cycle of 19 months with 19 days each. The four remaining
34 ;; "intercalary" days are called the Ayyam-i-Ha (days of Ha), and are 34 ;; "intercalary" days are called the Ayyám-i-Há (days of Há), and are
35 ;; placed between the 18th and 19th months. They are meant as a time 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 36 ;; of festivals preceding the 19th month, which is the month of
37 ;; fasting. In Gregorian leap years, there are 5 of these days (Ha 37 ;; fasting. In Gregorian leap years, there are 5 of these days (Há
38 ;; has the numerical value of 5 in the arabic abjad, or 38 ;; has the numerical value of 5 in the arabic abjad, or
39 ;; letter-to-number, reckoning). 39 ;; letter-to-number, reckoning).
40 40
41 ;; Each month is named after an attribute of God, as are the 19 days 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 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 43 ;; for each year in every 19 year cycle. These cycles are called
44 ;; Vahids. A cycle of 19 Vahids (361 years) is called a Kullu-Shay, 44 ;; Váhids. A cycle of 19 Váhids (361 years) is called a Kullu-Shay,
45 ;; which means "all things". 45 ;; which means "all things".
46 46
47 ;; The calendar was named the "Badi calendar" by its author, the Bab. 47 ;; The calendar was named the "Badí` calendar" by its author, the Báb.
48 ;; It uses a week of seven days, corresponding to the Gregorian week, 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 49 ;; each of which has its own name, again patterned after the
50 ;; attributes of God. 50 ;; attributes of God.
51 51
52 ;; Note: The days of Ayyam-i-Ha are encoded as zero and negative 52 ;; Note: The days of Ayyám-i-Há are encoded as zero and negative
53 ;; offsets from the first day of the final month. So, (19 -3 157) is 53 ;; offsets from the first day of the final month. So, (19 -3 157) is
54 ;; the first day of Ayyam-i-Ha, in the year 157 BE. 54 ;; the first day of Ayyám-i-Há, in the year 157 BE.
55 55
56 ;;; Code: 56 ;;; Code:
57 57
58 (defvar date) 58 (defvar date)
59 (defvar displayed-month) 59 (defvar displayed-month)
62 (defvar original-date) 62 (defvar original-date)
63 63
64 (require 'cal-julian) 64 (require 'cal-julian)
65 65
66 (defconst calendar-bahai-month-name-array 66 (defconst calendar-bahai-month-name-array
67 ["Baha" "Jalal" "Jamal" "`Azamat" "Nur" "Rahmat" "Kalimat" "Kamal" 67 ["Bahá" "Jalál" "Jamál" "`Azamat" "Núr" "Rahmat" "Kalimát" "Kamál"
68 "Asma" "`Izzat" "Mashiyyat" "`Ilm" "Qudrat" "Qawl" "Masa'il" 68 "Asmá" "`Izzat" "Mashiyyat" "`Ilm" "Qudrat" "Qawl" "Masá'il"
69 "Sharaf" "Sultan" "Mulk" "`Ala"]) 69 "Sharaf" "Sultán" "Mulk" "`Alá"])
70 70
71 (defconst calendar-bahai-epoch (calendar-absolute-from-gregorian '(3 21 1844)) 71 (defconst calendar-bahai-epoch (calendar-absolute-from-gregorian '(3 21 1844))
72 "Absolute date of start of Baha'i calendar = March 19, 622 A.D. (Julian).") 72 "Absolute date of start of Bahá'í calendar = March 19, 622 A.D. (Julian).")
73 73
74 (defun calendar-bahai-leap-year-p (year) 74 (defun calendar-bahai-leap-year-p (year)
75 "True if YEAR is a leap year on the Baha'i calendar." 75 "True if YEAR is a leap year on the Bahá'í calendar."
76 (calendar-leap-year-p (+ year 1844))) 76 (calendar-leap-year-p (+ year 1844)))
77 77
78 (defconst calendar-bahai-leap-base 78 (defconst calendar-bahai-leap-base
79 (+ (/ 1844 4) (- (/ 1844 100)) (/ 1844 400))) 79 (+ (/ 1844 4) (- (/ 1844 100)) (/ 1844 400)))
80 80
81 (defun calendar-absolute-from-bahai (date) 81 (defun calendar-absolute-from-bahai (date)
82 "Compute absolute date from Baha'i date DATE. 82 "Compute absolute date from Bahá'í date DATE.
83 The absolute date is the number of days elapsed since the (imaginary) 83 The absolute date is the number of days elapsed since the (imaginary)
84 Gregorian date Sunday, December 31, 1 BC." 84 Gregorian date Sunday, December 31, 1 BC."
85 (let* ((month (extract-calendar-month date)) 85 (let* ((month (extract-calendar-month date))
86 (day (extract-calendar-day date)) 86 (day (extract-calendar-day date))
87 (year (extract-calendar-year date)) 87 (year (extract-calendar-year date))
96 (calendar-sum m 1 (< m month) 19) 96 (calendar-sum m 1 (< m month) 19)
97 (if (= month 19) 4 0) 97 (if (= month 19) 4 0)
98 day))) ; Days so far this month. 98 day))) ; Days so far this month.
99 99
100 (defun calendar-bahai-from-absolute (date) 100 (defun calendar-bahai-from-absolute (date)
101 "Baha'i year corresponding to the absolute DATE." 101 "Bahá'í year corresponding to the absolute DATE."
102 (if (< date calendar-bahai-epoch) 102 (if (< date calendar-bahai-epoch)
103 (list 0 0 0) ;; pre-Baha'i date 103 (list 0 0 0) ;; pre-Bahá'í date
104 (let* ((greg (calendar-gregorian-from-absolute date)) 104 (let* ((greg (calendar-gregorian-from-absolute date))
105 (year (+ (- (extract-calendar-year greg) 1844) 105 (year (+ (- (extract-calendar-year greg) 1844)
106 (if (or (> (extract-calendar-month greg) 3) 106 (if (or (> (extract-calendar-month greg) 3)
107 (and (= (extract-calendar-month greg) 3) 107 (and (= (extract-calendar-month greg) 3)
108 (>= (extract-calendar-day greg) 21))) 108 (>= (extract-calendar-day greg) 21)))
117 (- date 117 (- date
118 (1- (calendar-absolute-from-bahai (list month 1 year)))))) 118 (1- (calendar-absolute-from-bahai (list month 1 year))))))
119 (list month day year)))) 119 (list month day year))))
120 120
121 (defun calendar-bahai-date-string (&optional date) 121 (defun calendar-bahai-date-string (&optional date)
122 "String of Baha'i date of Gregorian DATE. 122 "String of Bahá'í date of Gregorian DATE.
123 Defaults to today's date if DATE is not given." 123 Defaults to today's date if DATE is not given."
124 (let* ((bahai-date (calendar-bahai-from-absolute 124 (let* ((bahai-date (calendar-bahai-from-absolute
125 (calendar-absolute-from-gregorian 125 (calendar-absolute-from-gregorian
126 (or date (calendar-current-date))))) 126 (or date (calendar-current-date)))))
127 (y (extract-calendar-year bahai-date)) 127 (y (extract-calendar-year bahai-date))
128 (m (extract-calendar-month bahai-date)) 128 (m (extract-calendar-month bahai-date))
129 (d (extract-calendar-day bahai-date))) 129 (d (extract-calendar-day bahai-date)))
130 (let ((monthname 130 (let ((monthname
131 (if (and (= m 19) 131 (if (and (= m 19)
132 (<= d 0)) 132 (<= d 0))
133 "Ayyam-i-Ha" 133 "Ayyám-i-Há"
134 (aref calendar-bahai-month-name-array (1- m)))) 134 (aref calendar-bahai-month-name-array (1- m))))
135 (day (int-to-string 135 (day (int-to-string
136 (if (<= d 0) 136 (if (<= d 0)
137 (if (calendar-bahai-leap-year-p y) 137 (if (calendar-bahai-leap-year-p y)
138 (+ d 5) 138 (+ d 5)
142 (month (int-to-string m)) 142 (month (int-to-string m))
143 (year (int-to-string y))) 143 (year (int-to-string y)))
144 (mapconcat 'eval calendar-date-display-form "")))) 144 (mapconcat 'eval calendar-date-display-form ""))))
145 145
146 (defun calendar-print-bahai-date () 146 (defun calendar-print-bahai-date ()
147 "Show the Baha'i calendar equivalent of the selected date." 147 "Show the Bahá'í calendar equivalent of the selected date."
148 (interactive) 148 (interactive)
149 (message "Baha'i date: %s" 149 (message "Bahá'í date: %s"
150 (calendar-bahai-date-string (calendar-cursor-to-date t)))) 150 (calendar-bahai-date-string (calendar-cursor-to-date t))))
151 151
152 (defun calendar-goto-bahai-date (date &optional noecho) 152 (defun calendar-goto-bahai-date (date &optional noecho)
153 "Move cursor to Baha'i date DATE. 153 "Move cursor to Bahá'í date DATE.
154 Echo Baha'i date unless NOECHO is t." 154 Echo Bahá'í date unless NOECHO is t."
155 (interactive (calendar-bahai-prompt-for-date)) 155 (interactive (calendar-bahai-prompt-for-date))
156 (calendar-goto-date (calendar-gregorian-from-absolute 156 (calendar-goto-date (calendar-gregorian-from-absolute
157 (calendar-absolute-from-bahai date))) 157 (calendar-absolute-from-bahai date)))
158 (or noecho (calendar-print-bahai-date))) 158 (or noecho (calendar-print-bahai-date)))
159 159
160 (defun calendar-bahai-prompt-for-date () 160 (defun calendar-bahai-prompt-for-date ()
161 "Ask for a Baha'i date." 161 "Ask for a Bahá'í date."
162 (let* ((today (calendar-current-date)) 162 (let* ((today (calendar-current-date))
163 (year (calendar-read 163 (year (calendar-read
164 "Baha'i calendar year (not 0): " 164 "Bahá'í calendar year (not 0): "
165 '(lambda (x) (/= x 0)) 165 '(lambda (x) (/= x 0))
166 (int-to-string 166 (int-to-string
167 (extract-calendar-year 167 (extract-calendar-year
168 (calendar-bahai-from-absolute 168 (calendar-bahai-from-absolute
169 (calendar-absolute-from-gregorian today)))))) 169 (calendar-absolute-from-gregorian today))))))
170 (completion-ignore-case t) 170 (completion-ignore-case t)
171 (month (cdr (assoc 171 (month (cdr (assoc
172 (completing-read 172 (completing-read
173 "Baha'i calendar month name: " 173 "Bahá'í calendar month name: "
174 (mapcar 'list 174 (mapcar 'list
175 (append calendar-bahai-month-name-array nil)) 175 (append calendar-bahai-month-name-array nil))
176 nil t) 176 nil t)
177 (calendar-make-alist calendar-bahai-month-name-array 177 (calendar-make-alist calendar-bahai-month-name-array
178 1)))) 178 1))))
179 (day (calendar-read "Baha'i calendar day (1-19): " 179 (day (calendar-read "Bahá'í calendar day (1-19): "
180 '(lambda (x) (and (< 0 x) (<= x 19)))))) 180 '(lambda (x) (and (< 0 x) (<= x 19))))))
181 (list (list month day year)))) 181 (list (list month day year))))
182 182
183 (defun diary-bahai-date () 183 (defun diary-bahai-date ()
184 "Baha'i calendar equivalent of date diary entry." 184 "Bahá'í calendar equivalent of date diary entry."
185 (format "Baha'i date: %s" (calendar-bahai-date-string date))) 185 (format "Bahá'í date: %s" (calendar-bahai-date-string date)))
186 186
187 (defun holiday-bahai (month day string) 187 (defun holiday-bahai (month day string)
188 "Holiday on MONTH, DAY (Baha'i) called STRING. 188 "Holiday on MONTH, DAY (Bahá'í) called STRING.
189 If MONTH, DAY (Baha'i) is visible, the value returned is corresponding 189 If MONTH, DAY (Bahá'í) is visible, the value returned is corresponding
190 Gregorian date in the form of the list (((month day year) STRING)). Returns 190 Gregorian date in the form of the list (((month day year) STRING)). Returns
191 nil if it is not visible in the current calendar window." 191 nil if it is not visible in the current calendar window."
192 (let* ((bahai-date (calendar-bahai-from-absolute 192 (let* ((bahai-date (calendar-bahai-from-absolute
193 (calendar-absolute-from-gregorian 193 (calendar-absolute-from-gregorian
194 (list displayed-month 15 displayed-year)))) 194 (list displayed-month 15 displayed-year))))
195 (m (extract-calendar-month bahai-date)) 195 (m (extract-calendar-month bahai-date))
196 (y (extract-calendar-year bahai-date)) 196 (y (extract-calendar-year bahai-date))
197 (date)) 197 (date))
198 (if (< m 1) 198 (if (< m 1)
199 nil ;; Baha'i calendar doesn't apply. 199 nil ;; Bahá'í calendar doesn't apply.
200 (increment-calendar-month m y (- 10 month)) 200 (increment-calendar-month m y (- 10 month))
201 (if (> m 7) ;; Baha'i date might be visible 201 (if (> m 7) ;; Bahá'í date might be visible
202 (let ((date (calendar-gregorian-from-absolute 202 (let ((date (calendar-gregorian-from-absolute
203 (calendar-absolute-from-bahai (list month day y))))) 203 (calendar-absolute-from-bahai (list month day y)))))
204 (if (calendar-date-is-visible-p date) 204 (if (calendar-date-is-visible-p date)
205 (list (list date string)))))))) 205 (list (list date string))))))))
206 206
207 (defun diary-list-bahai-entries () 207 (defun diary-list-bahai-entries ()
208 "Add any Baha'i date entries from the diary file to `diary-entries-list'. 208 "Add any Bahá'í date entries from the diary file to `diary-entries-list'.
209 Baha'i date diary entries must be prefaced by an 209 Bahá'í date diary entries must be prefaced by an
210 `bahai-diary-entry-symbol' (normally a `B'). The same diary date 210 `bahai-diary-entry-symbol' (normally a `B'). The same diary date
211 forms govern the style of the Baha'i calendar entries, except that the 211 forms govern the style of the Bahá'í calendar entries, except that the
212 Baha'i month names must be given numerically. The Baha'i months are 212 Bahá'í month names must be given numerically. The Bahá'í months are
213 numbered from 1 to 19 with Baha being 1 and 19 being `Ala. If a 213 numbered from 1 to 19 with Bahá being 1 and 19 being `Alá. If a
214 Baha'i date diary entry begins with a `diary-nonmarking-symbol', the 214 Bahá'í date diary entry begins with a `diary-nonmarking-symbol', the
215 entry will appear in the diary listing, but will not be marked in the 215 entry will appear in the diary listing, but will not be marked in the
216 calendar. This function is provided for use with the 216 calendar. This function is provided for use with the
217 `nongregorian-diary-listing-hook'." 217 `nongregorian-diary-listing-hook'."
218 (if (< 0 number) 218 (if (< 0 number)
219 (let ((buffer-read-only nil) 219 (let ((buffer-read-only nil)
289 (1+ (calendar-absolute-from-gregorian gdate))))) 289 (1+ (calendar-absolute-from-gregorian gdate)))))
290 (set-buffer-modified-p diary-modified)) 290 (set-buffer-modified-p diary-modified))
291 (goto-char (point-min)))) 291 (goto-char (point-min))))
292 292
293 (defun diary-bahai-mark-entries () 293 (defun diary-bahai-mark-entries ()
294 "Mark days in the calendar window that have Baha'i date diary entries. 294 "Mark days in the calendar window that have Bahá'í date diary entries.
295 Each entry in diary-file (or included files) visible in the calendar 295 Each entry in diary-file (or included files) visible in the calendar
296 window is marked. Baha'i date entries are prefaced by a 296 window is marked. Bahá'í date entries are prefaced by a
297 bahai-diary-entry-symbol \(normally a B`I'). The same 297 bahai-diary-entry-symbol \(normally a B`I'). The same
298 diary-date-forms govern the style of the Baha'i calendar entries, 298 diary-date-forms govern the style of the Bahá'í calendar entries,
299 except that the Baha'i month names must be spelled in full. The 299 except that the Bahá'í month names must be spelled in full. The
300 Baha'i months are numbered from 1 to 12 with Baha being 1 and 12 being 300 Bahá'í months are numbered from 1 to 12 with Bahá being 1 and 12 being
301 `Ala. Baha'i date diary entries that begin with a 301 `Alá. Bahá'í date diary entries that begin with a
302 diary-nonmarking-symbol will not be marked in the calendar. This 302 diary-nonmarking-symbol will not be marked in the calendar. This
303 function is provided for use as part of the 303 function is provided for use as part of the
304 nongregorian-diary-marking-hook." 304 nongregorian-diary-marking-hook."
305 (let ((d diary-date-forms)) 305 (let ((d diary-date-forms))
306 (while d 306 (while d
399 t))))) 399 t)))))
400 (calendar-bahai-mark-date-pattern mm dd yy))))) 400 (calendar-bahai-mark-date-pattern mm dd yy)))))
401 (setq d (cdr d))))) 401 (setq d (cdr d)))))
402 402
403 (defun calendar-bahai-mark-date-pattern (month day year) 403 (defun calendar-bahai-mark-date-pattern (month day year)
404 "Mark dates in calendar window that conform to Baha'i date MONTH/DAY/YEAR. 404 "Mark dates in calendar window that conform to Bahá'í date MONTH/DAY/YEAR.
405 A value of 0 in any position is a wildcard." 405 A value of 0 in any position is a wildcard."
406 (save-excursion 406 (save-excursion
407 (set-buffer calendar-buffer) 407 (set-buffer calendar-buffer)
408 (if (and (/= 0 month) (/= 0 day)) 408 (if (and (/= 0 month) (/= 0 day))
409 (if (/= 0 year) 409 (if (/= 0 year)
410 ;; Fully specified Baha'i date. 410 ;; Fully specified Bahá'í date.
411 (let ((date (calendar-gregorian-from-absolute 411 (let ((date (calendar-gregorian-from-absolute
412 (calendar-absolute-from-bahai 412 (calendar-absolute-from-bahai
413 (list month day year))))) 413 (list month day year)))))
414 (if (calendar-date-is-visible-p date) 414 (if (calendar-date-is-visible-p date)
415 (mark-visible-calendar-date date))) 415 (mark-visible-calendar-date date)))
419 (list displayed-month 15 displayed-year)))) 419 (list displayed-month 15 displayed-year))))
420 (m (extract-calendar-month bahai-date)) 420 (m (extract-calendar-month bahai-date))
421 (y (extract-calendar-year bahai-date)) 421 (y (extract-calendar-year bahai-date))
422 (date)) 422 (date))
423 (if (< m 1) 423 (if (< m 1)
424 nil;; Baha'i calendar doesn't apply. 424 nil;; Bahá'í calendar doesn't apply.
425 (increment-calendar-month m y (- 10 month)) 425 (increment-calendar-month m y (- 10 month))
426 (if (> m 7);; Baha'i date might be visible 426 (if (> m 7);; Bahá'í date might be visible
427 (let ((date (calendar-gregorian-from-absolute 427 (let ((date (calendar-gregorian-from-absolute
428 (calendar-absolute-from-bahai 428 (calendar-absolute-from-bahai
429 (list month day y))))) 429 (list month day y)))))
430 (if (calendar-date-is-visible-p date) 430 (if (calendar-date-is-visible-p date)
431 (mark-visible-calendar-date date))))))) 431 (mark-visible-calendar-date date)))))))
458 (mark-visible-calendar-date 458 (mark-visible-calendar-date
459 (calendar-gregorian-from-absolute date))))))))) 459 (calendar-gregorian-from-absolute date)))))))))
460 460
461 (defun diary-insert-bahai-entry (arg) 461 (defun diary-insert-bahai-entry (arg)
462 "Insert a diary entry. 462 "Insert a diary entry.
463 For the Baha'i date corresponding to the date indicated by point. 463 For the Bahá'í date corresponding to the date indicated by point.
464 Prefix arg will make the entry nonmarking." 464 Prefix arg will make the entry nonmarking."
465 (interactive "P") 465 (interactive "P")
466 (let* ((calendar-month-name-array calendar-bahai-month-name-array)) 466 (let* ((calendar-month-name-array calendar-bahai-month-name-array))
467 (make-diary-entry 467 (make-diary-entry
468 (concat 468 (concat
474 nil t)) 474 nil t))
475 arg))) 475 arg)))
476 476
477 (defun diary-bahai-insert-monthly-entry (arg) 477 (defun diary-bahai-insert-monthly-entry (arg)
478 "Insert a monthly diary entry. 478 "Insert a monthly diary entry.
479 For the day of the Baha'i month corresponding to the date indicated by point. 479 For the day of the Bahá'í month corresponding to the date indicated by point.
480 Prefix arg will make the entry nonmarking." 480 Prefix arg will make the entry nonmarking."
481 (interactive "P") 481 (interactive "P")
482 (let* ((calendar-date-display-form 482 (let* ((calendar-date-display-form
483 (if european-calendar-style '(day " * ") '("* " day ))) 483 (if european-calendar-style '(day " * ") '("* " day )))
484 (calendar-month-name-array calendar-bahai-month-name-array)) 484 (calendar-month-name-array calendar-bahai-month-name-array))
491 (calendar-cursor-to-date t))))) 491 (calendar-cursor-to-date t)))))
492 arg))) 492 arg)))
493 493
494 (defun diary-bahai-insert-yearly-entry (arg) 494 (defun diary-bahai-insert-yearly-entry (arg)
495 "Insert an annual diary entry. 495 "Insert an annual diary entry.
496 For the day of the Baha'i year corresponding to the date indicated by point. 496 For the day of the Bahá'í year corresponding to the date indicated by point.
497 Prefix arg will make the entry nonmarking." 497 Prefix arg will make the entry nonmarking."
498 (interactive "P") 498 (interactive "P")
499 (let* ((calendar-date-display-form 499 (let* ((calendar-date-display-form
500 (if european-calendar-style 500 (if european-calendar-style
501 '(day " " monthname) 501 '(day " " monthname)