Mercurial > emacs
annotate lisp/calendar/cal-coptic.el @ 19860:c17fd465ea95 libc-970911 libc-970912 libc-970913 libc-970914 libc-970915 libc-970916 libc-970917 libc-970918 libc-970919 libc-970920 libc-970921 libc-970922 libc-970923 libc-970924 libc-970925 libc-970926 libc-970927 libc-970928 libc-970929 libc-970930 libc-971001 libc-971018 libc-971019 libc-971020 libc-971021 libc-971022 libc-971023 libc-971024 libc-971025 libc-971026 libc-971027 libc-971028 libc-971029 libc-971030 libc-971031 libc-971101 libc-971102 libc-971103 libc-971104 libc-971105 libc-971106 libc-971107 libc-971108 libc-971109 libc-971110 libc-971111 libc-971112 libc-971113 libc-971114 libc-971115 libc-971116 libc-971117 libc-971118 libc-971120 libc-971121 libc-971122 libc-971123 libc-971124 libc-971125 libc-971126 libc-971127 libc-971128 libc-971129 libc-971130 libc-971201 libc-971203 libc-971204 libc-971205 libc-971206 libc-971207 libc-971208 libc-971209 libc-971210 libc-971211 libc-971212 libc-971213 libc-971214 libc-971217 libc-971218 libc-971219 libc-971220 libc-971221 libc-971222 libc-971223 libc-971224 libc-971225 libc-971226 libc-971227 libc-971228 libc-971229 libc-971230 libc-971231 libc-980103 libc-980104 libc-980105 libc-980106 libc-980107 libc-980108 libc-980109 libc-980110 libc-980111 libc-980112 libc-980114 libc-980115 libc-980116 libc-980117 libc-980118 libc-980119 libc-980120 libc-980121 libc-980122 libc-980123 libc-980124 libc-980125 libc-980126 libc-980127 libc-980128
typos.
author | Jeff Law <law@redhat.com> |
---|---|
date | Wed, 10 Sep 1997 21:16:20 +0000 |
parents | e4c551837753 |
children | fd00ceeb06c6 |
rev | line source |
---|---|
13053 | 1 ;;; cal-coptic.el --- calendar functions for the Coptic/Ethiopic calendars. |
2 | |
3 ;; Copyright (C) 1995 Free Software Foundation, Inc. | |
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 |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, 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 | |
31 ;; Comments, corrections, and improvements should be sent to | |
32 ;; Edward M. Reingold Department of Computer Science | |
33 ;; (217) 333-6733 University of Illinois at Urbana-Champaign | |
34 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue | |
35 ;; Urbana, Illinois 61801 | |
36 | |
37 ;;; Code: | |
38 | |
39 (require 'cal-julian) | |
40 | |
41 (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
|
42 ["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
|
43 "Bashans" "Baunah" "Abib" "Misra" "al-Nasi"]) |
13053 | 44 |
45 (defvar coptic-calendar-epoch (calendar-absolute-from-julian '(8 29 284)) | |
46 "Absolute date of start of Coptic calendar = August 29, 284 A.D. (Julian).") | |
47 | |
48 (defconst coptic-name "Coptic") | |
49 | |
50 (defun coptic-calendar-leap-year-p (year) | |
51 "True if YEAR is a leap year on the Coptic calendar." | |
52 (zerop (mod (1+ year) 4))) | |
53 | |
54 (defun coptic-calendar-last-day-of-month (month year) | |
55 "Return last day of MONTH, YEAR on the Coptic calendar. | |
56 The 13th month is not really a month, but the 5 (6 in leap years) day period of | |
57 Nisi (Kebus) at the end of the year." | |
58 (if (< month 13) | |
59 30 | |
60 (if (coptic-calendar-leap-year-p year) | |
61 6 | |
62 5))) | |
63 | |
64 (defun calendar-absolute-from-coptic (date) | |
65 "Compute absolute date from Coptic date DATE. | |
66 The absolute date is the number of days elapsed since the (imaginary) | |
67 Gregorian date Sunday, December 31, 1 BC." | |
68 (let ((month (extract-calendar-month date)) | |
69 (day (extract-calendar-day date)) | |
70 (year (extract-calendar-year date))) | |
71 (+ (1- coptic-calendar-epoch);; Days before start of calendar | |
72 (* 365 (1- year)) ;; Days in prior years | |
73 (/ year 4) ;; Leap days in prior years | |
74 (* 30 (1- month)) ;; Days in prior months this year | |
75 day))) ;; Days so far this month | |
76 | |
77 | |
78 (defun calendar-coptic-from-absolute (date) | |
79 "Compute the Coptic equivalent for absolute date DATE. | |
80 The result is a list of the form (MONTH DAY YEAR). | |
81 The absolute date is the number of days elapsed since the imaginary | |
82 Gregorian date Sunday, December 31, 1 BC." | |
83 (if (< date coptic-calendar-epoch) | |
84 (list 0 0 0);; pre-Coptic date | |
85 (let* ((approx (/ (- date coptic-calendar-epoch) | |
86 366)) ;; Approximation from below. | |
87 (year ;; Search forward from the approximation. | |
88 (+ approx | |
89 (calendar-sum y approx | |
90 (>= date (calendar-absolute-from-coptic (list 1 1 (1+ y)))) | |
91 1))) | |
92 (month ;; Search forward from Tot. | |
93 (1+ (calendar-sum m 1 | |
94 (> date | |
95 (calendar-absolute-from-coptic | |
96 (list m | |
97 (coptic-calendar-last-day-of-month m year) | |
98 year))) | |
99 1))) | |
100 (day ;; Calculate the day by subtraction. | |
101 (- date | |
102 (1- (calendar-absolute-from-coptic (list month 1 year)))))) | |
103 (list month day year)))) | |
104 | |
105 (defun calendar-coptic-date-string (&optional date) | |
106 "String of Coptic date of Gregorian DATE. | |
107 Returns the empty string if DATE is pre-Coptic calendar. | |
108 Defaults to today's date if DATE is not given." | |
109 (let* ((coptic-date (calendar-coptic-from-absolute | |
110 (calendar-absolute-from-gregorian | |
111 (or date (calendar-current-date))))) | |
112 (y (extract-calendar-year coptic-date)) | |
113 (m (extract-calendar-month coptic-date))) | |
114 (if (< y 1) | |
115 "" | |
116 (let ((monthname (aref coptic-calendar-month-name-array (1- m))) | |
117 (day (int-to-string (extract-calendar-day coptic-date))) | |
118 (dayname nil) | |
119 (month (int-to-string m)) | |
120 (year (int-to-string y))) | |
121 (mapconcat 'eval calendar-date-display-form ""))))) | |
122 | |
123 (defun calendar-print-coptic-date () | |
124 "Show the Coptic calendar equivalent of the selected date." | |
125 (interactive) | |
126 (let ((f (calendar-coptic-date-string (calendar-cursor-to-date t)))) | |
127 (if (string-equal f "") | |
128 (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
|
129 (message "%s date: %s" coptic-name f)))) |
13053 | 130 |
131 (defun calendar-goto-coptic-date (date &optional noecho) | |
132 "Move cursor to Coptic date DATE. | |
133 Echo Coptic date unless NOECHO is t." | |
134 (interactive (coptic-prompt-for-date)) | |
135 (calendar-goto-date (calendar-gregorian-from-absolute | |
136 (calendar-absolute-from-coptic date))) | |
137 (or noecho (calendar-print-coptic-date))) | |
138 | |
139 (defun coptic-prompt-for-date () | |
140 "Ask for a Coptic date." | |
141 (let* ((today (calendar-current-date)) | |
142 (year (calendar-read | |
143 (format "%s calendar year (>0): " coptic-name) | |
144 '(lambda (x) (> x 0)) | |
145 (int-to-string | |
146 (extract-calendar-year | |
147 (calendar-coptic-from-absolute | |
148 (calendar-absolute-from-gregorian today)))))) | |
149 (completion-ignore-case t) | |
150 (month (cdr (assoc | |
151 (capitalize | |
152 (completing-read | |
153 (format "%s calendar month name: " coptic-name) | |
154 (mapcar 'list | |
155 (append coptic-calendar-month-name-array nil)) | |
156 nil t)) | |
157 (calendar-make-alist coptic-calendar-month-name-array | |
158 1 'capitalize)))) | |
159 (last (coptic-calendar-last-day-of-month month year)) | |
160 (day (calendar-read | |
161 (format "%s calendar day (1-%d): " coptic-name last) | |
162 '(lambda (x) (and (< 0 x) (<= x last)))))) | |
163 (list (list month day year)))) | |
164 | |
165 (defun diary-coptic-date () | |
166 "Coptic calendar equivalent of date diary entry." | |
17383
dade44f8a6b0
(diary-coptic-date): Use `date'.
Richard M. Stallman <rms@gnu.org>
parents:
14568
diff
changeset
|
167 (let ((f (calendar-coptic-date-string date))) |
13053 | 168 (if (string-equal f "") |
169 (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
|
170 (format "%s date: %s" coptic-name f)))) |
13053 | 171 |
172 (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
|
173 ["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
|
174 "Genbot" "Sane" "Hamle" "Nahas" "Paguem"]) |
13053 | 175 |
14568
60730f9e6b80
Coorect Ethiopic epoch and some spelling errors.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14169
diff
changeset
|
176 (defconst ethiopic-calendar-epoch 2430 |
60730f9e6b80
Coorect Ethiopic epoch and some spelling errors.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14169
diff
changeset
|
177 "Absolute date of start of Ethiopic calendar = August 29, 7 C.E. (Julian).") |
13053 | 178 |
179 (defconst ethiopic-name "Ethiopic") | |
180 | |
181 (defun calendar-absolute-from-ethiopic (date) | |
182 "Compute absolute date from Ethiopic date DATE. | |
183 The absolute date is the number of days elapsed since the (imaginary) | |
184 Gregorian date Sunday, December 31, 1 BC." | |
185 (let ((coptic-calendar-epoch ethiopic-calendar-epoch)) | |
186 (calendar-absolute-from-coptic date))) | |
187 | |
188 (defun calendar-ethiopic-from-absolute (date) | |
189 "Compute the Ethiopic equivalent for absolute date DATE. | |
190 The result is a list of the form (MONTH DAY YEAR). | |
191 The absolute date is the number of days elapsed since the imaginary | |
192 Gregorian date Sunday, December 31, 1 BC." | |
193 (let ((coptic-calendar-epoch ethiopic-calendar-epoch)) | |
194 (calendar-coptic-from-absolute date))) | |
195 | |
196 (defun calendar-ethiopic-date-string (&optional date) | |
197 "String of Ethiopic date of Gregorian DATE. | |
198 Returns the empty string if DATE is pre-Ethiopic calendar. | |
199 Defaults to today's date if DATE is not given." | |
200 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
201 (coptic-name ethiopic-name) | |
202 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
203 (calendar-coptic-date-string date))) | |
204 | |
205 (defun calendar-print-ethiopic-date () | |
206 "Show the Ethiopic calendar equivalent of the selected date." | |
207 (interactive) | |
208 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
209 (coptic-name ethiopic-name) | |
210 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
211 (call-interactively 'calendar-print-coptic-date))) | |
212 | |
213 (defun calendar-goto-ethiopic-date (date &optional noecho) | |
214 "Move cursor to Ethiopic date DATE. | |
215 Echo Ethiopic date unless NOECHO is t." | |
216 (interactive | |
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 (coptic-prompt-for-date))) | |
221 (calendar-goto-date (calendar-gregorian-from-absolute | |
222 (calendar-absolute-from-ethiopic date))) | |
223 (or noecho (calendar-print-ethiopic-date))) | |
224 | |
225 (defun diary-ethiopic-date () | |
226 "Ethiopic calendar equivalent of date diary entry." | |
227 (let ((coptic-calendar-epoch ethiopic-calendar-epoch) | |
228 (coptic-name ethiopic-name) | |
229 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) | |
230 (diary-coptic-date))) | |
231 | |
232 (provide 'cal-coptic) | |
233 | |
234 ;;; cal-coptic.el ends here |