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