Mercurial > emacs
annotate lisp/calendar/cal-coptic.el @ 73593:bc8ade3f96b7
* eintr: updated `Introduction to Programming in Emacs Lisp'
author | Robert J. Chassell <bob@rattlesnake.com> |
---|---|
date | Tue, 31 Oct 2006 18:03:03 +0000 |
parents | 8daf7d9a0771 |
children | 7a3f13e2dd57 4b3d39451150 |
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 |
68721 | 3 ;; Copyright (C) 1995, 1997, 2001, 2002, 2003, 2004, 2005, 2006 |
67465
a55ee709ec8d
Update copyright pending Emacs 22.
Glenn Morris <rgm@gnu.org>
parents:
65145
diff
changeset
|
4 ;; 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 | |
15 ;; the Free Software Foundation; either version 2, or (at your option) | |
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 | |
30 ;; This collection of functions implements the features of calendar.el and | |
31 ;; diary.el that deal with the Coptic and Ethiopic calendars. | |
32 | |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
20209
diff
changeset
|
33 ;; 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
|
34 ;; ``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
|
35 ;; 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
|
36 |
13053 | 37 ;; Comments, corrections, and improvements should be sent to |
38 ;; Edward M. Reingold Department of Computer Science | |
39 ;; (217) 333-6733 University of Illinois at Urbana-Champaign | |
40 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue | |
41 ;; Urbana, Illinois 61801 | |
42 | |
43 ;;; Code: | |
44 | |
65145
ac895e21e622
(date): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
45 (defvar date) |
ac895e21e622
(date): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
46 |
13053 | 47 (require 'cal-julian) |
48 | |
49 (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
|
50 ["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
|
51 "Bashans" "Baunah" "Abib" "Misra" "al-Nasi"]) |
13053 | 52 |
53 (defvar coptic-calendar-epoch (calendar-absolute-from-julian '(8 29 284)) | |
54 "Absolute date of start of Coptic calendar = August 29, 284 A.D. (Julian).") | |
55 | |
52111
e6182946cacd
(coptic-name): defvar rather than defconst.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
56 (defvar coptic-name "Coptic") |
13053 | 57 |
58 (defun coptic-calendar-leap-year-p (year) | |
59 "True if YEAR is a leap year on the Coptic calendar." | |
60 (zerop (mod (1+ year) 4))) | |
61 | |
62 (defun coptic-calendar-last-day-of-month (month year) | |
63 "Return last day of MONTH, YEAR on the Coptic calendar. | |
64 The 13th month is not really a month, but the 5 (6 in leap years) day period of | |
65 Nisi (Kebus) at the end of the year." | |
66 (if (< month 13) | |
67 30 | |
68 (if (coptic-calendar-leap-year-p year) | |
69 6 | |
70 5))) | |
71 | |
72 (defun calendar-absolute-from-coptic (date) | |
73 "Compute absolute date from Coptic date DATE. | |
74 The absolute date is the number of days elapsed since the (imaginary) | |
75 Gregorian date Sunday, December 31, 1 BC." | |
76 (let ((month (extract-calendar-month date)) | |
77 (day (extract-calendar-day date)) | |
78 (year (extract-calendar-year date))) | |
79 (+ (1- coptic-calendar-epoch);; Days before start of calendar | |
80 (* 365 (1- year)) ;; Days in prior years | |
81 (/ year 4) ;; Leap days in prior years | |
82 (* 30 (1- month)) ;; Days in prior months this year | |
83 day))) ;; Days so far this month | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
84 |
13053 | 85 |
86 (defun calendar-coptic-from-absolute (date) | |
87 "Compute the Coptic equivalent for absolute date DATE. | |
88 The result is a list of the form (MONTH DAY YEAR). | |
89 The absolute date is the number of days elapsed since the imaginary | |
90 Gregorian date Sunday, December 31, 1 BC." | |
91 (if (< date coptic-calendar-epoch) | |
92 (list 0 0 0);; pre-Coptic date | |
93 (let* ((approx (/ (- date coptic-calendar-epoch) | |
94 366)) ;; Approximation from below. | |
95 (year ;; Search forward from the approximation. | |
96 (+ approx | |
97 (calendar-sum y approx | |
98 (>= date (calendar-absolute-from-coptic (list 1 1 (1+ y)))) | |
99 1))) | |
100 (month ;; Search forward from Tot. | |
101 (1+ (calendar-sum m 1 | |
102 (> date | |
103 (calendar-absolute-from-coptic | |
104 (list m | |
105 (coptic-calendar-last-day-of-month m year) | |
106 year))) | |
107 1))) | |
108 (day ;; Calculate the day by subtraction. | |
109 (- date | |
110 (1- (calendar-absolute-from-coptic (list month 1 year)))))) | |
111 (list month day year)))) | |
112 | |
113 (defun calendar-coptic-date-string (&optional date) | |
114 "String of Coptic date of Gregorian DATE. | |
115 Returns the empty string if DATE is pre-Coptic calendar. | |
116 Defaults to today's date if DATE is not given." | |
117 (let* ((coptic-date (calendar-coptic-from-absolute | |
118 (calendar-absolute-from-gregorian | |
119 (or date (calendar-current-date))))) | |
120 (y (extract-calendar-year coptic-date)) | |
121 (m (extract-calendar-month coptic-date))) | |
122 (if (< y 1) | |
123 "" | |
124 (let ((monthname (aref coptic-calendar-month-name-array (1- m))) | |
125 (day (int-to-string (extract-calendar-day coptic-date))) | |
126 (dayname nil) | |
127 (month (int-to-string m)) | |
128 (year (int-to-string y))) | |
129 (mapconcat 'eval calendar-date-display-form ""))))) | |
130 | |
131 (defun calendar-print-coptic-date () | |
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 "") | |
136 (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
|
137 (message "%s date: %s" coptic-name f)))) |
13053 | 138 |
139 (defun calendar-goto-coptic-date (date &optional noecho) | |
140 "Move cursor to Coptic date DATE. | |
141 Echo Coptic date unless NOECHO is t." | |
142 (interactive (coptic-prompt-for-date)) | |
143 (calendar-goto-date (calendar-gregorian-from-absolute | |
144 (calendar-absolute-from-coptic date))) | |
145 (or noecho (calendar-print-coptic-date))) | |
146 | |
147 (defun coptic-prompt-for-date () | |
148 "Ask for a Coptic date." | |
149 (let* ((today (calendar-current-date)) | |
150 (year (calendar-read | |
151 (format "%s calendar year (>0): " coptic-name) | |
152 '(lambda (x) (> x 0)) | |
153 (int-to-string | |
154 (extract-calendar-year | |
155 (calendar-coptic-from-absolute | |
156 (calendar-absolute-from-gregorian today)))))) | |
157 (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
|
158 (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
|
159 (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
|
160 (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
|
161 (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
|
162 (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
|
163 nil t) |
13053 | 164 (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
|
165 1) t))) |
13053 | 166 (last (coptic-calendar-last-day-of-month month year)) |
167 (day (calendar-read | |
168 (format "%s calendar day (1-%d): " coptic-name last) | |
169 '(lambda (x) (and (< 0 x) (<= x last)))))) | |
170 (list (list month day year)))) | |
171 | |
172 (defun diary-coptic-date () | |
173 "Coptic calendar equivalent of date diary entry." | |
17383
dade44f8a6b0
(diary-coptic-date): Use `date'.
Richard M. Stallman <rms@gnu.org>
parents:
14568
diff
changeset
|
174 (let ((f (calendar-coptic-date-string date))) |
13053 | 175 (if (string-equal f "") |
176 (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
|
177 (format "%s date: %s" coptic-name f)))) |
13053 | 178 |
179 (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
|
180 ["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
|
181 "Genbot" "Sane" "Hamle" "Nahas" "Paguem"]) |
13053 | 182 |
20209
fd00ceeb06c6
(ethiopic-calendar-epoch): Correct to 8 CE.
Karl Heuer <kwzh@gnu.org>
parents:
17571
diff
changeset
|
183 (defconst ethiopic-calendar-epoch 2796 |
fd00ceeb06c6
(ethiopic-calendar-epoch): Correct to 8 CE.
Karl Heuer <kwzh@gnu.org>
parents:
17571
diff
changeset
|
184 "Absolute date of start of Ethiopic calendar = August 29, 8 C.E. (Julian).") |
13053 | 185 |
186 (defconst ethiopic-name "Ethiopic") | |
187 | |
188 (defun calendar-absolute-from-ethiopic (date) | |
189 "Compute absolute date from Ethiopic date DATE. | |
190 The absolute date is the number of days elapsed since the (imaginary) | |
191 Gregorian date Sunday, December 31, 1 BC." | |
192 (let ((coptic-calendar-epoch ethiopic-calendar-epoch)) | |
193 (calendar-absolute-from-coptic date))) | |
194 | |
195 (defun calendar-ethiopic-from-absolute (date) | |
196 "Compute the Ethiopic equivalent for absolute date DATE. | |
197 The result is a list of the form (MONTH DAY YEAR). | |
198 The absolute date is the number of days elapsed since the imaginary | |
199 Gregorian date Sunday, December 31, 1 BC." | |
200 (let ((coptic-calendar-epoch ethiopic-calendar-epoch)) | |
201 (calendar-coptic-from-absolute date))) | |
202 | |
203 (defun calendar-ethiopic-date-string (&optional date) | |
204 "String of Ethiopic date of Gregorian DATE. | |
205 Returns the empty string if DATE is pre-Ethiopic calendar. | |
206 Defaults to today's date if DATE is not given." | |
207 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
208 (coptic-name ethiopic-name) | |
209 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
210 (calendar-coptic-date-string date))) | |
211 | |
212 (defun calendar-print-ethiopic-date () | |
213 "Show the Ethiopic calendar equivalent of the selected date." | |
214 (interactive) | |
215 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
216 (coptic-name ethiopic-name) | |
217 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
218 (call-interactively 'calendar-print-coptic-date))) | |
219 | |
220 (defun calendar-goto-ethiopic-date (date &optional noecho) | |
221 "Move cursor to Ethiopic date DATE. | |
222 Echo Ethiopic date unless NOECHO is t." | |
223 (interactive | |
224 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
225 (coptic-name ethiopic-name) | |
226 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
227 (coptic-prompt-for-date))) | |
228 (calendar-goto-date (calendar-gregorian-from-absolute | |
229 (calendar-absolute-from-ethiopic date))) | |
230 (or noecho (calendar-print-ethiopic-date))) | |
231 | |
232 (defun diary-ethiopic-date () | |
233 "Ethiopic calendar equivalent of date diary entry." | |
234 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
235 (coptic-name ethiopic-name) | |
236 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
237 (diary-coptic-date))) | |
238 | |
239 (provide 'cal-coptic) | |
240 | |
52401 | 241 ;;; arch-tag: 72d49161-25df-4072-9312-b182cdca7627 |
13053 | 242 ;;; cal-coptic.el ends here |