diff options
| author | Glenn Morris | 2008-08-10 20:06:08 +0000 |
|---|---|---|
| committer | Glenn Morris | 2008-08-10 20:06:08 +0000 |
| commit | 411518022540534f3eb83cdf457ec6aebced9a2f (patch) | |
| tree | cbc74147e45f82a2350c4e1eca0cb803184f0f43 | |
| parent | bf9b4e4e7f6697c3ce3f4d7fd88982e609879a25 (diff) | |
| download | emacs-411518022540534f3eb83cdf457ec6aebced9a2f.tar.gz emacs-411518022540534f3eb83cdf457ec6aebced9a2f.zip | |
(holiday-bahai): Use an algorithm actually relevant to this calendar
system (sync from trunk 2008-03-31).
(calendar-bahai-date-string): Avoid an error for pre-Bahai dates (sync
from trunk 2008-03-31).
(calendar-print-bahai-date): Handle pre-Bahai dates (sync from trunk
2008-03-20).
(calendar-absolute-from-bahai): Fix the leap-year case (sync from trunk
2008-03-20).
| -rw-r--r-- | lisp/calendar/cal-bahai.el | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/lisp/calendar/cal-bahai.el b/lisp/calendar/cal-bahai.el index 9e1c411afe2..08e9d5a7547 100644 --- a/lisp/calendar/cal-bahai.el +++ b/lisp/calendar/cal-bahai.el | |||
| @@ -94,7 +94,9 @@ Gregorian date Sunday, December 31, 1 BC." | |||
| 94 | (* 365 (1- year)) ; Days in prior years. | 94 | (* 365 (1- year)) ; Days in prior years. |
| 95 | leap-days | 95 | leap-days |
| 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) |
| 98 | (if (bahai-calendar-leap-year-p year) 5 4) | ||
| 99 | 0) | ||
| 98 | day))) ; Days so far this month. | 100 | day))) ; Days so far this month. |
| 99 | 101 | ||
| 100 | (defun calendar-bahai-from-absolute (date) | 102 | (defun calendar-bahai-from-absolute (date) |
| @@ -127,27 +129,31 @@ Defaults to today's date if DATE is not given." | |||
| 127 | (y (extract-calendar-year bahai-date)) | 129 | (y (extract-calendar-year bahai-date)) |
| 128 | (m (extract-calendar-month bahai-date)) | 130 | (m (extract-calendar-month bahai-date)) |
| 129 | (d (extract-calendar-day bahai-date))) | 131 | (d (extract-calendar-day bahai-date))) |
| 130 | (let ((monthname | 132 | (if (< y 1) |
| 131 | (if (and (= m 19) | 133 | "" ; pre-Bahai |
| 132 | (<= d 0)) | 134 | (let ((monthname |
| 133 | "Ayyam-i-Ha" | 135 | (if (and (= m 19) |
| 134 | (aref bahai-calendar-month-name-array (1- m)))) | 136 | (<= d 0)) |
| 135 | (day (int-to-string | 137 | "Ayyam-i-Ha" |
| 136 | (if (<= d 0) | 138 | (aref bahai-calendar-month-name-array (1- m)))) |
| 137 | (if (bahai-calendar-leap-year-p y) | 139 | (day (int-to-string |
| 138 | (+ d 5) | 140 | (if (<= d 0) |
| 139 | (+ d 4)) | 141 | (if (bahai-calendar-leap-year-p y) |
| 140 | d))) | 142 | (+ d 5) |
| 141 | (dayname nil) | 143 | (+ d 4)) |
| 142 | (month (int-to-string m)) | 144 | d))) |
| 143 | (year (int-to-string y))) | 145 | (dayname nil) |
| 144 | (mapconcat 'eval calendar-date-display-form "")))) | 146 | (month (int-to-string m)) |
| 147 | (year (int-to-string y))) | ||
| 148 | (mapconcat 'eval calendar-date-display-form ""))))) | ||
| 145 | 149 | ||
| 146 | (defun calendar-print-bahai-date () | 150 | (defun calendar-print-bahai-date () |
| 147 | "Show the Baha'i calendar equivalent of the selected date." | 151 | "Show the Baha'i calendar equivalent of the selected date." |
| 148 | (interactive) | 152 | (interactive) |
| 149 | (message "Baha'i date: %s" | 153 | (let ((s (calendar-bahai-date-string (calendar-cursor-to-date t)))) |
| 150 | (calendar-bahai-date-string (calendar-cursor-to-date t)))) | 154 | (if (string-equal s "") |
| 155 | (message "Date is pre-Baha'i") | ||
| 156 | (message "Baha'i date: %s" s)))) | ||
| 151 | 157 | ||
| 152 | (defun calendar-goto-bahai-date (date &optional noecho) | 158 | (defun calendar-goto-bahai-date (date &optional noecho) |
| 153 | "Move cursor to Baha'i date DATE. | 159 | "Move cursor to Baha'i date DATE. |
| @@ -186,23 +192,33 @@ Echo Baha'i date unless NOECHO is t." | |||
| 186 | 192 | ||
| 187 | (defun holiday-bahai (month day string) | 193 | (defun holiday-bahai (month day string) |
| 188 | "Holiday on MONTH, DAY (Baha'i) called STRING. | 194 | "Holiday on MONTH, DAY (Baha'i) called STRING. |
| 189 | If MONTH, DAY (Baha'i) is visible, the value returned is corresponding | 195 | If MONTH, DAY (Baha'i) is visible in the current calendar window, |
| 190 | Gregorian date in the form of the list (((month day year) STRING)). Returns | 196 | returns the corresponding Gregorian date in the form of the |
| 191 | nil if it is not visible in the current calendar window." | 197 | list (((month day year) STRING)). Otherwise, returns nil." |
| 198 | ;; Since the calendar window shows 3 months at a time, there are | ||
| 199 | ;; approx +/- 45 days either side of the central month. | ||
| 200 | ;; Since the Bahai months have 19 days, this means up to +/- 3 months. | ||
| 192 | (let* ((bahai-date (calendar-bahai-from-absolute | 201 | (let* ((bahai-date (calendar-bahai-from-absolute |
| 193 | (calendar-absolute-from-gregorian | 202 | (calendar-absolute-from-gregorian |
| 194 | (list displayed-month 15 displayed-year)))) | 203 | (list displayed-month 15 displayed-year)))) |
| 195 | (m (extract-calendar-month bahai-date)) | 204 | (m (extract-calendar-month bahai-date)) |
| 196 | (y (extract-calendar-year bahai-date)) | 205 | (y (extract-calendar-year bahai-date)) |
| 197 | (date)) | 206 | date) |
| 198 | (if (< m 1) | 207 | (unless (< m 1) ; Baha'i calendar doesn't apply |
| 199 | nil ;; Baha'i calendar doesn't apply. | 208 | ;; Cf holiday-fixed, holiday-islamic. |
| 200 | (increment-calendar-month m y (- 10 month)) | 209 | ;; With a +- 3 month calendar window, and 19 months per year, |
| 201 | (if (> m 7) ;; Baha'i date might be visible | 210 | ;; month 16 is special. When m16 is central is when the |
| 202 | (let ((date (calendar-gregorian-from-absolute | 211 | ;; end-of-year first appears. When m1 is central, m16 is no |
| 203 | (calendar-absolute-from-bahai (list month day y))))) | 212 | ;; longer visible. Hence we can do a one-sided test to see if |
| 204 | (if (calendar-date-is-visible-p date) | 213 | ;; m16 is visible. m16 is visible when the central month >= 13. |
| 205 | (list (list date string)))))))) | 214 | ;; To see if other months are visible we can shift the range |
| 215 | ;; accordingly. | ||
| 216 | (calendar-increment-month m y (- 16 month) 19) | ||
| 217 | (and (> m 12) ; Baha'i date might be visible | ||
| 218 | (calendar-date-is-visible-p | ||
| 219 | (setq date (calendar-gregorian-from-absolute | ||
| 220 | (calendar-absolute-from-bahai (list month day y))))) | ||
| 221 | (list (list date string)))))) | ||
| 206 | 222 | ||
| 207 | (defun list-bahai-diary-entries () | 223 | (defun list-bahai-diary-entries () |
| 208 | "Add any Baha'i date entries from the diary file to `diary-entries-list'. | 224 | "Add any Baha'i date entries from the diary file to `diary-entries-list'. |