Mercurial > emacs
annotate lisp/calendar/cal-persia.el @ 30929:3d5ccbaddc59
Set to standard author/maintainer/keyword fields.
Fine tuning to menu map appearance and operation, and added help.
Remove `start' and `end' error messages when compiling.
(ispell-choices-win-default-height): Fixed comment string.
(ispell-dictionary-alist-1): Fixed regexp in castellano and
castellano8 dictionaries.
(ispell-dictionary-alist-3): Fixed regexp in francais dictionary.
(ispell-dictionary-alist-4): Fixed regexp in francais-tex
dictionary, added italiano dictionary.
(ispell-skip-region-alist): Removed regexp thrashing when `-' is a
word character
(ispell-tex-skip-alists): Added psfig support.
(ispell-skip-html): Renamed from ispell-skip-sgml.
(ispell-begin-skip-region-regexp, ispell-skip-region)
(ispell-minor-check): Improved html skipping support to skip across
code, and recognize `&' commands without propper `;' syntax;
(ispell-process-line): Fix alignment error when manually
correcting spelling.
(ispell): Fix comment string.
(ispell-add-per-file-word-list): Always put word list on new line.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Thu, 17 Aug 2000 20:54:01 +0000 |
parents | 8aae7db1922c |
children | 7a94f1c588c4 |
rev | line source |
---|---|
15259
984ea4011d7e
Renamed from cal-persian.el to avoid 14-character limitation.
Karl Heuer <kwzh@gnu.org>
parents:
15070
diff
changeset
|
1 ;;; cal-persia.el --- calendar functions for the Persian calendar. |
14914 | 2 |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17382
diff
changeset
|
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc. |
14914 | 4 |
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> | |
6 ;; Keywords: calendar | |
7 ;; Human-Keywords: Persian 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 | |
15070
ec84bec5804e
Update some comments.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14914
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
ec84bec5804e
Update some comments.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14914
diff
changeset
|
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ec84bec5804e
Update some comments.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14914
diff
changeset
|
24 ;; Boston, MA 02111-1307, USA. |
14914 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; This collection of functions implements the features of calendar.el and | |
29 ;; diary.el that deal with the Persian calendar. | |
30 | |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17382
diff
changeset
|
31 ;; Technical details of all the calendrical calculations can be found in |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17382
diff
changeset
|
32 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold, |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17382
diff
changeset
|
33 ;; Cambridge University Press (1997). |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17382
diff
changeset
|
34 |
14914 | 35 ;; Comments, corrections, and improvements should be sent to |
36 ;; Edward M. Reingold Department of Computer Science | |
37 ;; (217) 333-6733 University of Illinois at Urbana-Champaign | |
38 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue | |
39 ;; Urbana, Illinois 61801 | |
40 | |
41 ;;; Code: | |
42 | |
43 (require 'cal-julian) | |
44 | |
45 (defvar persian-calendar-month-name-array | |
46 ["Farvardin" "Ordibehest" "Xordad" "Tir" "Mordad" "Sahrivar" "Mehr" "Aban" | |
47 "Azar" "Dey" "Bahman" "Esfand"]) | |
48 | |
49 (defvar persian-calendar-epoch (calendar-absolute-from-julian '(3 19 622)) | |
50 "Absolute date of start of Persian calendar = March 19, 622 A.D. (Julian).") | |
51 | |
52 (defun persian-calendar-leap-year-p (year) | |
53 "True if YEAR is a leap year on the Persian calendar." | |
54 (< (mod (* (mod (mod (if (<= 0 year) | |
55 ; No year zero | |
56 (+ year 2346) | |
57 (+ year 2347)) | |
58 2820) | |
59 768) | |
60 683) | |
61 2820) | |
62 683)) | |
63 | |
64 (defun persian-calendar-last-day-of-month (month year) | |
65 "Return last day of MONTH, YEAR on the Persian calendar." | |
66 (cond | |
67 ((< month 7) 31) | |
68 ((or (< month 12) (persian-calendar-leap-year-p year)) 30) | |
69 (t 29))) | |
70 | |
71 (defun calendar-absolute-from-persian (date) | |
72 "Compute absolute date from Persian date DATE. | |
73 The absolute date is the number of days elapsed since the (imaginary) | |
74 Gregorian date Sunday, December 31, 1 BC." | |
75 (let ((month (extract-calendar-month date)) | |
76 (day (extract-calendar-day date)) | |
77 (year (extract-calendar-year date))) | |
78 (if (< year 0) | |
79 (+ (calendar-absolute-from-persian | |
80 (list month day (1+ (mod year 2820)))) | |
81 (* 1029983 (floor year 2820))) | |
82 (+ (1- persian-calendar-epoch); Days before epoch | |
83 (* 365 (1- year)) ; Days in prior years. | |
84 (* 683 ; Leap days in prior 2820-year cycles | |
85 (floor (+ year 2345) 2820)) | |
86 (* 186 ; Leap days in prior 768 year cycles | |
87 (floor (mod (+ year 2345) 2820) 768)) | |
88 (floor; Leap years in current 768 or 516 year cycle | |
89 (* 683 (mod (mod (+ year 2345) 2820) 768)) | |
90 2820) | |
91 -568 ; Leap years in Persian years -2345...-1 | |
92 (calendar-sum ; Days in prior months this year. | |
93 m 1 (< m month) | |
94 (persian-calendar-last-day-of-month m year)) | |
95 day)))) ; Days so far this month. | |
96 | |
97 (defun calendar-persian-year-from-absolute (date) | |
98 "Persian year corresponding to the absolute DATE." | |
99 (let* ((d0 ; Prior days since start of 2820 cycles | |
100 (- date (calendar-absolute-from-persian (list 1 1 -2345)))) | |
101 (n2820 ; Completed 2820-year cycles | |
102 (floor d0 1029983)) | |
103 (d1 ; Prior days not in n2820 | |
104 (mod d0 1029983)) | |
105 (n768 ; 768-year cycles not in n2820 | |
106 (floor d1 280506)) | |
107 (d2 ; Prior days not in n2820 or n768 | |
108 (mod d1 280506)) | |
109 (n1 ; Years not in n2820 or n768 | |
110 ; we want is | |
111 ; (floor (+ (* 2820 d2) (* 2820 366)) 1029983)) | |
112 ; but that causes overflow, so we use | |
113 (let ((a (floor d2 366)); we use 366 as the divisor because | |
114 ; (2820*366 mod 1029983) is small | |
115 (b (mod d2 366))) | |
116 (+ 1 a (floor (+ (* 2137 a) (* 2820 b) 2137) 1029983)))) | |
117 (year (+ (* 2820 n2820); Complete 2820 year cycles | |
118 (* 768 n768) ; Complete 768 year cycles | |
119 (if ; Remaining years | |
120 ; Last day of 2820 year cycle | |
121 (= d1 1029617) | |
122 (1- n1) | |
123 n1) | |
124 -2345))) ; Years before year 1 | |
125 (if (< year 1) | |
126 (1- year); No year zero | |
127 year))) | |
128 | |
129 (defun calendar-persian-from-absolute (date) | |
130 "Compute the Persian equivalent for absolute date DATE. | |
131 The result is a list of the form (MONTH DAY YEAR). | |
132 The absolute date is the number of days elapsed since the imaginary | |
133 Gregorian date Sunday, December 31, 1 BC." | |
134 (let* ((year (calendar-persian-year-from-absolute date)) | |
135 (month ; Search forward from Farvardin | |
136 (1+ (calendar-sum m 1 | |
137 (> date | |
138 (calendar-absolute-from-persian | |
139 (list | |
140 m | |
141 (persian-calendar-last-day-of-month m year) | |
142 year))) | |
143 1))) | |
144 (day ; Calculate the day by subtraction | |
145 (- date (1- (calendar-absolute-from-persian | |
146 (list month 1 year)))))) | |
147 (list month day year))) | |
148 | |
149 (defun calendar-persian-date-string (&optional date) | |
150 "String of Persian date of Gregorian DATE. | |
151 Defaults to today's date if DATE is not given." | |
152 (let* ((persian-date (calendar-persian-from-absolute | |
153 (calendar-absolute-from-gregorian | |
154 (or date (calendar-current-date))))) | |
155 (y (extract-calendar-year persian-date)) | |
156 (m (extract-calendar-month persian-date))) | |
157 (let ((monthname (aref persian-calendar-month-name-array (1- m))) | |
158 (day (int-to-string (extract-calendar-day persian-date))) | |
159 (dayname nil) | |
160 (month (int-to-string m)) | |
161 (year (int-to-string y))) | |
162 (mapconcat 'eval calendar-date-display-form "")))) | |
163 | |
164 (defun calendar-print-persian-date () | |
165 "Show the Persian calendar equivalent of the selected date." | |
166 (interactive) | |
167 (message "Persian date: %s" | |
168 (calendar-persian-date-string (calendar-cursor-to-date t)))) | |
169 | |
170 (defun calendar-goto-persian-date (date &optional noecho) | |
171 "Move cursor to Persian date DATE. | |
172 Echo Persian date unless NOECHO is t." | |
173 (interactive (persian-prompt-for-date)) | |
174 (calendar-goto-date (calendar-gregorian-from-absolute | |
175 (calendar-absolute-from-persian date))) | |
176 (or noecho (calendar-print-persian-date))) | |
177 | |
178 (defun persian-prompt-for-date () | |
179 "Ask for a Persian date." | |
180 (let* ((today (calendar-current-date)) | |
181 (year (calendar-read | |
182 "Persian calendar year (not 0): " | |
183 '(lambda (x) (/= x 0)) | |
184 (int-to-string | |
185 (extract-calendar-year | |
186 (calendar-persian-from-absolute | |
187 (calendar-absolute-from-gregorian today)))))) | |
188 (completion-ignore-case t) | |
189 (month (cdr (assoc | |
190 (completing-read | |
191 "Persian calendar month name: " | |
192 (mapcar 'list | |
193 (append persian-calendar-month-name-array nil)) | |
24186
8aae7db1922c
(persian-prompt-for-date): Use assoc-ignore-case and do not capitalize
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
194 nil t) |
14914 | 195 (calendar-make-alist persian-calendar-month-name-array |
24186
8aae7db1922c
(persian-prompt-for-date): Use assoc-ignore-case and do not capitalize
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
196 1)))) |
14914 | 197 (last (persian-calendar-last-day-of-month month year)) |
198 (day (calendar-read | |
199 (format "Persian calendar day (1-%d): " last) | |
200 '(lambda (x) (and (< 0 x) (<= x last)))))) | |
201 (list (list month day year)))) | |
202 | |
203 (defun diary-persian-date () | |
204 "Persian calendar equivalent of date diary entry." | |
17382
41db5b776fe4
(diary-persian-date): Use `date'.
Richard M. Stallman <rms@gnu.org>
parents:
15259
diff
changeset
|
205 (format "Persian date: %s" (calendar-persian-date-string date))) |
14914 | 206 |
15259
984ea4011d7e
Renamed from cal-persian.el to avoid 14-character limitation.
Karl Heuer <kwzh@gnu.org>
parents:
15070
diff
changeset
|
207 (provide 'cal-persia) |
14914 | 208 |
15259
984ea4011d7e
Renamed from cal-persian.el to avoid 14-character limitation.
Karl Heuer <kwzh@gnu.org>
parents:
15070
diff
changeset
|
209 ;;; cal-persia.el ends here |