Mercurial > emacs
annotate lisp/calendar/cal-coptic.el @ 93637:60b7d8c48c07
Update for cal-julian name changes.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Fri, 04 Apr 2008 07:05:44 +0000 |
parents | 022b9c621dbe |
children | bab9812286c1 |
rev | line source |
---|---|
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
24190
diff
changeset
|
1 ;;; cal-coptic.el --- calendar functions for the Coptic/Ethiopic calendars |
13053 | 2 |
92966
446f7aee7bf1
(coptic-calendar-epoch): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
92897
diff
changeset
|
3 ;; Copyright (C) 1995, 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
446f7aee7bf1
(coptic-calendar-epoch): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
92897
diff
changeset
|
4 ;; 2008 Free Software Foundation, Inc. |
13053 | 5 |
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> | |
67465
a55ee709ec8d
Update copyright pending Emacs 22.
Glenn Morris <rgm@gnu.org>
parents:
65145
diff
changeset
|
7 ;; Maintainer: Glenn Morris <rgm@gnu.org> |
13053 | 8 ;; Keywords: calendar |
9 ;; Human-Keywords: Coptic calendar, Ethiopic calendar, calendar, diary | |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14 ;; it under the terms of the GNU General Public License as published by | |
78216
93e11478c954
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
15 ;; the Free Software Foundation; either version 3, or (at your option) |
13053 | 16 ;; any later version. |
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 | |
14169 | 24 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 ;; Boston, MA 02110-1301, USA. | |
13053 | 27 |
28 ;;; Commentary: | |
29 | |
93478
022b9c621dbe
(Commentary): Point to calendar.el.
Glenn Morris <rgm@gnu.org>
parents:
93221
diff
changeset
|
30 ;; See calendar.el. |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
20209
diff
changeset
|
31 |
13053 | 32 ;;; Code: |
33 | |
93221
546789da9d8f
Require calendar rather than cal-julian.
Glenn Morris <rgm@gnu.org>
parents:
93182
diff
changeset
|
34 (require 'calendar) |
65145
ac895e21e622
(date): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
35 |
92613
28583a8ab749
(coptic-name): Add doc string.
Glenn Morris <rgm@gnu.org>
parents:
92580
diff
changeset
|
36 ;; Not constants because they get let-bound. |
13053 | 37 |
38 (defvar coptic-calendar-month-name-array | |
14568
60730f9e6b80
Coorect Ethiopic epoch and some spelling errors.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14169
diff
changeset
|
39 ["Tut" "Babah" "Hatur" "Kiyahk" "Tubah" "Amshir" "Baramhat" "Barmundah" |
92897 | 40 "Bashans" "Baunah" "Abib" "Misra" "al-Nasi"] |
41 "Array of the month names in the Coptic calendar.") | |
13053 | 42 |
93221
546789da9d8f
Require calendar rather than cal-julian.
Glenn Morris <rgm@gnu.org>
parents:
93182
diff
changeset
|
43 (eval-and-compile |
546789da9d8f
Require calendar rather than cal-julian.
Glenn Morris <rgm@gnu.org>
parents:
93182
diff
changeset
|
44 (autoload 'calendar-absolute-from-julian "cal-julian")) |
546789da9d8f
Require calendar rather than cal-julian.
Glenn Morris <rgm@gnu.org>
parents:
93182
diff
changeset
|
45 |
546789da9d8f
Require calendar rather than cal-julian.
Glenn Morris <rgm@gnu.org>
parents:
93182
diff
changeset
|
46 (defvar coptic-calendar-epoch |
546789da9d8f
Require calendar rather than cal-julian.
Glenn Morris <rgm@gnu.org>
parents:
93182
diff
changeset
|
47 (eval-when-compile (calendar-absolute-from-julian '(8 29 284))) |
92966
446f7aee7bf1
(coptic-calendar-epoch): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
92897
diff
changeset
|
48 "Absolute date of start of Coptic calendar = August 29, 284 AD (Julian).") |
13053 | 49 |
92613
28583a8ab749
(coptic-name): Add doc string.
Glenn Morris <rgm@gnu.org>
parents:
92580
diff
changeset
|
50 (defvar coptic-name "Coptic" |
28583a8ab749
(coptic-name): Add doc string.
Glenn Morris <rgm@gnu.org>
parents:
92580
diff
changeset
|
51 "Used in some message strings.") |
13053 | 52 |
53 (defun coptic-calendar-leap-year-p (year) | |
54 "True if YEAR is a leap year on the Coptic calendar." | |
55 (zerop (mod (1+ year) 4))) | |
56 | |
57 (defun coptic-calendar-last-day-of-month (month year) | |
58 "Return last day of MONTH, YEAR on the Coptic calendar. | |
59 The 13th month is not really a month, but the 5 (6 in leap years) day period of | |
92627 | 60 Nisi (Kebus) at the end of the year." |
13053 | 61 (if (< month 13) |
62 30 | |
63 (if (coptic-calendar-leap-year-p year) | |
64 6 | |
65 5))) | |
66 | |
67 (defun calendar-absolute-from-coptic (date) | |
68 "Compute absolute date from Coptic date DATE. | |
69 The absolute date is the number of days elapsed since the (imaginary) | |
70 Gregorian date Sunday, December 31, 1 BC." | |
71 (let ((month (extract-calendar-month date)) | |
72 (day (extract-calendar-day date)) | |
73 (year (extract-calendar-year date))) | |
92897 | 74 (+ (1- coptic-calendar-epoch) ; days before start of calendar |
75 (* 365 (1- year)) ; days in prior years | |
76 (/ year 4) ; leap days in prior years | |
77 (* 30 (1- month)) ; days in prior months this year | |
78 day))) ; days so far this month | |
13053 | 79 |
80 (defun calendar-coptic-from-absolute (date) | |
81 "Compute the Coptic equivalent for absolute date DATE. | |
82 The result is a list of the form (MONTH DAY YEAR). | |
83 The absolute date is the number of days elapsed since the imaginary | |
84 Gregorian date Sunday, December 31, 1 BC." | |
85 (if (< date coptic-calendar-epoch) | |
92627 | 86 (list 0 0 0) ; pre-Coptic date |
13053 | 87 (let* ((approx (/ (- date coptic-calendar-epoch) |
92897 | 88 366)) ; approximation from below |
89 (year ; search forward from the approximation | |
13053 | 90 (+ approx |
91 (calendar-sum y approx | |
92897 | 92 (>= date (calendar-absolute-from-coptic |
93 (list 1 1 (1+ y)))) | |
94 1))) | |
92627 | 95 (month ; search forward from Tot |
13053 | 96 (1+ (calendar-sum m 1 |
92897 | 97 (> date |
98 (calendar-absolute-from-coptic | |
99 (list m | |
100 (coptic-calendar-last-day-of-month m | |
101 year) | |
102 year))) | |
103 1))) | |
92627 | 104 (day ; calculate the day by subtraction |
13053 | 105 (- date |
106 (1- (calendar-absolute-from-coptic (list month 1 year)))))) | |
92897 | 107 (list month day year)))) |
13053 | 108 |
92828
5d415a63a344
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92627
diff
changeset
|
109 ;;;###cal-autoload |
13053 | 110 (defun calendar-coptic-date-string (&optional date) |
111 "String of Coptic date of Gregorian DATE. | |
112 Returns the empty string if DATE is pre-Coptic calendar. | |
113 Defaults to today's date if DATE is not given." | |
114 (let* ((coptic-date (calendar-coptic-from-absolute | |
115 (calendar-absolute-from-gregorian | |
116 (or date (calendar-current-date))))) | |
117 (y (extract-calendar-year coptic-date)) | |
118 (m (extract-calendar-month coptic-date))) | |
119 (if (< y 1) | |
120 "" | |
121 (let ((monthname (aref coptic-calendar-month-name-array (1- m))) | |
122 (day (int-to-string (extract-calendar-day coptic-date))) | |
123 (dayname nil) | |
124 (month (int-to-string m)) | |
125 (year (int-to-string y))) | |
126 (mapconcat 'eval calendar-date-display-form ""))))) | |
127 | |
92828
5d415a63a344
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92627
diff
changeset
|
128 ;;;###cal-autoload |
13053 | 129 (defun calendar-print-coptic-date () |
130 "Show the Coptic calendar equivalent of the selected date." | |
131 (interactive) | |
132 (let ((f (calendar-coptic-date-string (calendar-cursor-to-date t)))) | |
133 (if (string-equal f "") | |
134 (message "Date is pre-%s calendar" coptic-name) | |
17571
e4c551837753
(calendar-print-coptic-date): Label Coptic/Ethiopic date in echo area.
Richard M. Stallman <rms@gnu.org>
parents:
17383
diff
changeset
|
135 (message "%s date: %s" coptic-name f)))) |
13053 | 136 |
93182
6011e8a7280f
(calendar-coptic-read-date): New name for coptic-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents:
92966
diff
changeset
|
137 (defun calendar-coptic-read-date () |
6011e8a7280f
(calendar-coptic-read-date): New name for coptic-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents:
92966
diff
changeset
|
138 "Interactively read the arguments for a Coptic date command. |
6011e8a7280f
(calendar-coptic-read-date): New name for coptic-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents:
92966
diff
changeset
|
139 Reads a year, month, and day." |
13053 | 140 (let* ((today (calendar-current-date)) |
141 (year (calendar-read | |
142 (format "%s calendar year (>0): " coptic-name) | |
92580
2a9b05a547d4
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
143 (lambda (x) (> x 0)) |
13053 | 144 (int-to-string |
145 (extract-calendar-year | |
146 (calendar-coptic-from-absolute | |
147 (calendar-absolute-from-gregorian today)))))) | |
148 (completion-ignore-case t) | |
54072
7cd960d120ba
(coptic-prompt-for-date): Use assoc-string instead of assoc-ignore-case.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
149 (month (cdr (assoc-string |
24190
77853cf5a2e5
(coptic-prompt-for-date): Use assoc-ignore-case and do not capitalize
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
150 (completing-read |
77853cf5a2e5
(coptic-prompt-for-date): Use assoc-ignore-case and do not capitalize
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
151 (format "%s calendar month name: " coptic-name) |
77853cf5a2e5
(coptic-prompt-for-date): Use assoc-ignore-case and do not capitalize
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
152 (mapcar 'list |
77853cf5a2e5
(coptic-prompt-for-date): Use assoc-ignore-case and do not capitalize
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
153 (append coptic-calendar-month-name-array nil)) |
77853cf5a2e5
(coptic-prompt-for-date): Use assoc-ignore-case and do not capitalize
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
154 nil t) |
13053 | 155 (calendar-make-alist coptic-calendar-month-name-array |
54072
7cd960d120ba
(coptic-prompt-for-date): Use assoc-string instead of assoc-ignore-case.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
156 1) t))) |
13053 | 157 (last (coptic-calendar-last-day-of-month month year)) |
158 (day (calendar-read | |
159 (format "%s calendar day (1-%d): " coptic-name last) | |
92580
2a9b05a547d4
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
160 (lambda (x) (and (< 0 x) (<= x last)))))) |
13053 | 161 (list (list month day year)))) |
162 | |
93182
6011e8a7280f
(calendar-coptic-read-date): New name for coptic-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents:
92966
diff
changeset
|
163 (define-obsolete-function-alias |
6011e8a7280f
(calendar-coptic-read-date): New name for coptic-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents:
92966
diff
changeset
|
164 'coptic-prompt-for-date 'calendar-coptic-read-date "23.1") |
6011e8a7280f
(calendar-coptic-read-date): New name for coptic-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents:
92966
diff
changeset
|
165 |
92897 | 166 ;;;###cal-autoload |
167 (defun calendar-goto-coptic-date (date &optional noecho) | |
168 "Move cursor to Coptic date DATE. | |
169 Echo Coptic date unless NOECHO is t." | |
93182
6011e8a7280f
(calendar-coptic-read-date): New name for coptic-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents:
92966
diff
changeset
|
170 (interactive (calendar-coptic-read-date)) |
92897 | 171 (calendar-goto-date (calendar-gregorian-from-absolute |
172 (calendar-absolute-from-coptic date))) | |
173 (or noecho (calendar-print-coptic-date))) | |
174 | |
92622 | 175 (defvar date) |
176 | |
177 ;; To be called from list-sexp-diary-entries, where DATE is bound. | |
92828
5d415a63a344
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92627
diff
changeset
|
178 ;;;###diary-autoload |
13053 | 179 (defun diary-coptic-date () |
180 "Coptic calendar equivalent of date diary entry." | |
17383
dade44f8a6b0
(diary-coptic-date): Use `date'.
Richard M. Stallman <rms@gnu.org>
parents:
14568
diff
changeset
|
181 (let ((f (calendar-coptic-date-string date))) |
13053 | 182 (if (string-equal f "") |
183 (format "Date is pre-%s calendar" coptic-name) | |
17383
dade44f8a6b0
(diary-coptic-date): Use `date'.
Richard M. Stallman <rms@gnu.org>
parents:
14568
diff
changeset
|
184 (format "%s date: %s" coptic-name f)))) |
13053 | 185 |
186 (defconst ethiopic-calendar-month-name-array | |
14568
60730f9e6b80
Coorect Ethiopic epoch and some spelling errors.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14169
diff
changeset
|
187 ["Maskaram" "Teqemt" "Khedar" "Takhsas" "Ter" "Yakatit" "Magabit" "Miyazya" |
92897 | 188 "Genbot" "Sane" "Hamle" "Nahas" "Paguem"] |
189 "Array of the month names in the Ethiopic calendar.") | |
13053 | 190 |
20209
fd00ceeb06c6
(ethiopic-calendar-epoch): Correct to 8 CE.
Karl Heuer <kwzh@gnu.org>
parents:
17571
diff
changeset
|
191 (defconst ethiopic-calendar-epoch 2796 |
fd00ceeb06c6
(ethiopic-calendar-epoch): Correct to 8 CE.
Karl Heuer <kwzh@gnu.org>
parents:
17571
diff
changeset
|
192 "Absolute date of start of Ethiopic calendar = August 29, 8 C.E. (Julian).") |
13053 | 193 |
92897 | 194 (defconst ethiopic-name "Ethiopic" |
195 "Used in some message strings.") | |
13053 | 196 |
197 (defun calendar-absolute-from-ethiopic (date) | |
198 "Compute absolute date from Ethiopic date DATE. | |
199 The absolute date is the number of days elapsed since the (imaginary) | |
200 Gregorian date Sunday, December 31, 1 BC." | |
201 (let ((coptic-calendar-epoch ethiopic-calendar-epoch)) | |
202 (calendar-absolute-from-coptic date))) | |
203 | |
204 (defun calendar-ethiopic-from-absolute (date) | |
205 "Compute the Ethiopic equivalent for absolute date DATE. | |
206 The result is a list of the form (MONTH DAY YEAR). | |
207 The absolute date is the number of days elapsed since the imaginary | |
208 Gregorian date Sunday, December 31, 1 BC." | |
209 (let ((coptic-calendar-epoch ethiopic-calendar-epoch)) | |
210 (calendar-coptic-from-absolute date))) | |
211 | |
92828
5d415a63a344
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92627
diff
changeset
|
212 ;;;###cal-autoload |
13053 | 213 (defun calendar-ethiopic-date-string (&optional date) |
214 "String of Ethiopic date of Gregorian DATE. | |
215 Returns the empty string if DATE is pre-Ethiopic calendar. | |
216 Defaults to today's date if DATE is not given." | |
217 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
218 (coptic-name ethiopic-name) | |
219 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
220 (calendar-coptic-date-string date))) | |
221 | |
92828
5d415a63a344
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92627
diff
changeset
|
222 ;;;###cal-autoload |
13053 | 223 (defun calendar-print-ethiopic-date () |
224 "Show the Ethiopic calendar equivalent of the selected date." | |
225 (interactive) | |
226 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
227 (coptic-name ethiopic-name) | |
228 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
229 (call-interactively 'calendar-print-coptic-date))) | |
230 | |
92828
5d415a63a344
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92627
diff
changeset
|
231 ;;;###cal-autoload |
13053 | 232 (defun calendar-goto-ethiopic-date (date &optional noecho) |
233 "Move cursor to Ethiopic date DATE. | |
234 Echo Ethiopic date unless NOECHO is t." | |
235 (interactive | |
236 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
237 (coptic-name ethiopic-name) | |
238 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
93182
6011e8a7280f
(calendar-coptic-read-date): New name for coptic-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents:
92966
diff
changeset
|
239 (calendar-coptic-read-date))) |
13053 | 240 (calendar-goto-date (calendar-gregorian-from-absolute |
241 (calendar-absolute-from-ethiopic date))) | |
242 (or noecho (calendar-print-ethiopic-date))) | |
243 | |
92613
28583a8ab749
(coptic-name): Add doc string.
Glenn Morris <rgm@gnu.org>
parents:
92580
diff
changeset
|
244 ;; To be called from list-sexp-diary-entries, where DATE is bound. |
92828
5d415a63a344
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92627
diff
changeset
|
245 ;;;###diary-autoload |
13053 | 246 (defun diary-ethiopic-date () |
247 "Ethiopic calendar equivalent of date diary entry." | |
248 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
249 (coptic-name ethiopic-name) | |
250 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
251 (diary-coptic-date))) | |
252 | |
253 (provide 'cal-coptic) | |
254 | |
92580
2a9b05a547d4
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
255 ;; arch-tag: 72d49161-25df-4072-9312-b182cdca7627 |
13053 | 256 ;;; cal-coptic.el ends here |