]> code.delx.au - gnu-emacs/blob - lisp/calendar/cal-french.el
(makefile-insert-special-target,
[gnu-emacs] / lisp / calendar / cal-french.el
1 ;;; cal-french.el --- calendar functions for the French Revolutionary calendar.
2
3 ;; Copyright (C) 1988, 1989, 1992, 1994, 1995 Free Software Foundation, Inc.
4
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
6 ;; Keywords: calendar
7 ;; Human-Keywords: French Revolutionary 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
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
25 ;;; Commentary:
26
27 ;; This collection of functions implements the features of calendar.el and
28 ;; diary.el that deal with the French Revolutionary calendar.
29
30 ;; Technical details of the French Revolutionary calendar can be found in
31 ;; ``Calendrical Calculations, Part II: Three Historical Calendars''
32 ;; by E. M. Reingold, N. Dershowitz, and S. M. Clamen,
33 ;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993),
34 ;; pages 383-404.
35
36 ;; Comments, corrections, and improvements should be sent to
37 ;; Edward M. Reingold Department of Computer Science
38 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
39 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
40 ;; Urbana, Illinois 61801
41
42 ;;; Code:
43
44 (require 'calendar)
45
46 (defconst french-calendar-epoch (calendar-absolute-from-gregorian '(9 22 1792))
47 "Absolute date of start of French Revolutionary calendar = September 22, 1792.")
48
49 (defconst french-calendar-month-name-array
50 ["Vende'miaire" "Brumaire" "Frimaire" "Nivo^se" "Pluvio^se" "Vento^se"
51 "Germinal" "Flore'al" "Prairial" "Messidor" "Thermidor" "Fructidor"])
52
53 (defconst french-calendar-day-name-array
54 ["Primidi" "Duodi" "Tridi" "Quartidi" "Quintidi" "Sextidi" "Septidi"
55 "Octidi" "Nonidi" "Decadi"])
56
57 (defconst french-calendar-special-days-array
58 ["de la Vertu" "du Genie" "du Labour" "de la Raison" "de la Re'compense"
59 "de la Re'volution"])
60
61 (defun french-calendar-leap-year-p (year)
62 "True if YEAR is a leap year on the French Revolutionary calendar.
63 For Gregorian years 1793 to 1805, the years of actual operation of the
64 calendar, uses historical practice based on equinoxes is followed (years 3, 7,
65 and 11 were leap years; 15 and 20 would have been leap years). For later
66 years uses the proposed rule of Romme (never adopted)--leap years fall every
67 four years except century years not divisible 400 and century years that are
68 multiples of 4000."
69 (or (memq year '(3 7 11));; Actual practice--based on equinoxes
70 (memq year '(15 20)) ;; Anticipated practice--based on equinoxes
71 (and (> year 20) ;; Romme's proposal--never adopted
72 (zerop (% year 4))
73 (not (memq (% year 400) '(100 200 300)))
74 (not (zerop (% year 4000))))))
75
76 (defun french-calendar-last-day-of-month (month year)
77 "Return last day of MONTH, YEAR on the French Revolutionary calendar.
78 The 13th month is not really a month, but the 5 (6 in leap years) day period of
79 `sansculottides' at the end of the year."
80 (if (< month 13)
81 30
82 (if (french-calendar-leap-year-p year)
83 6
84 5)))
85
86 (defun calendar-absolute-from-french (date)
87 "Compute absolute date from French Revolutionary date DATE.
88 The absolute date is the number of days elapsed since the (imaginary)
89 Gregorian date Sunday, December 31, 1 BC."
90 (let ((month (extract-calendar-month date))
91 (day (extract-calendar-day date))
92 (year (extract-calendar-year date)))
93 (+ (* 365 (1- year));; Days in prior years
94 ;; Leap days in prior years
95 (if (< year 20)
96 (/ year 4);; Actual and anticipated practice (years 3, 7, 11, 15)
97 ;; Romme's proposed rule (using the Principle of Inclusion/Exclusion)
98 (+ (/ (1- year) 4);; Luckily, there were 4 leap years before year 20
99 (- (/ (1- year) 100))
100 (/ (1- year) 400)
101 (- (/ (1- year) 4000))))
102 (* 30 (1- month));; Days in prior months this year
103 day;; Days so far this month
104 (1- french-calendar-epoch))));; Days before start of calendar
105
106 (defun calendar-french-from-absolute (date)
107 "Compute the French Revolutionary equivalent for absolute date DATE.
108 The result is a list of the form (MONTH DAY YEAR).
109 The absolute date is the number of days elapsed since the
110 \(imaginary) Gregorian date Sunday, December 31, 1 BC."
111 (if (< date french-calendar-epoch)
112 (list 0 0 0);; pre-French Revolutionary date
113 (let* ((approx ;; Approximation from below.
114 (/ (- date french-calendar-epoch) 366))
115 (year ;; Search forward from the approximation.
116 (+ approx
117 (calendar-sum y approx
118 (>= date (calendar-absolute-from-french (list 1 1 (1+ y))))
119 1)))
120 (month ;; Search forward from Vendemiaire.
121 (1+ (calendar-sum m 1
122 (> date
123 (calendar-absolute-from-french
124 (list m
125 (french-calendar-last-day-of-month m year)
126 year)))
127 1)))
128 (day ;; Calculate the day by subtraction.
129 (- date
130 (1- (calendar-absolute-from-french (list month 1 year))))))
131 (list month day year))))
132
133 (defun calendar-french-date-string (&optional date)
134 "String of French Revolutionary date of Gregorian DATE.
135 Returns the empty string if DATE is pre-French Revolutionary.
136 Defaults to today's date if DATE is not given."
137 (let* ((french-date (calendar-french-from-absolute
138 (calendar-absolute-from-gregorian
139 (or date (calendar-current-date)))))
140 (y (extract-calendar-year french-date))
141 (m (extract-calendar-month french-date))
142 (d (extract-calendar-day french-date)))
143 (cond
144 ((< y 1) "")
145 ((= m 13) (format "Jour %s de l'Anne'e %d de la Re'volution"
146 (aref french-calendar-special-days-array (1- d))
147 y))
148 (t (format "De'cade %s, %s de %s de l'Anne'e %d de la Re'volution"
149 (make-string (1+ (/ (1- d) 10)) ?I)
150 (aref french-calendar-day-name-array (% (1- d) 10))
151 (aref french-calendar-month-name-array (1- m))
152 y)))))
153
154 (defun calendar-print-french-date ()
155 "Show the French Revolutionary calendar equivalent of the selected date."
156 (interactive)
157 (let ((f (calendar-french-date-string (calendar-cursor-to-date t))))
158 (if (string-equal f "")
159 (message "Date is pre-French Revolution")
160 (message f))))
161
162 (defun calendar-goto-french-date (date &optional noecho)
163 "Move cursor to French Revolutionary date DATE.
164 Echo French Revolutionary date unless NOECHO is t."
165 (interactive
166 (let* ((year (calendar-read
167 "Anne'e de la Re'volution (>0): "
168 '(lambda (x) (> x 0))
169 (int-to-string
170 (extract-calendar-year
171 (calendar-french-from-absolute
172 (calendar-absolute-from-gregorian
173 (calendar-current-date)))))))
174 (month-list
175 (mapcar 'list
176 (append french-calendar-month-name-array
177 (if (french-calendar-leap-year-p year)
178 (mapcar
179 '(lambda (x) (concat "Jour " x))
180 french-calendar-special-days-array)
181 (reverse
182 (cdr;; we don't want rev. day in a non-leap yr.
183 (reverse
184 (mapcar
185 '(lambda (x) (concat "Jour " x))
186 french-calendar-special-days-array))))))))
187 (completion-ignore-case t)
188 (month (cdr (assoc
189 (capitalize
190 (completing-read
191 "Mois ou Sansculottide: "
192 month-list
193 nil t))
194 (calendar-make-alist
195 month-list
196 1
197 '(lambda (x) (capitalize (car x)))))))
198 (decade (if (> month 12)
199 1
200 (calendar-read
201 "De'cade (1-3): "
202 '(lambda (x) (memq x '(1 2 3))))))
203 (day (if (> month 12)
204 (- month 12)
205 (calendar-read
206 "Jour (1-10): "
207 '(lambda (x) (and (<= 1 x) (<= x 10))))))
208 (month (if (> month 12) 13 month))
209 (day (+ day (* 10 (1- decade)))))
210 (list (list month day year))))
211 (calendar-goto-date (calendar-gregorian-from-absolute
212 (calendar-absolute-from-french date)))
213 (or noecho (calendar-print-french-date)))
214
215 (defun diary-french-date ()
216 "French calendar equivalent of date diary entry."
217 (let ((f (calendar-french-date-string (calendar-cursor-to-date t))))
218 (if (string-equal f "")
219 "Date is pre-French Revolution"
220 f)))
221
222 (provide 'cal-french)
223
224 ;;; cal-french.el ends here