annotate lisp/calendar/cal-coptic.el @ 13053:621d48117fde

Initial revision
author Edward M. Reingold <reingold@emr.cs.iit.edu>
date Thu, 21 Sep 1995 03:11:06 +0000
parents
children 197015b859ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
1 ;;; cal-coptic.el --- calendar functions for the Coptic/Ethiopic calendars.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
2
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
4
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
6 ;; Keywords: calendar
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
7 ;; Human-Keywords: Coptic calendar, Ethiopic calendar, calendar, diary
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
8
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
10
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
14 ;; any later version.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
15
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
19 ;; GNU General Public License for more details.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
20
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
24
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
25 ;;; Commentary:
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
26
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
27 ;; This collection of functions implements the features of calendar.el and
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
28 ;; diary.el that deal with the Coptic and Ethiopic calendars.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
29
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
30 ;; Comments, corrections, and improvements should be sent to
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
31 ;; Edward M. Reingold Department of Computer Science
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
32 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
33 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
34 ;; Urbana, Illinois 61801
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
35
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
36 ;;; Code:
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
37
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
38 (require 'cal-julian)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
39
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
40 (defvar coptic-calendar-month-name-array
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
41 ["Tot" "Babe" "Hatur" "Kihak" "Tube" "Amshir" "Baramhat" "Barmuda"
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
42 "Bashnas" "Bauna" "Abib" "Misra" "Nisi"])
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
43
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
44 (defvar coptic-calendar-epoch (calendar-absolute-from-julian '(8 29 284))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
45 "Absolute date of start of Coptic calendar = August 29, 284 A.D. (Julian).")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
46
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
47 (defconst coptic-name "Coptic")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
48
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
49 (defun coptic-calendar-leap-year-p (year)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
50 "True if YEAR is a leap year on the Coptic calendar."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
51 (zerop (mod (1+ year) 4)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
52
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
53 (defun coptic-calendar-last-day-of-month (month year)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
54 "Return last day of MONTH, YEAR on the Coptic calendar.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
55 The 13th month is not really a month, but the 5 (6 in leap years) day period of
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
56 Nisi (Kebus) at the end of the year."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
57 (if (< month 13)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
58 30
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
59 (if (coptic-calendar-leap-year-p year)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
60 6
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
61 5)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
62
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
63 (defun calendar-absolute-from-coptic (date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
64 "Compute absolute date from Coptic date DATE.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
65 The absolute date is the number of days elapsed since the (imaginary)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
66 Gregorian date Sunday, December 31, 1 BC."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
67 (let ((month (extract-calendar-month date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
68 (day (extract-calendar-day date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
69 (year (extract-calendar-year date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
70 (+ (1- coptic-calendar-epoch);; Days before start of calendar
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
71 (* 365 (1- year)) ;; Days in prior years
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
72 (/ year 4) ;; Leap days in prior years
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
73 (* 30 (1- month)) ;; Days in prior months this year
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
74 day))) ;; Days so far this month
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
75
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
76
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
77 (defun calendar-coptic-from-absolute (date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
78 "Compute the Coptic equivalent for absolute date DATE.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
79 The result is a list of the form (MONTH DAY YEAR).
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
80 The absolute date is the number of days elapsed since the imaginary
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
81 Gregorian date Sunday, December 31, 1 BC."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
82 (if (< date coptic-calendar-epoch)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
83 (list 0 0 0);; pre-Coptic date
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
84 (let* ((approx (/ (- date coptic-calendar-epoch)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
85 366)) ;; Approximation from below.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
86 (year ;; Search forward from the approximation.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
87 (+ approx
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
88 (calendar-sum y approx
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
89 (>= date (calendar-absolute-from-coptic (list 1 1 (1+ y))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
90 1)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
91 (month ;; Search forward from Tot.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
92 (1+ (calendar-sum m 1
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
93 (> date
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
94 (calendar-absolute-from-coptic
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
95 (list m
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
96 (coptic-calendar-last-day-of-month m year)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
97 year)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
98 1)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
99 (day ;; Calculate the day by subtraction.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
100 (- date
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
101 (1- (calendar-absolute-from-coptic (list month 1 year))))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
102 (list month day year))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
103
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
104 (defun calendar-coptic-date-string (&optional date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
105 "String of Coptic date of Gregorian DATE.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
106 Returns the empty string if DATE is pre-Coptic calendar.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
107 Defaults to today's date if DATE is not given."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
108 (let* ((coptic-date (calendar-coptic-from-absolute
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
109 (calendar-absolute-from-gregorian
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
110 (or date (calendar-current-date)))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
111 (y (extract-calendar-year coptic-date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
112 (m (extract-calendar-month coptic-date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
113 (if (< y 1)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
114 ""
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
115 (let ((monthname (aref coptic-calendar-month-name-array (1- m)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
116 (day (int-to-string (extract-calendar-day coptic-date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
117 (dayname nil)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
118 (month (int-to-string m))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
119 (year (int-to-string y)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
120 (mapconcat 'eval calendar-date-display-form "")))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
121
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
122 (defun calendar-print-coptic-date ()
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
123 "Show the Coptic calendar equivalent of the selected date."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
124 (interactive)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
125 (let ((f (calendar-coptic-date-string (calendar-cursor-to-date t))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
126 (if (string-equal f "")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
127 (message "Date is pre-%s calendar" coptic-name)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
128 (message f))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
129
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
130 (defun calendar-goto-coptic-date (date &optional noecho)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
131 "Move cursor to Coptic date DATE.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
132 Echo Coptic date unless NOECHO is t."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
133 (interactive (coptic-prompt-for-date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
134 (calendar-goto-date (calendar-gregorian-from-absolute
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
135 (calendar-absolute-from-coptic date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
136 (or noecho (calendar-print-coptic-date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
137
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
138 (defun coptic-prompt-for-date ()
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
139 "Ask for a Coptic date."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
140 (let* ((today (calendar-current-date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
141 (year (calendar-read
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
142 (format "%s calendar year (>0): " coptic-name)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
143 '(lambda (x) (> x 0))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
144 (int-to-string
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
145 (extract-calendar-year
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
146 (calendar-coptic-from-absolute
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
147 (calendar-absolute-from-gregorian today))))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
148 (completion-ignore-case t)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
149 (month (cdr (assoc
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
150 (capitalize
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
151 (completing-read
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
152 (format "%s calendar month name: " coptic-name)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
153 (mapcar 'list
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
154 (append coptic-calendar-month-name-array nil))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
155 nil t))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
156 (calendar-make-alist coptic-calendar-month-name-array
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
157 1 'capitalize))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
158 (last (coptic-calendar-last-day-of-month month year))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
159 (day (calendar-read
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
160 (format "%s calendar day (1-%d): " coptic-name last)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
161 '(lambda (x) (and (< 0 x) (<= x last))))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
162 (list (list month day year))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
163
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
164 (defun diary-coptic-date ()
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
165 "Coptic calendar equivalent of date diary entry."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
166 (let ((f (calendar-coptic-date-string (calendar-cursor-to-date t))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
167 (if (string-equal f "")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
168 (format "Date is pre-%s calendar" coptic-name)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
169 f)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
170
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
171 (defconst ethiopic-calendar-month-name-array
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
172 ["Maskarram" "Tekemt" "Hadar" "Tahsas" "Tarr" "Yekatit" "Magawit" "Miaziah"
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
173 "Genbot" "Sanni" "Hamle" "Nas'hi" "Pagnem"])
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
174
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
175 (defconst ethiopic-calendar-epoch (calendar-absolute-from-julian '(8 29 7))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
176 "Absolute date of start of Ethiopic calendar = August 29, 7 A.D. (Julian).")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
177
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
178 (defconst ethiopic-name "Ethiopic")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
179
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
180 (defun calendar-absolute-from-ethiopic (date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
181 "Compute absolute date from Ethiopic date DATE.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
182 The absolute date is the number of days elapsed since the (imaginary)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
183 Gregorian date Sunday, December 31, 1 BC."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
184 (let ((coptic-calendar-epoch ethiopic-calendar-epoch))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
185 (calendar-absolute-from-coptic date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
186
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
187 (defun calendar-ethiopic-from-absolute (date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
188 "Compute the Ethiopic equivalent for absolute date DATE.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
189 The result is a list of the form (MONTH DAY YEAR).
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
190 The absolute date is the number of days elapsed since the imaginary
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
191 Gregorian date Sunday, December 31, 1 BC."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
192 (let ((coptic-calendar-epoch ethiopic-calendar-epoch))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
193 (calendar-coptic-from-absolute date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
194
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
195 (defun calendar-ethiopic-date-string (&optional date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
196 "String of Ethiopic date of Gregorian DATE.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
197 Returns the empty string if DATE is pre-Ethiopic calendar.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
198 Defaults to today's date if DATE is not given."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
199 (let ((coptic-calendar-epoch ethiopic-calendar-epoch)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
200 (coptic-name ethiopic-name)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
201 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
202 (calendar-coptic-date-string date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
203
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
204 (defun calendar-print-ethiopic-date ()
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
205 "Show the Ethiopic calendar equivalent of the selected date."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
206 (interactive)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
207 (let ((coptic-calendar-epoch ethiopic-calendar-epoch)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
208 (coptic-name ethiopic-name)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
209 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
210 (call-interactively 'calendar-print-coptic-date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
211
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
212 (defun calendar-goto-ethiopic-date (date &optional noecho)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
213 "Move cursor to Ethiopic date DATE.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
214 Echo Ethiopic date unless NOECHO is t."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
215 (interactive
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
216 (let ((coptic-calendar-epoch ethiopic-calendar-epoch)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
217 (coptic-name ethiopic-name)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
218 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
219 (coptic-prompt-for-date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
220 (calendar-goto-date (calendar-gregorian-from-absolute
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
221 (calendar-absolute-from-ethiopic date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
222 (or noecho (calendar-print-ethiopic-date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
223
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
224 (defun diary-ethiopic-date ()
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
225 "Ethiopic calendar equivalent of date diary entry."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
226 (let ((coptic-calendar-epoch ethiopic-calendar-epoch)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
227 (coptic-name ethiopic-name)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
228 (coptic-calendar-month-name-array ethiopic-calendar-month-name-array))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
229 (diary-coptic-date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
230
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
231 (provide 'cal-coptic)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
232
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
233 ;;; cal-coptic.el ends here