| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
(defvar date) |
|---|
| 40 |
|
|---|
| 41 |
(require 'cal-julian) |
|---|
| 42 |
|
|---|
| 43 |
(defvar coptic-calendar-month-name-array |
|---|
| 44 |
["Tut" "Babah" "Hatur" "Kiyahk" "Tubah" "Amshir" "Baramhat" "Barmundah" |
|---|
| 45 |
"Bashans" "Baunah" "Abib" "Misra" "al-Nasi"]) |
|---|
| 46 |
|
|---|
| 47 |
(defvar coptic-calendar-epoch (calendar-absolute-from-julian '(8 29 284)) |
|---|
| 48 |
"Absolute date of start of Coptic calendar = August 29, 284 A.D. (Julian).") |
|---|
| 49 |
|
|---|
| 50 |
(defvar coptic-name "Coptic") |
|---|
| 51 |
|
|---|
| 52 |
(defun coptic-calendar-leap-year-p (year) |
|---|
| 53 |
"True if YEAR is a leap year on the Coptic calendar." |
|---|
| 54 |
(zerop (mod (1+ year) 4))) |
|---|
| 55 |
|
|---|
| 56 |
(defun coptic-calendar-last-day-of-month (month year) |
|---|
| 57 |
"Return last day of MONTH, YEAR on the Coptic calendar. |
|---|
| 58 |
The 13th month is not really a month, but the 5 (6 in leap years) day period of |
|---|
| 59 |
Nisi (Kebus) at the end of the year." |
|---|
| 60 |
(if (< month 13) |
|---|
| 61 |
30 |
|---|
| 62 |
(if (coptic-calendar-leap-year-p year) |
|---|
| 63 |
6 |
|---|
| 64 |
5))) |
|---|
| 65 |
|
|---|
| 66 |
(defun calendar-absolute-from-coptic (date) |
|---|
| 67 |
"Compute absolute date from Coptic date DATE. |
|---|
| 68 |
The absolute date is the number of days elapsed since the (imaginary) |
|---|
| 69 |
Gregorian date Sunday, December 31, 1 BC." |
|---|
| 70 |
(let ((month (extract-calendar-month date)) |
|---|
| 71 |
(day (extract-calendar-day date)) |
|---|
| 72 |
(year (extract-calendar-year date))) |
|---|
| 73 |
(+ (1- coptic-calendar-epoch) |
|---|
| 74 |
(* 365 (1- year)) |
|---|
| 75 |
(/ year 4) |
|---|
| 76 |
(* 30 (1- month)) |
|---|
| 77 |
day))) |
|---|
| 78 |
|
|---|
| 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) |
|---|
| 86 |
(list 0 0 0) |
|---|
| 87 |
(let* ((approx (/ (- date coptic-calendar-epoch) |
|---|
| 88 |
366)) |
|---|
| 89 |
(year |
|---|
| 90 |
(+ approx |
|---|
| 91 |
(calendar-sum y approx |
|---|
| 92 |
(>= date (calendar-absolute-from-coptic (list 1 1 (1+ y)))) |
|---|
| 93 |
1))) |
|---|
| 94 |
(month |
|---|
| 95 |
(1+ (calendar-sum m 1 |
|---|
| 96 |
(> date |
|---|
| 97 |
(calendar-absolute-from-coptic |
|---|
| 98 |
(list m |
|---|
| 99 |
(coptic-calendar-last-day-of-month m year) |
|---|
| 100 |
year))) |
|---|
| 101 |
1))) |
|---|
| 102 |
(day |
|---|
| 103 |
(- date |
|---|
| 104 |
(1- (calendar-absolute-from-coptic (list month 1 year)))))) |
|---|
| 105 |
(list month day year)))) |
|---|
| 106 |
|
|---|
| 107 |
(defun calendar-coptic-date-string (&optional date) |
|---|
| 108 |
"String of Coptic date of Gregorian DATE. |
|---|
| 109 |
Returns the empty string if DATE is pre-Coptic calendar. |
|---|
| 110 |
Defaults to today's date if DATE is not given." |
|---|
| 111 |
(let* ((coptic-date (calendar-coptic-from-absolute |
|---|
| 112 |
(calendar-absolute-from-gregorian |
|---|
| 113 |
(or date (calendar-current-date))))) |
|---|
| 114 |
(y (extract-calendar-year coptic-date)) |
|---|
| 115 |
(m (extract-calendar-month coptic-date))) |
|---|
| 116 |
(if (< y 1) |
|---|
| 117 |
"" |
|---|
| 118 |
(let ((monthname (aref coptic-calendar-month-name-array (1- m))) |
|---|
| 119 |
(day (int-to-string (extract-calendar-day coptic-date))) |
|---|
| 120 |
(dayname nil) |
|---|
| 121 |
(month (int-to-string m)) |
|---|
| 122 |
(year (int-to-string y))) |
|---|
| 123 |
(mapconcat 'eval calendar-date-display-form ""))))) |
|---|
| 124 |
|
|---|
| 125 |
(defun calendar-print-coptic-date () |
|---|
| 126 |
"Show the Coptic calendar equivalent of the selected date." |
|---|
| 127 |
(interactive) |
|---|
| 128 |
(let ((f (calendar-coptic-date-string (calendar-cursor-to-date t)))) |
|---|
| 129 |
(if (string-equal f "") |
|---|
| 130 |
(message "Date is pre-%s calendar" coptic-name) |
|---|
| 131 |
(message "%s date: %s" coptic-name f)))) |
|---|
| 132 |
|
|---|
| 133 |
(defun calendar-goto-coptic-date (date &optional noecho) |
|---|
| 134 |
"Move cursor to Coptic date DATE. |
|---|
| 135 |
Echo Coptic date unless NOECHO is t." |
|---|
| 136 |
(interactive (coptic-prompt-for-date)) |
|---|
| 137 |
(calendar-goto-date (calendar-gregorian-from-absolute |
|---|
| 138 |
(calendar-absolute-from-coptic date))) |
|---|
| 139 |
(or noecho (calendar-print-coptic-date))) |
|---|
| 140 |
|
|---|
| 141 |
(defun coptic-prompt-for-date () |
|---|
| 142 |
"Ask for a Coptic date." |
|---|
| 143 |
(let* ((today (calendar-current-date)) |
|---|
| 144 |
(year (calendar-read |
|---|
| 145 |
(format "%s calendar year (>0): " coptic-name) |
|---|
| 146 |
'(lambda (x) (> x 0)) |
|---|
| 147 |
(int-to-string |
|---|
| 148 |
(extract-calendar-year |
|---|
| 149 |
(calendar-coptic-from-absolute |
|---|
| 150 |
(calendar-absolute-from-gregorian today)))))) |
|---|
| 151 |
(completion-ignore-case t) |
|---|
| 152 |
(month (cdr (assoc-string |
|---|
| 153 |
(completing-read |
|---|
| 154 |
(format "%s calendar month name: " coptic-name) |
|---|
| 155 |
(mapcar 'list |
|---|
| 156 |
(append coptic-calendar-month-name-array nil)) |
|---|
| 157 |
nil t) |
|---|
| 158 |
(calendar-make-alist coptic-calendar-month-name-array |
|---|
| 159 |
1) t))) |
|---|
| 160 |
(last (coptic-calendar-last-day-of-month month year)) |
|---|
| 161 |
(day (calendar-read |
|---|
| 162 |
(format "%s calendar day (1-%d): " coptic-name last) |
|---|
| 163 |
'(lambda (x) (and (< 0 x) (<= x last)))))) |
|---|
| 164 |
(list (list month day year)))) |
|---|
| 165 |
|
|---|
| 166 |
(defun diary-coptic-date () |
|---|
| 167 |
"Coptic calendar equivalent of date diary entry." |
|---|
| 168 |
(let ((f (calendar-coptic-date-string date))) |
|---|
| 169 |
(if (string-equal f "") |
|---|
| 170 |
(format "Date is pre-%s calendar" coptic-name) |
|---|
| 171 |
(format "%s date: %s" coptic-name f)))) |
|---|
| 172 |
|
|---|
| 173 |
(defconst ethiopic-calendar-month-name-array |
|---|
| 174 |
["Maskaram" "Teqemt" "Khedar" "Takhsas" "Ter" "Yakatit" "Magabit" "Miyazya" |
|---|
| 175 |
"Genbot" "Sane" "Hamle" "Nahas" "Paguem"]) |
|---|
| 176 |
|
|---|
| 177 |
(defconst ethiopic-calendar-epoch 2796 |
|---|
| 178 |
"Absolute date of start of Ethiopic calendar = August 29, 8 C.E. (Julian).") |
|---|
| 179 |
|
|---|
| 180 |
(defconst ethiopic-name "Ethiopic") |
|---|
| 181 |
|
|---|
| 182 |
(defun calendar-absolute-from-ethiopic (date) |
|---|
| 183 |
"Compute absolute date from Ethiopic date DATE. |
|---|
| 184 |
The absolute date is the number of days elapsed since the (imaginary) |
|---|
| 185 |
Gregorian date Sunday, December 31, 1 BC." |
|---|
| 186 |
(let ((coptic-calendar-epoch ethiopic-calendar-epoch)) |
|---|
| 187 |
(calendar-absolute-from-coptic date))) |
|---|
| 188 |
|
|---|
| 189 |
(defun calendar-ethiopic-from-absolute (date) |
|---|
| 190 |
"Compute the Ethiopic equivalent for absolute date DATE. |
|---|
| 191 |
The result is a list of the form (MONTH DAY YEAR). |
|---|
| 192 |
The absolute date is the number of days elapsed since the imaginary |
|---|
| 193 |
Gregorian date Sunday, December 31, 1 BC." |
|---|
| 194 |
(let ((coptic-calendar-epoch ethiopic-calendar-epoch)) |
|---|
| 195 |
(calendar-coptic-from-absolute date))) |
|---|
| 196 |
|
|---|
| 197 |
(defun calendar-ethiopic-date-string (&optional date) |
|---|
| 198 |
"String of Ethiopic date of Gregorian DATE. |
|---|
| 199 |
Returns the empty string if DATE is pre-Ethiopic calendar. |
|---|
| 200 |
Defaults to today's date if DATE is not given." |
|---|
| 201 |
(let ((coptic-calendar-epoch ethiopic-calendar-epoch) |
|---|
| 202 |
(coptic-name ethiopic-name) |
|---|
| 203 |
(coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) |
|---|
| 204 |
(calendar-coptic-date-string date))) |
|---|
| 205 |
|
|---|
| 206 |
(defun calendar-print-ethiopic-date () |
|---|
| 207 |
"Show the Ethiopic calendar equivalent of the selected date." |
|---|
| 208 |
(interactive) |
|---|
| 209 |
(let ((coptic-calendar-epoch ethiopic-calendar-epoch) |
|---|
| 210 |
(coptic-name ethiopic-name) |
|---|
| 211 |
(coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) |
|---|
| 212 |
(call-interactively 'calendar-print-coptic-date))) |
|---|
| 213 |
|
|---|
| 214 |
(defun calendar-goto-ethiopic-date (date &optional noecho) |
|---|
| 215 |
"Move cursor to Ethiopic date DATE. |
|---|
| 216 |
Echo Ethiopic date unless NOECHO is t." |
|---|
| 217 |
(interactive |
|---|
| 218 |
(let ((coptic-calendar-epoch ethiopic-calendar-epoch) |
|---|
| 219 |
(coptic-name ethiopic-name) |
|---|
| 220 |
(coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) |
|---|
| 221 |
(coptic-prompt-for-date))) |
|---|
| 222 |
(calendar-goto-date (calendar-gregorian-from-absolute |
|---|
| 223 |
(calendar-absolute-from-ethiopic date))) |
|---|
| 224 |
(or noecho (calendar-print-ethiopic-date))) |
|---|
| 225 |
|
|---|
| 226 |
(defun diary-ethiopic-date () |
|---|
| 227 |
"Ethiopic calendar equivalent of date diary entry." |
|---|
| 228 |
(let ((coptic-calendar-epoch ethiopic-calendar-epoch) |
|---|
| 229 |
(coptic-name ethiopic-name) |
|---|
| 230 |
(coptic-calendar-month-name-array ethiopic-calendar-month-name-array)) |
|---|
| 231 |
(diary-coptic-date))) |
|---|
| 232 |
|
|---|
| 233 |
(provide 'cal-coptic) |
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|