cal-french.el 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. ;;; cal-french.el --- calendar functions for the French Revolutionary calendar
  2. ;; Copyright (C) 1988-1989, 1992, 1994-1995, 1997, 2001-2012
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
  5. ;; Maintainer: Glenn Morris <rgm@gnu.org>
  6. ;; Keywords: calendar
  7. ;; Human-Keywords: French Revolutionary calendar, calendar, diary
  8. ;; Package: calendar
  9. ;; This file is part of GNU Emacs.
  10. ;; GNU Emacs is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  20. ;;; Commentary:
  21. ;; See calendar.el.
  22. ;;; Code:
  23. (require 'calendar)
  24. (defconst calendar-french-epoch (calendar-absolute-from-gregorian '(9 22 1792))
  25. "Absolute date of start of French Revolutionary calendar = Sept 22, 1792.")
  26. (defconst calendar-french-month-name-array
  27. ["Vende'miaire" "Brumaire" "Frimaire" "Nivo^se" "Pluvio^se" "Vento^se"
  28. "Germinal" "Flore'al" "Prairial" "Messidor" "Thermidor" "Fructidor"]
  29. "Array of month names in the French calendar.")
  30. (defconst calendar-french-multibyte-month-name-array
  31. ["Vendémiaire" "Brumaire" "Frimaire" "Nivôse" "Pluviôse" "Ventôse"
  32. "Germinal" "Floréal" "Prairial" "Messidor" "Thermidor" "Fructidor"]
  33. "Array of multibyte month names in the French calendar.")
  34. (defconst calendar-french-day-name-array
  35. ["Primidi" "Duodi" "Tridi" "Quartidi" "Quintidi" "Sextidi" "Septidi"
  36. "Octidi" "Nonidi" "Decadi"]
  37. "Array of day names in the French calendar.")
  38. (defconst calendar-french-special-days-array
  39. ["de la Vertu" "du Ge'nie" "du Travail" "de la Raison" "des Re'compenses"
  40. "de la Re'volution"]
  41. "Array of special day names in the French calendar.")
  42. (defconst calendar-french-multibyte-special-days-array
  43. ["de la Vertu" "du Génie" "du Travail" "de la Raison" "des Récompenses"
  44. "de la Révolution"]
  45. "Array of multibyte special day names in the French calendar.")
  46. (defun calendar-french-accents-p ()
  47. "Return non-nil if diacritical marks are available."
  48. (and (or window-system
  49. (terminal-coding-system))
  50. (or enable-multibyte-characters
  51. (and (char-table-p standard-display-table)
  52. (equal (aref standard-display-table 161) [161])))))
  53. (defun calendar-french-month-name-array ()
  54. "Return the array of month names, depending on whether accents are available."
  55. (if (calendar-french-accents-p)
  56. calendar-french-multibyte-month-name-array
  57. calendar-french-month-name-array))
  58. (defun calendar-french-day-name-array ()
  59. "Return the array of day names."
  60. calendar-french-day-name-array)
  61. (defun calendar-french-special-days-array ()
  62. "Return the special day names, depending on whether accents are available."
  63. (if (calendar-french-accents-p)
  64. calendar-french-multibyte-special-days-array
  65. calendar-french-special-days-array))
  66. (defun calendar-french-leap-year-p (year)
  67. "True if YEAR is a leap year on the French Revolutionary calendar.
  68. For Gregorian years 1793 to 1805, the years of actual operation of the
  69. calendar, follows historical practice based on equinoxes (years 3, 7,
  70. and 11 were leap years; 15 and 20 would have been leap years). For later
  71. years uses the proposed rule of Romme (never adopted)--leap years fall every
  72. four years except century years not divisible 400 and century years that are
  73. multiples of 4000."
  74. (or (memq year '(3 7 11)) ; actual practice--based on equinoxes
  75. (memq year '(15 20)) ; anticipated practice--based on equinoxes
  76. (and (> year 20) ; Romme's proposal--never adopted
  77. (zerop (% year 4))
  78. (not (memq (% year 400) '(100 200 300)))
  79. (not (zerop (% year 4000))))))
  80. (defun calendar-french-last-day-of-month (month year)
  81. "Return last day of MONTH, YEAR on the French Revolutionary calendar.
  82. The 13th month is not really a month, but the 5 (6 in leap years) day period of
  83. `sansculottides' at the end of the year."
  84. (if (< month 13)
  85. 30
  86. (if (calendar-french-leap-year-p year)
  87. 6
  88. 5)))
  89. (defun calendar-french-to-absolute (date)
  90. "Compute absolute date from French Revolutionary date DATE.
  91. The absolute date is the number of days elapsed since the (imaginary)
  92. Gregorian date Sunday, December 31, 1 BC."
  93. (let ((month (calendar-extract-month date))
  94. (day (calendar-extract-day date))
  95. (year (calendar-extract-year date)))
  96. (+ (* 365 (1- year)) ; days in prior years
  97. ;; Leap days in prior years.
  98. (if (< year 20)
  99. (/ year 4) ; actual and anticipated practice (years 3, 7, 11, 15)
  100. ;; Romme's proposed rule (using the Principle of Inclusion/Exclusion).
  101. (+ (/ (1- year) 4) ; luckily, there were 4 leap years before year 20
  102. (- (/ (1- year) 100))
  103. (/ (1- year) 400)
  104. (- (/ (1- year) 4000))))
  105. (* 30 (1- month)) ; days in prior months this year
  106. day ; days so far this month
  107. (1- calendar-french-epoch)))) ; days before start of calendar
  108. (define-obsolete-function-alias 'calendar-absolute-from-french
  109. 'calendar-french-to-absolute "23.1")
  110. (defun calendar-french-from-absolute (date)
  111. "Compute the French Revolutionary equivalent for absolute date DATE.
  112. The result is a list of the form (MONTH DAY YEAR).
  113. The absolute date is the number of days elapsed since the
  114. \(imaginary) Gregorian date Sunday, December 31, 1 BC."
  115. (if (< date calendar-french-epoch)
  116. (list 0 0 0) ; pre-French Revolutionary date
  117. (let* ((approx ; approximation from below
  118. (/ (- date calendar-french-epoch) 366))
  119. (year ; search forward from the approximation
  120. (+ approx
  121. (calendar-sum y approx
  122. (>= date (calendar-french-to-absolute
  123. (list 1 1 (1+ y))))
  124. 1)))
  125. (month ; search forward from Vendemiaire
  126. (1+ (calendar-sum m 1
  127. (> date
  128. (calendar-french-to-absolute
  129. (list m
  130. (calendar-french-last-day-of-month
  131. m year)
  132. year)))
  133. 1)))
  134. (day ; calculate the day by subtraction
  135. (- date
  136. (1- (calendar-french-to-absolute (list month 1 year))))))
  137. (list month day year))))
  138. ;;;###cal-autoload
  139. (defun calendar-french-date-string (&optional date)
  140. "String of French Revolutionary date of Gregorian DATE.
  141. Returns the empty string if DATE is pre-French Revolutionary.
  142. Defaults to today's date if DATE is not given."
  143. (let* ((french-date (calendar-french-from-absolute
  144. (calendar-absolute-from-gregorian
  145. (or date (calendar-current-date)))))
  146. (y (calendar-extract-year french-date))
  147. (m (calendar-extract-month french-date))
  148. (d (calendar-extract-day french-date)))
  149. (cond
  150. ((< y 1) "")
  151. ((= m 13) (format (if (calendar-french-accents-p)
  152. "Jour %s de l'Année %d de la Révolution"
  153. "Jour %s de l'Anne'e %d de la Re'volution")
  154. (aref (calendar-french-special-days-array) (1- d))
  155. y))
  156. (t (format
  157. (if (calendar-french-accents-p)
  158. "%d %s an %d de la Révolution"
  159. "%d %s an %d de la Re'volution")
  160. d
  161. (aref (calendar-french-month-name-array) (1- m))
  162. y)))))
  163. ;;;###cal-autoload
  164. (defun calendar-french-print-date ()
  165. "Show the French Revolutionary calendar equivalent of the selected date."
  166. (interactive)
  167. (let ((f (calendar-french-date-string (calendar-cursor-to-date t))))
  168. (if (string-equal f "")
  169. (message "Date is pre-French Revolution")
  170. (message "French Revolutionary date: %s" f))))
  171. (define-obsolete-function-alias 'calendar-print-french-date
  172. 'calendar-french-print-date "23.1")
  173. ;;;###cal-autoload
  174. (defun calendar-french-goto-date (date &optional noecho)
  175. "Move cursor to French Revolutionary date DATE.
  176. Echo French Revolutionary date unless NOECHO is non-nil."
  177. (interactive
  178. (let* ((months (calendar-french-month-name-array))
  179. (special-days (calendar-french-special-days-array))
  180. (year (progn
  181. (calendar-read
  182. (if (calendar-french-accents-p)
  183. "Année de la Révolution (>0): "
  184. "Anne'e de la Re'volution (>0): ")
  185. (lambda (x) (> x 0))
  186. (number-to-string
  187. (calendar-extract-year
  188. (calendar-french-from-absolute
  189. (calendar-absolute-from-gregorian
  190. (calendar-current-date))))))))
  191. (month-list
  192. (mapcar 'list
  193. (append months
  194. (if (calendar-french-leap-year-p year)
  195. (mapcar
  196. (lambda (x) (concat "Jour " x))
  197. calendar-french-special-days-array)
  198. (reverse
  199. (cdr ; we don't want rev. day in a non-leap yr
  200. (reverse
  201. (mapcar
  202. (lambda (x)
  203. (concat "Jour " x))
  204. special-days))))))))
  205. (completion-ignore-case t)
  206. (month (cdr (assoc-string
  207. (completing-read
  208. "Mois ou Sansculottide: "
  209. month-list
  210. nil t)
  211. (calendar-make-alist month-list 1 'car) t)))
  212. (day (if (> month 12)
  213. (- month 12)
  214. (calendar-read
  215. "Jour (1-30): "
  216. (lambda (x) (and (<= 1 x) (<= x 30))))))
  217. (month (if (> month 12) 13 month)))
  218. (list (list month day year))))
  219. (calendar-goto-date (calendar-gregorian-from-absolute
  220. (calendar-french-to-absolute date)))
  221. (or noecho (calendar-french-print-date)))
  222. (define-obsolete-function-alias 'calendar-goto-french-date
  223. 'calendar-french-goto-date "23.1")
  224. (defvar date)
  225. ;; To be called from diary-list-sexp-entries, where DATE is bound.
  226. ;;;###diary-autoload
  227. (defun diary-french-date ()
  228. "French calendar equivalent of date diary entry."
  229. (let ((f (calendar-french-date-string date)))
  230. (if (string-equal f "")
  231. "Date is pre-French Revolution"
  232. (format "French Revolutionary date: %s" f))))
  233. (provide 'cal-french)
  234. ;; Local Variables:
  235. ;; coding: utf-8
  236. ;; End:
  237. ;;; cal-french.el ends here