Mercurial > emacs
annotate lisp/calendar/cal-coptic.el @ 66413:4e56b3fda002
* menu-bar.el (menu-bar-help-menu): Rename "psychiatrist", in line
with 2005-10-23 change to doctor.el.
* finder.el (finder-mode-map): Add follow-link binding.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Mon, 24 Oct 2005 22:13:08 +0000 |
parents | ac895e21e622 |
children | a55ee709ec8d a3716f7538f2 |
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 |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
20209
diff
changeset
|
3 ;; Copyright (C) 1995, 1997 Free Software Foundation, Inc. |
13053 | 4 |
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> | |
6 ;; Keywords: calendar | |
7 ;; Human-Keywords: Coptic calendar, Ethiopic calendar, calendar, diary | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
13053 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; This collection of functions implements the features of calendar.el and | |
29 ;; diary.el that deal with the Coptic and Ethiopic calendars. | |
30 | |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
20209
diff
changeset
|
31 ;; Technical details of all the calendrical calculations can be found in |
61148
7f7db25577d9
Update reference to "Calendrical Calculations" book; there's a new edition.
Paul Eggert <eggert@twinsun.com>
parents:
54072
diff
changeset
|
32 ;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold |
7f7db25577d9
Update reference to "Calendrical Calculations" book; there's a new edition.
Paul Eggert <eggert@twinsun.com>
parents:
54072
diff
changeset
|
33 ;; and Nachum Dershowitz, Cambridge University Press (2001). |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
20209
diff
changeset
|
34 |
13053 | 35 ;; Comments, corrections, and improvements should be sent to |
36 ;; Edward M. Reingold Department of Computer Science | |
37 ;; (217) 333-6733 University of Illinois at Urbana-Champaign | |
38 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue | |
39 ;; Urbana, Illinois 61801 | |
40 | |
41 ;;; Code: | |
42 | |
65145
ac895e21e622
(date): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
43 (defvar date) |
ac895e21e622
(date): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
44 |
13053 | 45 (require 'cal-julian) |
46 | |
47 (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
|
48 ["Tut" "Babah" "Hatur" "Kiyahk" "Tubah" "Amshir" "Baramhat" "Barmundah" |
60730f9e6b80
Coorect Ethiopic epoch and some spelling errors.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14169
diff
changeset
|
49 "Bashans" "Baunah" "Abib" "Misra" "al-Nasi"]) |
13053 | 50 |
51 (defvar coptic-calendar-epoch (calendar-absolute-from-julian '(8 29 284)) | |
52 "Absolute date of start of Coptic calendar = August 29, 284 A.D. (Julian).") | |
53 | |
52111
e6182946cacd
(coptic-name): defvar rather than defconst.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
54 (defvar coptic-name "Coptic") |
13053 | 55 |
56 (defun coptic-calendar-leap-year-p (year) | |
57 "True if YEAR is a leap year on the Coptic calendar." | |
58 (zerop (mod (1+ year) 4))) | |
59 | |
60 (defun coptic-calendar-last-day-of-month (month year) | |
61 "Return last day of MONTH, YEAR on the Coptic calendar. | |
62 The 13th month is not really a month, but the 5 (6 in leap years) day period of | |
63 Nisi (Kebus) at the end of the year." | |
64 (if (< month 13) | |
65 30 | |
66 (if (coptic-calendar-leap-year-p year) | |
67 6 | |
68 5))) | |
69 | |
70 (defun calendar-absolute-from-coptic (date) | |
71 "Compute absolute date from Coptic date DATE. | |
72 The absolute date is the number of days elapsed since the (imaginary) | |
73 Gregorian date Sunday, December 31, 1 BC." | |
74 (let ((month (extract-calendar-month date)) | |
75 (day (extract-calendar-day date)) | |
76 (year (extract-calendar-year date))) | |
77 (+ (1- coptic-calendar-epoch);; Days before start of calendar | |
78 (* 365 (1- year)) ;; Days in prior years | |
79 (/ year 4) ;; Leap days in prior years | |
80 (* 30 (1- month)) ;; Days in prior months this year | |
81 day))) ;; Days so far this month | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
82 |
13053 | 83 |
84 (defun calendar-coptic-from-absolute (date) | |
85 "Compute the Coptic equivalent for absolute date DATE. | |
86 The result is a list of the form (MONTH DAY YEAR). | |
87 The absolute date is the number of days elapsed since the imaginary | |
88 Gregorian date Sunday, December 31, 1 BC." | |
89 (if (< date coptic-calendar-epoch) | |
90 (list 0 0 0);; pre-Coptic date | |
91 (let* ((approx (/ (- date coptic-calendar-epoch) | |
92 366)) ;; Approximation from below. | |
93 (year ;; Search forward from the approximation. | |
94 (+ approx | |
95 (calendar-sum y approx | |
96 (>= date (calendar-absolute-from-coptic (list 1 1 (1+ y)))) | |
97 1))) | |
98 (month ;; Search forward from Tot. | |
99 (1+ (calendar-sum m 1 | |
100 (> date | |
101 (calendar-absolute-from-coptic | |
102 (list m | |
103 (coptic-calendar-last-day-of-month m year) | |
104 year))) | |
105 1))) | |
106 (day ;; Calculate the day by subtraction. | |
107 (- date | |
108 (1- (calendar-absolute-from-coptic (list month 1 year)))))) | |
109 (list month day year)))) | |
110 | |
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))))) | |
118 (y (extract-calendar-year coptic-date)) | |
119 (m (extract-calendar-month coptic-date))) | |
120 (if (< y 1) | |
121 "" | |
122 (let ((monthname (aref coptic-calendar-month-name-array (1- m))) | |
123 (day (int-to-string (extract-calendar-day coptic-date))) | |
124 (dayname nil) | |
125 (month (int-to-string m)) | |
126 (year (int-to-string y))) | |
127 (mapconcat 'eval calendar-date-display-form ""))))) | |
128 | |
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 |
137 (defun calendar-goto-coptic-date (date &optional noecho) | |
138 "Move cursor to Coptic date DATE. | |
139 Echo Coptic date unless NOECHO is t." | |
140 (interactive (coptic-prompt-for-date)) | |
141 (calendar-goto-date (calendar-gregorian-from-absolute | |
142 (calendar-absolute-from-coptic date))) | |
143 (or noecho (calendar-print-coptic-date))) | |
144 | |
145 (defun coptic-prompt-for-date () | |
146 "Ask for a Coptic date." | |
147 (let* ((today (calendar-current-date)) | |
148 (year (calendar-read | |
149 (format "%s calendar year (>0): " coptic-name) | |
150 '(lambda (x) (> x 0)) | |
151 (int-to-string | |
152 (extract-calendar-year | |
153 (calendar-coptic-from-absolute | |
154 (calendar-absolute-from-gregorian today)))))) | |
155 (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
|
156 (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
|
157 (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
|
158 (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
|
159 (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
|
160 (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
|
161 nil t) |
13053 | 162 (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
|
163 1) t))) |
13053 | 164 (last (coptic-calendar-last-day-of-month month year)) |
165 (day (calendar-read | |
166 (format "%s calendar day (1-%d): " coptic-name last) | |
167 '(lambda (x) (and (< 0 x) (<= x last)))))) | |
168 (list (list month day year)))) | |
169 | |
170 (defun diary-coptic-date () | |
171 "Coptic calendar equivalent of date diary entry." | |
17383
dade44f8a6b0
(diary-coptic-date): Use `date'.
Richard M. Stallman <rms@gnu.org>
parents:
14568
diff
changeset
|
172 (let ((f (calendar-coptic-date-string date))) |
13053 | 173 (if (string-equal f "") |
174 (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
|
175 (format "%s date: %s" coptic-name f)))) |
13053 | 176 |
177 (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
|
178 ["Maskaram" "Teqemt" "Khedar" "Takhsas" "Ter" "Yakatit" "Magabit" "Miyazya" |
60730f9e6b80
Coorect Ethiopic epoch and some spelling errors.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14169
diff
changeset
|
179 "Genbot" "Sane" "Hamle" "Nahas" "Paguem"]) |
13053 | 180 |
20209
fd00ceeb06c6
(ethiopic-calendar-epoch): Correct to 8 CE.
Karl Heuer <kwzh@gnu.org>
parents:
17571
diff
changeset
|
181 (defconst ethiopic-calendar-epoch 2796 |
fd00ceeb06c6
(ethiopic-calendar-epoch): Correct to 8 CE.
Karl Heuer <kwzh@gnu.org>
parents:
17571
diff
changeset
|
182 "Absolute date of start of Ethiopic calendar = August 29, 8 C.E. (Julian).") |
13053 | 183 |
184 (defconst ethiopic-name "Ethiopic") | |
185 | |
186 (defun calendar-absolute-from-ethiopic (date) | |
187 "Compute absolute date from Ethiopic date DATE. | |
188 The absolute date is the number of days elapsed since the (imaginary) | |
189 Gregorian date Sunday, December 31, 1 BC." | |
190 (let ((coptic-calendar-epoch ethiopic-calendar-epoch)) | |
191 (calendar-absolute-from-coptic date))) | |
192 | |
193 (defun calendar-ethiopic-from-absolute (date) | |
194 "Compute the Ethiopic equivalent for absolute date DATE. | |
195 The result is a list of the form (MONTH DAY YEAR). | |
196 The absolute date is the number of days elapsed since the imaginary | |
197 Gregorian date Sunday, December 31, 1 BC." | |
198 (let ((coptic-calendar-epoch ethiopic-calendar-epoch)) | |
199 (calendar-coptic-from-absolute date))) | |
200 | |
201 (defun calendar-ethiopic-date-string (&optional date) | |
202 "String of Ethiopic date of Gregorian DATE. | |
203 Returns the empty string if DATE is pre-Ethiopic calendar. | |
204 Defaults to today's date if DATE is not given." | |
205 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
206 (coptic-name ethiopic-name) | |
207 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
208 (calendar-coptic-date-string date))) | |
209 | |
210 (defun calendar-print-ethiopic-date () | |
211 "Show the Ethiopic calendar equivalent of the selected date." | |
212 (interactive) | |
213 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
214 (coptic-name ethiopic-name) | |
215 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
216 (call-interactively 'calendar-print-coptic-date))) | |
217 | |
218 (defun calendar-goto-ethiopic-date (date &optional noecho) | |
219 "Move cursor to Ethiopic date DATE. | |
220 Echo Ethiopic date unless NOECHO is t." | |
221 (interactive | |
222 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
223 (coptic-name ethiopic-name) | |
224 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
225 (coptic-prompt-for-date))) | |
226 (calendar-goto-date (calendar-gregorian-from-absolute | |
227 (calendar-absolute-from-ethiopic date))) | |
228 (or noecho (calendar-print-ethiopic-date))) | |
229 | |
230 (defun diary-ethiopic-date () | |
231 "Ethiopic calendar equivalent of date diary entry." | |
232 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
233 (coptic-name ethiopic-name) | |
234 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
235 (diary-coptic-date))) | |
236 | |
237 (provide 'cal-coptic) | |
238 | |
52401 | 239 ;;; arch-tag: 72d49161-25df-4072-9312-b182cdca7627 |
13053 | 240 ;;; cal-coptic.el ends here |