2001-07-16 07:46:48 +00:00
|
|
|
;;; cal-coptic.el --- calendar functions for the Coptic/Ethiopic calendars
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2012-01-05 09:46:05 +00:00
|
|
|
;; Copyright (C) 1995, 1997, 2001-2012 Free Software Foundation, Inc.
|
1995-09-21 03:11:06 +00:00
|
|
|
|
|
|
|
;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
|
2005-12-10 05:46:09 +00:00
|
|
|
;; Maintainer: Glenn Morris <rgm@gnu.org>
|
1995-09-21 03:11:06 +00:00
|
|
|
;; Keywords: calendar
|
|
|
|
;; Human-Keywords: Coptic calendar, Ethiopic calendar, calendar, diary
|
2010-08-29 16:17:13 +00:00
|
|
|
;; Package: calendar
|
1995-09-21 03:11:06 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 03:07:58 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1995-09-21 03:11:06 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 03:07:58 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
1995-09-21 03:11:06 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 03:07:58 +00:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
1995-09-21 03:11:06 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
2008-04-01 02:39:52 +00:00
|
|
|
;; See calendar.el.
|
1997-12-16 19:12:36 +00:00
|
|
|
|
1995-09-21 03:11:06 +00:00
|
|
|
;;; Code:
|
|
|
|
|
2008-03-26 03:10:04 +00:00
|
|
|
(require 'calendar)
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-08 04:26:21 +00:00
|
|
|
;; Not constants because they get let-bound.
|
|
|
|
|
2008-04-05 19:08:04 +00:00
|
|
|
(defvar calendar-coptic-month-name-array
|
1996-02-15 15:18:38 +00:00
|
|
|
["Tut" "Babah" "Hatur" "Kiyahk" "Tubah" "Amshir" "Baramhat" "Barmundah"
|
2008-03-14 02:49:59 +00:00
|
|
|
"Bashans" "Baunah" "Abib" "Misra" "al-Nasi"]
|
|
|
|
"Array of the month names in the Coptic calendar.")
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-26 03:10:04 +00:00
|
|
|
(eval-and-compile
|
2008-04-04 07:06:53 +00:00
|
|
|
(autoload 'calendar-julian-to-absolute "cal-julian"))
|
2008-03-26 03:10:04 +00:00
|
|
|
|
2008-04-05 19:08:04 +00:00
|
|
|
(defvar calendar-coptic-epoch
|
2008-04-04 07:06:53 +00:00
|
|
|
(eval-when-compile (calendar-julian-to-absolute '(8 29 284)))
|
2008-03-15 02:58:39 +00:00
|
|
|
"Absolute date of start of Coptic calendar = August 29, 284 AD (Julian).")
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-04-05 19:08:04 +00:00
|
|
|
(defvar calendar-coptic-name "Coptic"
|
2008-03-08 04:26:21 +00:00
|
|
|
"Used in some message strings.")
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-04-05 19:08:04 +00:00
|
|
|
(defun calendar-coptic-leap-year-p (year)
|
1995-09-21 03:11:06 +00:00
|
|
|
"True if YEAR is a leap year on the Coptic calendar."
|
|
|
|
(zerop (mod (1+ year) 4)))
|
|
|
|
|
2008-04-05 19:08:04 +00:00
|
|
|
(defun calendar-coptic-last-day-of-month (month year)
|
1995-09-21 03:11:06 +00:00
|
|
|
"Return last day of MONTH, YEAR on the Coptic calendar.
|
|
|
|
The 13th month is not really a month, but the 5 (6 in leap years) day period of
|
2008-03-08 20:15:15 +00:00
|
|
|
Nisi (Kebus) at the end of the year."
|
1995-09-21 03:11:06 +00:00
|
|
|
(if (< month 13)
|
|
|
|
30
|
2008-04-05 19:08:04 +00:00
|
|
|
(if (calendar-coptic-leap-year-p year)
|
1995-09-21 03:11:06 +00:00
|
|
|
6
|
|
|
|
5)))
|
|
|
|
|
2008-04-05 19:08:04 +00:00
|
|
|
(defun calendar-coptic-to-absolute (date)
|
1995-09-21 03:11:06 +00:00
|
|
|
"Compute absolute date from Coptic date DATE.
|
|
|
|
The absolute date is the number of days elapsed since the (imaginary)
|
|
|
|
Gregorian date Sunday, December 31, 1 BC."
|
2008-04-07 01:59:37 +00:00
|
|
|
(let ((month (calendar-extract-month date))
|
|
|
|
(day (calendar-extract-day date))
|
|
|
|
(year (calendar-extract-year date)))
|
2008-04-05 19:08:04 +00:00
|
|
|
(+ (1- calendar-coptic-epoch) ; days before start of calendar
|
2008-03-14 02:49:59 +00:00
|
|
|
(* 365 (1- year)) ; days in prior years
|
|
|
|
(/ year 4) ; leap days in prior years
|
|
|
|
(* 30 (1- month)) ; days in prior months this year
|
|
|
|
day))) ; days so far this month
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-04-05 19:08:04 +00:00
|
|
|
(define-obsolete-function-alias 'calendar-absolute-from-coptic
|
|
|
|
'calendar-coptic-to-absolute "23.1")
|
|
|
|
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-coptic-from-absolute (date)
|
|
|
|
"Compute the Coptic equivalent for absolute date DATE.
|
|
|
|
The result is a list of the form (MONTH DAY YEAR).
|
|
|
|
The absolute date is the number of days elapsed since the imaginary
|
|
|
|
Gregorian date Sunday, December 31, 1 BC."
|
2008-04-05 19:08:04 +00:00
|
|
|
(if (< date calendar-coptic-epoch)
|
2008-03-08 20:15:15 +00:00
|
|
|
(list 0 0 0) ; pre-Coptic date
|
2008-04-05 19:08:04 +00:00
|
|
|
(let* ((approx (/ (- date calendar-coptic-epoch)
|
2008-03-14 02:49:59 +00:00
|
|
|
366)) ; approximation from below
|
|
|
|
(year ; search forward from the approximation
|
1995-09-21 03:11:06 +00:00
|
|
|
(+ approx
|
|
|
|
(calendar-sum y approx
|
2008-04-05 19:08:04 +00:00
|
|
|
(>= date (calendar-coptic-to-absolute
|
2008-03-14 02:49:59 +00:00
|
|
|
(list 1 1 (1+ y))))
|
|
|
|
1)))
|
2008-03-08 20:15:15 +00:00
|
|
|
(month ; search forward from Tot
|
1995-09-21 03:11:06 +00:00
|
|
|
(1+ (calendar-sum m 1
|
2008-03-14 02:49:59 +00:00
|
|
|
(> date
|
2008-04-05 19:08:04 +00:00
|
|
|
(calendar-coptic-to-absolute
|
2008-03-14 02:49:59 +00:00
|
|
|
(list m
|
2008-04-05 19:08:04 +00:00
|
|
|
(calendar-coptic-last-day-of-month m
|
2008-03-14 02:49:59 +00:00
|
|
|
year)
|
|
|
|
year)))
|
|
|
|
1)))
|
2008-03-08 20:15:15 +00:00
|
|
|
(day ; calculate the day by subtraction
|
1995-09-21 03:11:06 +00:00
|
|
|
(- date
|
2008-04-05 19:08:04 +00:00
|
|
|
(1- (calendar-coptic-to-absolute (list month 1 year))))))
|
2008-03-14 02:49:59 +00:00
|
|
|
(list month day year))))
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-13 05:41:16 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-coptic-date-string (&optional date)
|
|
|
|
"String of Coptic date of Gregorian DATE.
|
|
|
|
Returns the empty string if DATE is pre-Coptic calendar.
|
|
|
|
Defaults to today's date if DATE is not given."
|
|
|
|
(let* ((coptic-date (calendar-coptic-from-absolute
|
|
|
|
(calendar-absolute-from-gregorian
|
|
|
|
(or date (calendar-current-date)))))
|
2008-04-07 01:59:37 +00:00
|
|
|
(y (calendar-extract-year coptic-date))
|
|
|
|
(m (calendar-extract-month coptic-date)))
|
1995-09-21 03:11:06 +00:00
|
|
|
(if (< y 1)
|
|
|
|
""
|
2008-04-05 19:08:04 +00:00
|
|
|
(let ((monthname (aref calendar-coptic-month-name-array (1- m)))
|
2008-04-08 07:08:24 +00:00
|
|
|
(day (number-to-string (calendar-extract-day coptic-date)))
|
1995-09-21 03:11:06 +00:00
|
|
|
(dayname nil)
|
2008-04-08 07:08:24 +00:00
|
|
|
(month (number-to-string m))
|
|
|
|
(year (number-to-string y)))
|
1995-09-21 03:11:06 +00:00
|
|
|
(mapconcat 'eval calendar-date-display-form "")))))
|
|
|
|
|
2008-03-13 05:41:16 +00:00
|
|
|
;;;###cal-autoload
|
2008-04-05 19:08:04 +00:00
|
|
|
(defun calendar-coptic-print-date ()
|
1995-09-21 03:11:06 +00:00
|
|
|
"Show the Coptic calendar equivalent of the selected date."
|
|
|
|
(interactive)
|
|
|
|
(let ((f (calendar-coptic-date-string (calendar-cursor-to-date t))))
|
|
|
|
(if (string-equal f "")
|
2008-04-05 19:08:04 +00:00
|
|
|
(message "Date is pre-%s calendar" calendar-coptic-name)
|
|
|
|
(message "%s date: %s" calendar-coptic-name f))))
|
|
|
|
|
|
|
|
(define-obsolete-function-alias 'calendar-print-coptic-date
|
|
|
|
'calendar-coptic-print-date "23.1")
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-25 03:40:53 +00:00
|
|
|
(defun calendar-coptic-read-date ()
|
|
|
|
"Interactively read the arguments for a Coptic date command.
|
|
|
|
Reads a year, month, and day."
|
1995-09-21 03:11:06 +00:00
|
|
|
(let* ((today (calendar-current-date))
|
|
|
|
(year (calendar-read
|
2008-04-05 19:08:04 +00:00
|
|
|
(format "%s calendar year (>0): " calendar-coptic-name)
|
2008-03-08 03:40:14 +00:00
|
|
|
(lambda (x) (> x 0))
|
2008-04-08 07:08:24 +00:00
|
|
|
(number-to-string
|
2008-04-07 01:59:37 +00:00
|
|
|
(calendar-extract-year
|
1995-09-21 03:11:06 +00:00
|
|
|
(calendar-coptic-from-absolute
|
|
|
|
(calendar-absolute-from-gregorian today))))))
|
|
|
|
(completion-ignore-case t)
|
2004-02-19 01:15:03 +00:00
|
|
|
(month (cdr (assoc-string
|
1999-01-26 01:31:29 +00:00
|
|
|
(completing-read
|
2008-04-05 19:08:04 +00:00
|
|
|
(format "%s calendar month name: " calendar-coptic-name)
|
1999-01-26 01:31:29 +00:00
|
|
|
(mapcar 'list
|
2008-04-05 19:08:04 +00:00
|
|
|
(append calendar-coptic-month-name-array nil))
|
1999-01-26 01:31:29 +00:00
|
|
|
nil t)
|
2008-04-05 19:08:04 +00:00
|
|
|
(calendar-make-alist calendar-coptic-month-name-array
|
2004-02-19 01:15:03 +00:00
|
|
|
1) t)))
|
2008-04-05 19:08:04 +00:00
|
|
|
(last (calendar-coptic-last-day-of-month month year))
|
1995-09-21 03:11:06 +00:00
|
|
|
(day (calendar-read
|
2008-04-05 19:08:04 +00:00
|
|
|
(format "%s calendar day (1-%d): " calendar-coptic-name last)
|
2008-03-08 03:40:14 +00:00
|
|
|
(lambda (x) (and (< 0 x) (<= x last))))))
|
1995-09-21 03:11:06 +00:00
|
|
|
(list (list month day year))))
|
|
|
|
|
2008-04-05 19:08:04 +00:00
|
|
|
(define-obsolete-function-alias 'coptic-prompt-for-date
|
|
|
|
'calendar-coptic-read-date "23.1")
|
2008-03-25 03:40:53 +00:00
|
|
|
|
2008-03-14 02:49:59 +00:00
|
|
|
;;;###cal-autoload
|
2008-04-05 19:08:04 +00:00
|
|
|
(defun calendar-coptic-goto-date (date &optional noecho)
|
2008-03-14 02:49:59 +00:00
|
|
|
"Move cursor to Coptic date DATE.
|
|
|
|
Echo Coptic date unless NOECHO is t."
|
2008-03-25 03:40:53 +00:00
|
|
|
(interactive (calendar-coptic-read-date))
|
2008-03-14 02:49:59 +00:00
|
|
|
(calendar-goto-date (calendar-gregorian-from-absolute
|
2008-04-05 19:08:04 +00:00
|
|
|
(calendar-coptic-to-absolute date)))
|
|
|
|
(or noecho (calendar-coptic-print-date)))
|
|
|
|
|
|
|
|
(define-obsolete-function-alias 'calendar-goto-coptic-date
|
|
|
|
'calendar-coptic-goto-date "23.1")
|
2008-03-14 02:49:59 +00:00
|
|
|
|
2008-03-08 19:50:37 +00:00
|
|
|
(defvar date)
|
|
|
|
|
2008-04-06 20:49:40 +00:00
|
|
|
;; To be called from diary-list-sexp-entries, where DATE is bound.
|
2008-03-13 05:41:16 +00:00
|
|
|
;;;###diary-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun diary-coptic-date ()
|
|
|
|
"Coptic calendar equivalent of date diary entry."
|
1997-04-11 02:35:08 +00:00
|
|
|
(let ((f (calendar-coptic-date-string date)))
|
1995-09-21 03:11:06 +00:00
|
|
|
(if (string-equal f "")
|
2008-04-05 19:08:04 +00:00
|
|
|
(format "Date is pre-%s calendar" calendar-coptic-name)
|
|
|
|
(format "%s date: %s" calendar-coptic-name f))))
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-04-05 19:08:04 +00:00
|
|
|
(defconst calendar-ethiopic-month-name-array
|
1996-02-15 15:18:38 +00:00
|
|
|
["Maskaram" "Teqemt" "Khedar" "Takhsas" "Ter" "Yakatit" "Magabit" "Miyazya"
|
2008-03-14 02:49:59 +00:00
|
|
|
"Genbot" "Sane" "Hamle" "Nahas" "Paguem"]
|
|
|
|
"Array of the month names in the Ethiopic calendar.")
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-04-05 19:08:04 +00:00
|
|
|
(defconst calendar-ethiopic-epoch 2796
|
1997-11-03 02:57:05 +00:00
|
|
|
"Absolute date of start of Ethiopic calendar = August 29, 8 C.E. (Julian).")
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-04-05 19:08:04 +00:00
|
|
|
(defconst calendar-ethiopic-name "Ethiopic"
|
2008-03-14 02:49:59 +00:00
|
|
|
"Used in some message strings.")
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-04-05 19:08:04 +00:00
|
|
|
(defun calendar-ethiopic-to-absolute (date)
|
1995-09-21 03:11:06 +00:00
|
|
|
"Compute absolute date from Ethiopic date DATE.
|
|
|
|
The absolute date is the number of days elapsed since the (imaginary)
|
|
|
|
Gregorian date Sunday, December 31, 1 BC."
|
2008-04-05 19:08:04 +00:00
|
|
|
(let ((calendar-coptic-epoch calendar-ethiopic-epoch))
|
|
|
|
(calendar-coptic-to-absolute date)))
|
|
|
|
|
|
|
|
(define-obsolete-function-alias 'calendar-absolute-from-ethiopic
|
|
|
|
'calendar-ethiopic-to-absolute "23.1")
|
1995-09-21 03:11:06 +00:00
|
|
|
|
|
|
|
(defun calendar-ethiopic-from-absolute (date)
|
|
|
|
"Compute the Ethiopic equivalent for absolute date DATE.
|
|
|
|
The result is a list of the form (MONTH DAY YEAR).
|
|
|
|
The absolute date is the number of days elapsed since the imaginary
|
|
|
|
Gregorian date Sunday, December 31, 1 BC."
|
2008-04-05 19:08:04 +00:00
|
|
|
(let ((calendar-coptic-epoch calendar-ethiopic-epoch))
|
1995-09-21 03:11:06 +00:00
|
|
|
(calendar-coptic-from-absolute date)))
|
|
|
|
|
2008-03-13 05:41:16 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-ethiopic-date-string (&optional date)
|
|
|
|
"String of Ethiopic date of Gregorian DATE.
|
|
|
|
Returns the empty string if DATE is pre-Ethiopic calendar.
|
|
|
|
Defaults to today's date if DATE is not given."
|
2008-04-05 19:08:04 +00:00
|
|
|
(let ((calendar-coptic-epoch calendar-ethiopic-epoch)
|
|
|
|
(calendar-coptic-name calendar-ethiopic-name)
|
|
|
|
(calendar-coptic-month-name-array calendar-ethiopic-month-name-array))
|
1995-09-21 03:11:06 +00:00
|
|
|
(calendar-coptic-date-string date)))
|
|
|
|
|
2008-03-13 05:41:16 +00:00
|
|
|
;;;###cal-autoload
|
2008-04-05 19:08:04 +00:00
|
|
|
(defun calendar-ethiopic-print-date ()
|
1995-09-21 03:11:06 +00:00
|
|
|
"Show the Ethiopic calendar equivalent of the selected date."
|
|
|
|
(interactive)
|
2008-04-05 19:08:04 +00:00
|
|
|
(let ((calendar-coptic-epoch calendar-ethiopic-epoch)
|
|
|
|
(calendar-coptic-name calendar-ethiopic-name)
|
|
|
|
(calendar-coptic-month-name-array calendar-ethiopic-month-name-array))
|
|
|
|
(call-interactively 'calendar-coptic-print-date)))
|
|
|
|
|
|
|
|
(define-obsolete-function-alias 'calendar-print-ethiopic-date
|
|
|
|
'calendar-ethiopic-print-date "23.1")
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-13 05:41:16 +00:00
|
|
|
;;;###cal-autoload
|
2008-04-05 19:08:04 +00:00
|
|
|
(defun calendar-ethiopic-goto-date (date &optional noecho)
|
1995-09-21 03:11:06 +00:00
|
|
|
"Move cursor to Ethiopic date DATE.
|
|
|
|
Echo Ethiopic date unless NOECHO is t."
|
|
|
|
(interactive
|
2008-04-05 19:08:04 +00:00
|
|
|
(let ((calendar-coptic-epoch calendar-ethiopic-epoch)
|
|
|
|
(calendar-coptic-name calendar-ethiopic-name)
|
|
|
|
(calendar-coptic-month-name-array calendar-ethiopic-month-name-array))
|
2008-03-25 03:40:53 +00:00
|
|
|
(calendar-coptic-read-date)))
|
1995-09-21 03:11:06 +00:00
|
|
|
(calendar-goto-date (calendar-gregorian-from-absolute
|
2008-04-05 19:08:04 +00:00
|
|
|
(calendar-ethiopic-to-absolute date)))
|
|
|
|
(or noecho (calendar-ethiopic-print-date)))
|
|
|
|
|
|
|
|
(define-obsolete-function-alias 'calendar-goto-ethiopic-date
|
|
|
|
'calendar-ethiopic-goto-date "23.1")
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-04-06 20:49:40 +00:00
|
|
|
;; To be called from diary-list-sexp-entries, where DATE is bound.
|
2008-03-13 05:41:16 +00:00
|
|
|
;;;###diary-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun diary-ethiopic-date ()
|
|
|
|
"Ethiopic calendar equivalent of date diary entry."
|
2008-04-05 19:08:04 +00:00
|
|
|
(let ((calendar-coptic-epoch calendar-ethiopic-epoch)
|
|
|
|
(calendar-coptic-name calendar-ethiopic-name)
|
|
|
|
(calendar-coptic-month-name-array calendar-ethiopic-month-name-array))
|
1995-09-21 03:11:06 +00:00
|
|
|
(diary-coptic-date)))
|
|
|
|
|
|
|
|
(provide 'cal-coptic)
|
|
|
|
|
|
|
|
;;; cal-coptic.el ends here
|