Commit | Line | Data |
---|---|---|
3afbc435 | 1 | ;;; cal-coptic.el --- calendar functions for the Coptic/Ethiopic calendars |
0808d911 | 2 | |
ba318903 | 3 | ;; Copyright (C) 1995, 1997, 2001-2014 Free Software Foundation, Inc. |
0808d911 ER |
4 | |
5 | ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> | |
dbfca9c4 | 6 | ;; Maintainer: Glenn Morris <rgm@gnu.org> |
0808d911 ER |
7 | ;; Keywords: calendar |
8 | ;; Human-Keywords: Coptic calendar, Ethiopic calendar, calendar, diary | |
bd78fa1d | 9 | ;; Package: calendar |
0808d911 ER |
10 | |
11 | ;; This file is part of GNU Emacs. | |
12 | ||
2ed66575 | 13 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
0808d911 | 14 | ;; it under the terms of the GNU General Public License as published by |
2ed66575 GM |
15 | ;; the Free Software Foundation, either version 3 of the License, or |
16 | ;; (at your option) any later version. | |
0808d911 ER |
17 | |
18 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | ;; GNU General Public License for more details. | |
22 | ||
23 | ;; You should have received a copy of the GNU General Public License | |
2ed66575 | 24 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
0808d911 ER |
25 | |
26 | ;;; Commentary: | |
27 | ||
b1c57079 | 28 | ;; See calendar.el. |
a96a5fca | 29 | |
0808d911 ER |
30 | ;;; Code: |
31 | ||
dad6b4ee | 32 | (require 'calendar) |
0808d911 | 33 | |
6fd6d1d8 GM |
34 | ;; Not constants because they get let-bound. |
35 | ||
990121a3 | 36 | (defvar calendar-coptic-month-name-array |
179bd1b3 | 37 | ["Tut" "Babah" "Hatur" "Kiyahk" "Tubah" "Amshir" "Baramhat" "Barmundah" |
ef473719 GM |
38 | "Bashans" "Baunah" "Abib" "Misra" "al-Nasi"] |
39 | "Array of the month names in the Coptic calendar.") | |
0808d911 | 40 | |
dad6b4ee | 41 | (eval-and-compile |
5c645a20 | 42 | (autoload 'calendar-julian-to-absolute "cal-julian")) |
dad6b4ee | 43 | |
990121a3 | 44 | (defvar calendar-coptic-epoch |
5c645a20 | 45 | (eval-when-compile (calendar-julian-to-absolute '(8 29 284))) |
cc7fff4f | 46 | "Absolute date of start of Coptic calendar = August 29, 284 AD (Julian).") |
0808d911 | 47 | |
990121a3 | 48 | (defvar calendar-coptic-name "Coptic" |
6fd6d1d8 | 49 | "Used in some message strings.") |
0808d911 | 50 | |
990121a3 | 51 | (defun calendar-coptic-leap-year-p (year) |
0808d911 ER |
52 | "True if YEAR is a leap year on the Coptic calendar." |
53 | (zerop (mod (1+ year) 4))) | |
54 | ||
990121a3 | 55 | (defun calendar-coptic-last-day-of-month (month year) |
0808d911 ER |
56 | "Return last day of MONTH, YEAR on the Coptic calendar. |
57 | The 13th month is not really a month, but the 5 (6 in leap years) day period of | |
d3bdb2a4 | 58 | Nisi (Kebus) at the end of the year." |
0808d911 ER |
59 | (if (< month 13) |
60 | 30 | |
990121a3 | 61 | (if (calendar-coptic-leap-year-p year) |
0808d911 ER |
62 | 6 |
63 | 5))) | |
64 | ||
990121a3 | 65 | (defun calendar-coptic-to-absolute (date) |
0808d911 ER |
66 | "Compute absolute date from Coptic date DATE. |
67 | The absolute date is the number of days elapsed since the (imaginary) | |
68 | Gregorian date Sunday, December 31, 1 BC." | |
e803eab7 GM |
69 | (let ((month (calendar-extract-month date)) |
70 | (day (calendar-extract-day date)) | |
71 | (year (calendar-extract-year date))) | |
990121a3 | 72 | (+ (1- calendar-coptic-epoch) ; days before start of calendar |
ef473719 GM |
73 | (* 365 (1- year)) ; days in prior years |
74 | (/ year 4) ; leap days in prior years | |
75 | (* 30 (1- month)) ; days in prior months this year | |
76 | day))) ; days so far this month | |
0808d911 | 77 | |
990121a3 GM |
78 | (define-obsolete-function-alias 'calendar-absolute-from-coptic |
79 | 'calendar-coptic-to-absolute "23.1") | |
80 | ||
0808d911 ER |
81 | (defun calendar-coptic-from-absolute (date) |
82 | "Compute the Coptic equivalent for absolute date DATE. | |
83 | The result is a list of the form (MONTH DAY YEAR). | |
84 | The absolute date is the number of days elapsed since the imaginary | |
85 | Gregorian date Sunday, December 31, 1 BC." | |
990121a3 | 86 | (if (< date calendar-coptic-epoch) |
d3bdb2a4 | 87 | (list 0 0 0) ; pre-Coptic date |
990121a3 | 88 | (let* ((approx (/ (- date calendar-coptic-epoch) |
ef473719 GM |
89 | 366)) ; approximation from below |
90 | (year ; search forward from the approximation | |
0808d911 ER |
91 | (+ approx |
92 | (calendar-sum y approx | |
990121a3 | 93 | (>= date (calendar-coptic-to-absolute |
ef473719 GM |
94 | (list 1 1 (1+ y)))) |
95 | 1))) | |
d3bdb2a4 | 96 | (month ; search forward from Tot |
0808d911 | 97 | (1+ (calendar-sum m 1 |
ef473719 | 98 | (> date |
990121a3 | 99 | (calendar-coptic-to-absolute |
ef473719 | 100 | (list m |
990121a3 | 101 | (calendar-coptic-last-day-of-month m |
ef473719 GM |
102 | year) |
103 | year))) | |
104 | 1))) | |
d3bdb2a4 | 105 | (day ; calculate the day by subtraction |
0808d911 | 106 | (- date |
990121a3 | 107 | (1- (calendar-coptic-to-absolute (list month 1 year)))))) |
ef473719 | 108 | (list month day year)))) |
0808d911 | 109 | |
1d0c7fdf | 110 | ;;;###cal-autoload |
0808d911 ER |
111 | (defun calendar-coptic-date-string (&optional date) |
112 | "String of Coptic date of Gregorian DATE. | |
113 | Returns the empty string if DATE is pre-Coptic calendar. | |
114 | Defaults to today's date if DATE is not given." | |
115 | (let* ((coptic-date (calendar-coptic-from-absolute | |
116 | (calendar-absolute-from-gregorian | |
117 | (or date (calendar-current-date))))) | |
e803eab7 GM |
118 | (y (calendar-extract-year coptic-date)) |
119 | (m (calendar-extract-month coptic-date))) | |
0808d911 ER |
120 | (if (< y 1) |
121 | "" | |
990121a3 | 122 | (let ((monthname (aref calendar-coptic-month-name-array (1- m))) |
d92bcf94 | 123 | (day (number-to-string (calendar-extract-day coptic-date))) |
0808d911 | 124 | (dayname nil) |
d92bcf94 GM |
125 | (month (number-to-string m)) |
126 | (year (number-to-string y))) | |
0808d911 ER |
127 | (mapconcat 'eval calendar-date-display-form ""))))) |
128 | ||
1d0c7fdf | 129 | ;;;###cal-autoload |
990121a3 | 130 | (defun calendar-coptic-print-date () |
0808d911 ER |
131 | "Show the Coptic calendar equivalent of the selected date." |
132 | (interactive) | |
133 | (let ((f (calendar-coptic-date-string (calendar-cursor-to-date t)))) | |
134 | (if (string-equal f "") | |
990121a3 GM |
135 | (message "Date is pre-%s calendar" calendar-coptic-name) |
136 | (message "%s date: %s" calendar-coptic-name f)))) | |
137 | ||
138 | (define-obsolete-function-alias 'calendar-print-coptic-date | |
139 | 'calendar-coptic-print-date "23.1") | |
0808d911 | 140 | |
af795681 GM |
141 | (defun calendar-coptic-read-date () |
142 | "Interactively read the arguments for a Coptic date command. | |
143 | Reads a year, month, and day." | |
0808d911 ER |
144 | (let* ((today (calendar-current-date)) |
145 | (year (calendar-read | |
990121a3 | 146 | (format "%s calendar year (>0): " calendar-coptic-name) |
2c47d99f | 147 | (lambda (x) (> x 0)) |
d92bcf94 | 148 | (number-to-string |
e803eab7 | 149 | (calendar-extract-year |
0808d911 ER |
150 | (calendar-coptic-from-absolute |
151 | (calendar-absolute-from-gregorian today)))))) | |
152 | (completion-ignore-case t) | |
3be2dc28 | 153 | (month (cdr (assoc-string |
50830fad | 154 | (completing-read |
990121a3 | 155 | (format "%s calendar month name: " calendar-coptic-name) |
50830fad | 156 | (mapcar 'list |
990121a3 | 157 | (append calendar-coptic-month-name-array nil)) |
50830fad | 158 | nil t) |
990121a3 | 159 | (calendar-make-alist calendar-coptic-month-name-array |
3be2dc28 | 160 | 1) t))) |
990121a3 | 161 | (last (calendar-coptic-last-day-of-month month year)) |
0808d911 | 162 | (day (calendar-read |
990121a3 | 163 | (format "%s calendar day (1-%d): " calendar-coptic-name last) |
2c47d99f | 164 | (lambda (x) (and (< 0 x) (<= x last)))))) |
0808d911 ER |
165 | (list (list month day year)))) |
166 | ||
990121a3 GM |
167 | (define-obsolete-function-alias 'coptic-prompt-for-date |
168 | 'calendar-coptic-read-date "23.1") | |
af795681 | 169 | |
ef473719 | 170 | ;;;###cal-autoload |
990121a3 | 171 | (defun calendar-coptic-goto-date (date &optional noecho) |
ef473719 GM |
172 | "Move cursor to Coptic date DATE. |
173 | Echo Coptic date unless NOECHO is t." | |
af795681 | 174 | (interactive (calendar-coptic-read-date)) |
ef473719 | 175 | (calendar-goto-date (calendar-gregorian-from-absolute |
990121a3 GM |
176 | (calendar-coptic-to-absolute date))) |
177 | (or noecho (calendar-coptic-print-date))) | |
178 | ||
179 | (define-obsolete-function-alias 'calendar-goto-coptic-date | |
180 | 'calendar-coptic-goto-date "23.1") | |
ef473719 | 181 | |
4692b6a0 GM |
182 | (defvar date) |
183 | ||
8c34d83e | 184 | ;; To be called from diary-list-sexp-entries, where DATE is bound. |
1d0c7fdf | 185 | ;;;###diary-autoload |
0808d911 ER |
186 | (defun diary-coptic-date () |
187 | "Coptic calendar equivalent of date diary entry." | |
7801463c | 188 | (let ((f (calendar-coptic-date-string date))) |
0808d911 | 189 | (if (string-equal f "") |
990121a3 GM |
190 | (format "Date is pre-%s calendar" calendar-coptic-name) |
191 | (format "%s date: %s" calendar-coptic-name f)))) | |
0808d911 | 192 | |
990121a3 | 193 | (defconst calendar-ethiopic-month-name-array |
179bd1b3 | 194 | ["Maskaram" "Teqemt" "Khedar" "Takhsas" "Ter" "Yakatit" "Magabit" "Miyazya" |
ef473719 GM |
195 | "Genbot" "Sane" "Hamle" "Nahas" "Paguem"] |
196 | "Array of the month names in the Ethiopic calendar.") | |
0808d911 | 197 | |
990121a3 | 198 | (defconst calendar-ethiopic-epoch 2796 |
d5824b35 | 199 | "Absolute date of start of Ethiopic calendar = August 29, 8 C.E. (Julian).") |
0808d911 | 200 | |
990121a3 | 201 | (defconst calendar-ethiopic-name "Ethiopic" |
ef473719 | 202 | "Used in some message strings.") |
0808d911 | 203 | |
990121a3 | 204 | (defun calendar-ethiopic-to-absolute (date) |
0808d911 ER |
205 | "Compute absolute date from Ethiopic date DATE. |
206 | The absolute date is the number of days elapsed since the (imaginary) | |
207 | Gregorian date Sunday, December 31, 1 BC." | |
990121a3 GM |
208 | (let ((calendar-coptic-epoch calendar-ethiopic-epoch)) |
209 | (calendar-coptic-to-absolute date))) | |
210 | ||
211 | (define-obsolete-function-alias 'calendar-absolute-from-ethiopic | |
212 | 'calendar-ethiopic-to-absolute "23.1") | |
0808d911 ER |
213 | |
214 | (defun calendar-ethiopic-from-absolute (date) | |
215 | "Compute the Ethiopic equivalent for absolute date DATE. | |
216 | The result is a list of the form (MONTH DAY YEAR). | |
217 | The absolute date is the number of days elapsed since the imaginary | |
218 | Gregorian date Sunday, December 31, 1 BC." | |
990121a3 | 219 | (let ((calendar-coptic-epoch calendar-ethiopic-epoch)) |
0808d911 ER |
220 | (calendar-coptic-from-absolute date))) |
221 | ||
1d0c7fdf | 222 | ;;;###cal-autoload |
0808d911 ER |
223 | (defun calendar-ethiopic-date-string (&optional date) |
224 | "String of Ethiopic date of Gregorian DATE. | |
225 | Returns the empty string if DATE is pre-Ethiopic calendar. | |
226 | Defaults to today's date if DATE is not given." | |
990121a3 GM |
227 | (let ((calendar-coptic-epoch calendar-ethiopic-epoch) |
228 | (calendar-coptic-name calendar-ethiopic-name) | |
229 | (calendar-coptic-month-name-array calendar-ethiopic-month-name-array)) | |
0808d911 ER |
230 | (calendar-coptic-date-string date))) |
231 | ||
1d0c7fdf | 232 | ;;;###cal-autoload |
990121a3 | 233 | (defun calendar-ethiopic-print-date () |
0808d911 ER |
234 | "Show the Ethiopic calendar equivalent of the selected date." |
235 | (interactive) | |
990121a3 GM |
236 | (let ((calendar-coptic-epoch calendar-ethiopic-epoch) |
237 | (calendar-coptic-name calendar-ethiopic-name) | |
238 | (calendar-coptic-month-name-array calendar-ethiopic-month-name-array)) | |
239 | (call-interactively 'calendar-coptic-print-date))) | |
240 | ||
241 | (define-obsolete-function-alias 'calendar-print-ethiopic-date | |
242 | 'calendar-ethiopic-print-date "23.1") | |
0808d911 | 243 | |
1d0c7fdf | 244 | ;;;###cal-autoload |
990121a3 | 245 | (defun calendar-ethiopic-goto-date (date &optional noecho) |
0808d911 ER |
246 | "Move cursor to Ethiopic date DATE. |
247 | Echo Ethiopic date unless NOECHO is t." | |
248 | (interactive | |
990121a3 GM |
249 | (let ((calendar-coptic-epoch calendar-ethiopic-epoch) |
250 | (calendar-coptic-name calendar-ethiopic-name) | |
251 | (calendar-coptic-month-name-array calendar-ethiopic-month-name-array)) | |
af795681 | 252 | (calendar-coptic-read-date))) |
0808d911 | 253 | (calendar-goto-date (calendar-gregorian-from-absolute |
990121a3 GM |
254 | (calendar-ethiopic-to-absolute date))) |
255 | (or noecho (calendar-ethiopic-print-date))) | |
256 | ||
257 | (define-obsolete-function-alias 'calendar-goto-ethiopic-date | |
258 | 'calendar-ethiopic-goto-date "23.1") | |
0808d911 | 259 | |
8c34d83e | 260 | ;; To be called from diary-list-sexp-entries, where DATE is bound. |
1d0c7fdf | 261 | ;;;###diary-autoload |
0808d911 ER |
262 | (defun diary-ethiopic-date () |
263 | "Ethiopic calendar equivalent of date diary entry." | |
990121a3 GM |
264 | (let ((calendar-coptic-epoch calendar-ethiopic-epoch) |
265 | (calendar-coptic-name calendar-ethiopic-name) | |
266 | (calendar-coptic-month-name-array calendar-ethiopic-month-name-array)) | |
0808d911 ER |
267 | (diary-coptic-date))) |
268 | ||
269 | (provide 'cal-coptic) | |
270 | ||
271 | ;;; cal-coptic.el ends here |