annotate lisp/calendar/cal-persia.el @ 97717:8b10135f8d6c

Comments.
author Glenn Morris <rgm@gnu.org>
date Tue, 26 Aug 2008 03:03:21 +0000
parents e49abd957e81
children a9dc0e7c3f2b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 24186
diff changeset
1 ;;; cal-persia.el --- calendar functions for the Persian calendar
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
2
92606
f49e5129551f (persian-calendar-month-name-array, persian-calendar-epoch): Make constants.
Glenn Morris <rgm@gnu.org>
parents: 92591
diff changeset
3 ;; Copyright (C) 1996, 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
f49e5129551f (persian-calendar-month-name-array, persian-calendar-epoch): Make constants.
Glenn Morris <rgm@gnu.org>
parents: 92591
diff changeset
4 ;; 2008 Free Software Foundation, Inc.
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
5
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
67465
a55ee709ec8d Update copyright pending Emacs 22.
Glenn Morris <rgm@gnu.org>
parents: 65145
diff changeset
7 ;; Maintainer: Glenn Morris <rgm@gnu.org>
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
8 ;; Keywords: calendar
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
9 ;; Human-Keywords: Persian calendar, calendar, diary
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
10
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
12
94653
e49abd957e81 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93844
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
94653
e49abd957e81 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93844
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
e49abd957e81 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93844
diff changeset
16 ;; (at your option) any later version.
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
17
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
21 ;; GNU General Public License for more details.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
22
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
94653
e49abd957e81 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93844
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
25
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
26 ;;; Commentary:
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
27
93487
426872139a89 (Commentary): Point to calendar.el.
Glenn Morris <rgm@gnu.org>
parents: 93225
diff changeset
28 ;; See calendar.el.
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
29
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
30 ;;; Code:
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
31
93225
da8dabfafecc Require calendar rather than cal-julian.
Glenn Morris <rgm@gnu.org>
parents: 93186
diff changeset
32 (require 'calendar)
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
33
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
34 (defconst calendar-persian-month-name-array
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
35 ["Farvardin" "Ordibehest" "Xordad" "Tir" "Mordad" "Sahrivar" "Mehr" "Aban"
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
36 "Azar" "Dey" "Bahman" "Esfand"]
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
37 "Names of the months in the Persian calendar.")
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
38
93225
da8dabfafecc Require calendar rather than cal-julian.
Glenn Morris <rgm@gnu.org>
parents: 93186
diff changeset
39 (eval-and-compile
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
40 (autoload 'calendar-julian-to-absolute "cal-julian"))
93225
da8dabfafecc Require calendar rather than cal-julian.
Glenn Morris <rgm@gnu.org>
parents: 93186
diff changeset
41
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
42 (defconst calendar-persian-epoch
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
43 (eval-when-compile (calendar-julian-to-absolute '(3 19 622)))
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
44 "Absolute date of start of Persian calendar = March 19, 622 AD (Julian).")
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
45
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
46 (defun calendar-persian-leap-year-p (year)
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
47 "True if YEAR is a leap year on the Persian calendar."
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
48 (< (mod (* (mod (mod (if (<= 0 year)
92606
f49e5129551f (persian-calendar-month-name-array, persian-calendar-epoch): Make constants.
Glenn Morris <rgm@gnu.org>
parents: 92591
diff changeset
49 (+ year 2346) ; no year zero
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
50 (+ year 2347))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
51 2820)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
52 768)
92606
f49e5129551f (persian-calendar-month-name-array, persian-calendar-epoch): Make constants.
Glenn Morris <rgm@gnu.org>
parents: 92591
diff changeset
53 683)
f49e5129551f (persian-calendar-month-name-array, persian-calendar-epoch): Make constants.
Glenn Morris <rgm@gnu.org>
parents: 92591
diff changeset
54 2820)
f49e5129551f (persian-calendar-month-name-array, persian-calendar-epoch): Make constants.
Glenn Morris <rgm@gnu.org>
parents: 92591
diff changeset
55 683))
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
56
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
57 (defun calendar-persian-last-day-of-month (month year)
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
58 "Return last day of MONTH, YEAR on the Persian calendar."
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
59 (cond
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
60 ((< month 7) 31)
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
61 ((or (< month 12) (calendar-persian-leap-year-p year)) 30)
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
62 (t 29)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
63
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
64 (defun calendar-persian-to-absolute (date)
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
65 "Compute absolute date from Persian date DATE.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
66 The absolute date is the number of days elapsed since the (imaginary)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
67 Gregorian date Sunday, December 31, 1 BC."
93809
3ff2b47de8f2 Update for calendar.el name changes.
Glenn Morris <rgm@gnu.org>
parents: 93785
diff changeset
68 (let ((month (calendar-extract-month date))
3ff2b47de8f2 Update for calendar.el name changes.
Glenn Morris <rgm@gnu.org>
parents: 93785
diff changeset
69 (day (calendar-extract-day date))
3ff2b47de8f2 Update for calendar.el name changes.
Glenn Morris <rgm@gnu.org>
parents: 93785
diff changeset
70 (year (calendar-extract-year date)))
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
71 (if (< year 0)
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
72 (+ (calendar-persian-to-absolute
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
73 (list month day (1+ (mod year 2820))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
74 (* 1029983 (floor year 2820)))
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
75 (+ (1- calendar-persian-epoch) ; days before epoch
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
76 (* 365 (1- year)) ; days in prior years
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
77 (* 683 ; leap days in prior 2820-year cycles
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
78 (floor (+ year 2345) 2820))
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
79 (* 186 ; leap days in prior 768 year cycles
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
80 (floor (mod (+ year 2345) 2820) 768))
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
81 (floor ; leap years in current 768 or 516 year cycle
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
82 (* 683 (mod (mod (+ year 2345) 2820) 768))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
83 2820)
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
84 -568 ; leap years in Persian years -2345...-1
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
85 (calendar-sum ; days in prior months this year
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
86 m 1 (< m month)
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
87 (calendar-persian-last-day-of-month m year))
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
88 day)))) ; days so far this month
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
89
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
90 (define-obsolete-function-alias 'calendar-absolute-from-persian
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
91 'calendar-persian-to-absolute "23.1")
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
92
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
93 (defun calendar-persian-year-from-absolute (date)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
94 "Persian year corresponding to the absolute DATE."
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
95 (let* ((d0 ; prior days since start of 2820 cycles
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
96 (- date (calendar-persian-to-absolute (list 1 1 -2345))))
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
97 (n2820 ; completed 2820-year cycles
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
98 (floor d0 1029983))
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
99 (d1 ; prior days not in n2820
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
100 (mod d0 1029983))
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
101 (n768 ; 768-year cycles not in n2820
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
102 (floor d1 280506))
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
103 (d2 ; prior days not in n2820 or n768
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
104 (mod d1 280506))
92903
eaaa58ed78d4 Re-indent.
Glenn Morris <rgm@gnu.org>
parents: 92837
diff changeset
105 (n1 ; years not in n2820 or n768
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
106 ;; Want:
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
107 ;; (floor (+ (* 2820 d2) (* 2820 366)) 1029983))
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
108 ;; but that causes overflow, so use the following.
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
109 ;; Use 366 as the divisor because (2820*366 mod 1029983) is small.
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
110 (let ((a (floor d2 366))
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
111 (b (mod d2 366)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
112 (+ 1 a (floor (+ (* 2137 a) (* 2820 b) 2137) 1029983))))
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
113 (year (+ (* 2820 n2820) ; complete 2820 year cycles
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
114 (* 768 n768) ; complete 768 year cycles
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
115 ;; Remaining years.
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
116 (if (= d1 1029617) ; last day of 2820 year cycle
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
117 (1- n1)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
118 n1)
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
119 -2345))) ; years before year 1
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
120 (if (< year 1)
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
121 (1- year) ; no year zero
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
122 year)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
123
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
124 (defun calendar-persian-from-absolute (date)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
125 "Compute the Persian equivalent for absolute date DATE.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
126 The result is a list of the form (MONTH DAY YEAR).
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
127 The absolute date is the number of days elapsed since the imaginary
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
128 Gregorian date Sunday, December 31, 1 BC."
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
129 (let* ((year (calendar-persian-year-from-absolute date))
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
130 (month ; search forward from Farvardin
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
131 (1+ (calendar-sum m 1
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
132 (> date
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
133 (calendar-persian-to-absolute
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
134 (list
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
135 m
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
136 (calendar-persian-last-day-of-month m year)
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
137 year)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
138 1)))
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
139 (day ; calculate the day by subtraction
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
140 (- date (1- (calendar-persian-to-absolute
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
141 (list month 1 year))))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
142 (list month day year)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
143
92837
2bcff1e54131 (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92820
diff changeset
144 ;;;###cal-autoload
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
145 (defun calendar-persian-date-string (&optional date)
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
146 "String of Persian date of Gregorian DATE, default today."
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
147 (let* ((persian-date (calendar-persian-from-absolute
92903
eaaa58ed78d4 Re-indent.
Glenn Morris <rgm@gnu.org>
parents: 92837
diff changeset
148 (calendar-absolute-from-gregorian
eaaa58ed78d4 Re-indent.
Glenn Morris <rgm@gnu.org>
parents: 92837
diff changeset
149 (or date (calendar-current-date)))))
93809
3ff2b47de8f2 Update for calendar.el name changes.
Glenn Morris <rgm@gnu.org>
parents: 93785
diff changeset
150 (y (calendar-extract-year persian-date))
3ff2b47de8f2 Update for calendar.el name changes.
Glenn Morris <rgm@gnu.org>
parents: 93785
diff changeset
151 (m (calendar-extract-month persian-date))
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
152 (monthname (aref calendar-persian-month-name-array (1- m)))
93844
bf9ef749c23e Replace int-to-string with number-to-string.
Glenn Morris <rgm@gnu.org>
parents: 93809
diff changeset
153 (day (number-to-string (calendar-extract-day persian-date)))
bf9ef749c23e Replace int-to-string with number-to-string.
Glenn Morris <rgm@gnu.org>
parents: 93809
diff changeset
154 (year (number-to-string y))
bf9ef749c23e Replace int-to-string with number-to-string.
Glenn Morris <rgm@gnu.org>
parents: 93809
diff changeset
155 (month (number-to-string m))
93487
426872139a89 (Commentary): Point to calendar.el.
Glenn Morris <rgm@gnu.org>
parents: 93225
diff changeset
156 dayname)
426872139a89 (Commentary): Point to calendar.el.
Glenn Morris <rgm@gnu.org>
parents: 93225
diff changeset
157 (mapconcat 'eval calendar-date-display-form "")))
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
158
92837
2bcff1e54131 (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92820
diff changeset
159 ;;;###cal-autoload
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
160 (defun calendar-persian-print-date ()
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
161 "Show the Persian calendar equivalent of the selected date."
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
162 (interactive)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
163 (message "Persian date: %s"
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
164 (calendar-persian-date-string (calendar-cursor-to-date t))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
165
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
166 (define-obsolete-function-alias 'calendar-print-persian-date
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
167 'calendar-persian-print-date "23.1")
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
168
93186
3c66b698cc43 (calendar-persian-read-date): New name for persian-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents: 92903
diff changeset
169 (defun calendar-persian-read-date ()
3c66b698cc43 (calendar-persian-read-date): New name for persian-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents: 92903
diff changeset
170 "Interactively read the arguments for a Persian date command.
3c66b698cc43 (calendar-persian-read-date): New name for persian-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents: 92903
diff changeset
171 Reads a year, month, and day."
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
172 (let* ((year (calendar-read
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
173 "Persian calendar year (not 0): "
92606
f49e5129551f (persian-calendar-month-name-array, persian-calendar-epoch): Make constants.
Glenn Morris <rgm@gnu.org>
parents: 92591
diff changeset
174 (lambda (x) (not (zerop x)))
93844
bf9ef749c23e Replace int-to-string with number-to-string.
Glenn Morris <rgm@gnu.org>
parents: 93809
diff changeset
175 (number-to-string
93809
3ff2b47de8f2 Update for calendar.el name changes.
Glenn Morris <rgm@gnu.org>
parents: 93785
diff changeset
176 (calendar-extract-year
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
177 (calendar-persian-from-absolute
92820
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
178 (calendar-absolute-from-gregorian
693124d99e7c Re-format comments.
Glenn Morris <rgm@gnu.org>
parents: 92606
diff changeset
179 (calendar-current-date)))))))
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
180 (completion-ignore-case t)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
181 (month (cdr (assoc
92903
eaaa58ed78d4 Re-indent.
Glenn Morris <rgm@gnu.org>
parents: 92837
diff changeset
182 (completing-read
eaaa58ed78d4 Re-indent.
Glenn Morris <rgm@gnu.org>
parents: 92837
diff changeset
183 "Persian calendar month name: "
eaaa58ed78d4 Re-indent.
Glenn Morris <rgm@gnu.org>
parents: 92837
diff changeset
184 (mapcar 'list
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
185 (append calendar-persian-month-name-array nil))
92903
eaaa58ed78d4 Re-indent.
Glenn Morris <rgm@gnu.org>
parents: 92837
diff changeset
186 nil t)
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
187 (calendar-make-alist calendar-persian-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
188 1))))
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
189 (last (calendar-persian-last-day-of-month month year))
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
190 (day (calendar-read
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
191 (format "Persian calendar day (1-%d): " last)
92591
dc0c296afd7e Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents: 79703
diff changeset
192 (lambda (x) (and (< 0 x) (<= x last))))))
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
193 (list (list month day year))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
194
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
195 (define-obsolete-function-alias 'persian-prompt-for-date
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
196 'calendar-persian-read-date "23.1")
93186
3c66b698cc43 (calendar-persian-read-date): New name for persian-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents: 92903
diff changeset
197
3c66b698cc43 (calendar-persian-read-date): New name for persian-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents: 92903
diff changeset
198 ;;;###cal-autoload
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
199 (defun calendar-persian-goto-date (date &optional noecho)
93186
3c66b698cc43 (calendar-persian-read-date): New name for persian-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents: 92903
diff changeset
200 "Move cursor to Persian date DATE.
3c66b698cc43 (calendar-persian-read-date): New name for persian-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents: 92903
diff changeset
201 Echo Persian date unless NOECHO is non-nil."
3c66b698cc43 (calendar-persian-read-date): New name for persian-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents: 92903
diff changeset
202 (interactive (calendar-persian-read-date))
3c66b698cc43 (calendar-persian-read-date): New name for persian-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents: 92903
diff changeset
203 (calendar-goto-date (calendar-gregorian-from-absolute
93644
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
204 (calendar-persian-to-absolute date)))
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
205 (or noecho (calendar-persian-print-date)))
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
206
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
207 (define-obsolete-function-alias 'calendar-goto-persian-date
05a344ce267f Update for cal-julian name changes.
Glenn Morris <rgm@gnu.org>
parents: 93487
diff changeset
208 'calendar-persian-goto-date "23.1")
93186
3c66b698cc43 (calendar-persian-read-date): New name for persian-prompt-for-date.
Glenn Morris <rgm@gnu.org>
parents: 92903
diff changeset
209
92606
f49e5129551f (persian-calendar-month-name-array, persian-calendar-epoch): Make constants.
Glenn Morris <rgm@gnu.org>
parents: 92591
diff changeset
210 (defvar date)
f49e5129551f (persian-calendar-month-name-array, persian-calendar-epoch): Make constants.
Glenn Morris <rgm@gnu.org>
parents: 92591
diff changeset
211
93785
df192d334c0a Comment.
Glenn Morris <rgm@gnu.org>
parents: 93644
diff changeset
212 ;; To be called from diary-list-sexp-entries, where DATE is bound.
92837
2bcff1e54131 (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92820
diff changeset
213 ;;;###diary-autoload
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
214 (defun diary-persian-date ()
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
215 "Persian calendar equivalent of date diary entry."
17382
41db5b776fe4 (diary-persian-date): Use `date'.
Richard M. Stallman <rms@gnu.org>
parents: 15259
diff changeset
216 (format "Persian date: %s" (calendar-persian-date-string date)))
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
217
15259
984ea4011d7e Renamed from cal-persian.el to avoid 14-character limitation.
Karl Heuer <kwzh@gnu.org>
parents: 15070
diff changeset
218 (provide 'cal-persia)
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
219
92591
dc0c296afd7e Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents: 79703
diff changeset
220 ;; arch-tag: 2832383c-e4b4-4dc2-8ee9-cfbdd53e5e2d
15259
984ea4011d7e Renamed from cal-persian.el to avoid 14-character limitation.
Karl Heuer <kwzh@gnu.org>
parents: 15070
diff changeset
221 ;;; cal-persia.el ends here