annotate lisp/calendar/cal-persia.el @ 17744:2522a70cd009

(custom-make-dependencies): Don't find the subdirs here; instead, use the dirs specified on the command line.
author Richard M. Stallman <rms@gnu.org>
date Mon, 12 May 1997 00:46:59 +0000
parents 41db5b776fe4
children d179de7ad92e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
2
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
4
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
6 ;; Keywords: calendar
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
7 ;; Human-Keywords: Persian calendar, calendar, diary
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
8
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
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 ;; GNU Emacs is free software; you can redistribute it and/or modify
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
14 ;; any later version.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
15
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
16 ;; 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
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
19 ;; GNU General Public License for more details.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
20
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
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
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
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
28 ;; This collection of functions implements the features of calendar.el and
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
29 ;; diary.el that deal with the Persian calendar.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
30
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
31 ;; Comments, corrections, and improvements should be sent to
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
32 ;; Edward M. Reingold Department of Computer Science
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
33 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
34 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
35 ;; Urbana, Illinois 61801
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
36
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
37 ;;; Code:
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
38
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
39 (require 'cal-julian)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
40
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
41 (defvar persian-calendar-month-name-array
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
42 ["Farvardin" "Ordibehest" "Xordad" "Tir" "Mordad" "Sahrivar" "Mehr" "Aban"
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
43 "Azar" "Dey" "Bahman" "Esfand"])
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
44
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
45 (defvar persian-calendar-epoch (calendar-absolute-from-julian '(3 19 622))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
46 "Absolute date of start of Persian calendar = March 19, 622 A.D. (Julian).")
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
47
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
48 (defun persian-calendar-leap-year-p (year)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
49 "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
50 (< (mod (* (mod (mod (if (<= 0 year)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
51 ; No year zero
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
52 (+ year 2346)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
53 (+ year 2347))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
54 2820)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
55 768)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
56 683)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
57 2820)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
58 683))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
59
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
60 (defun persian-calendar-last-day-of-month (month year)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
61 "Return last day of MONTH, YEAR on the Persian calendar."
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
62 (cond
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
63 ((< month 7) 31)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
64 ((or (< month 12) (persian-calendar-leap-year-p year)) 30)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
65 (t 29)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
66
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
67 (defun calendar-absolute-from-persian (date)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
68 "Compute absolute date from Persian date DATE.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
69 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
70 Gregorian date Sunday, December 31, 1 BC."
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
71 (let ((month (extract-calendar-month date))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
72 (day (extract-calendar-day date))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
73 (year (extract-calendar-year date)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
74 (if (< year 0)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
75 (+ (calendar-absolute-from-persian
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
76 (list month day (1+ (mod year 2820))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
77 (* 1029983 (floor year 2820)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
78 (+ (1- persian-calendar-epoch); Days before epoch
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
79 (* 365 (1- year)) ; Days in prior years.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
80 (* 683 ; Leap days in prior 2820-year cycles
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
81 (floor (+ year 2345) 2820))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
82 (* 186 ; Leap days in prior 768 year cycles
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
83 (floor (mod (+ year 2345) 2820) 768))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
84 (floor; Leap years in current 768 or 516 year cycle
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
85 (* 683 (mod (mod (+ year 2345) 2820) 768))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
86 2820)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
87 -568 ; Leap years in Persian years -2345...-1
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
88 (calendar-sum ; Days in prior months this year.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
89 m 1 (< m month)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
90 (persian-calendar-last-day-of-month m year))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
91 day)))) ; Days so far this month.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
92
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."
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
95 (let* ((d0 ; Prior days since start of 2820 cycles
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
96 (- date (calendar-absolute-from-persian (list 1 1 -2345))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
97 (n2820 ; Completed 2820-year cycles
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
98 (floor d0 1029983))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
99 (d1 ; Prior days not in n2820
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
100 (mod d0 1029983))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
101 (n768 ; 768-year cycles not in n2820
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
102 (floor d1 280506))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
103 (d2 ; Prior days not in n2820 or n768
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
104 (mod d1 280506))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
105 (n1 ; Years not in n2820 or n768
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
106 ; we want is
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
107 ; (floor (+ (* 2820 d2) (* 2820 366)) 1029983))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
108 ; but that causes overflow, so we use
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
109 (let ((a (floor d2 366)); we use 366 as the divisor because
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
110 ; (2820*366 mod 1029983) is small
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))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
113 (year (+ (* 2820 n2820); Complete 2820 year cycles
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
114 (* 768 n768) ; Complete 768 year cycles
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
115 (if ; Remaining years
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
116 ; Last day of 2820 year cycle
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
117 (= d1 1029617)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
118 (1- n1)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
119 n1)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
120 -2345))) ; Years before year 1
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
121 (if (< year 1)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
122 (1- year); No year zero
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
123 year)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
124
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
125 (defun calendar-persian-from-absolute (date)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
126 "Compute the Persian equivalent for absolute date DATE.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
127 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
128 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
129 Gregorian date Sunday, December 31, 1 BC."
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
130 (let* ((year (calendar-persian-year-from-absolute date))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
131 (month ; Search forward from Farvardin
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
132 (1+ (calendar-sum m 1
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
133 (> date
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
134 (calendar-absolute-from-persian
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
135 (list
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
136 m
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
137 (persian-calendar-last-day-of-month m year)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
138 year)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
139 1)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
140 (day ; Calculate the day by subtraction
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
141 (- date (1- (calendar-absolute-from-persian
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
142 (list month 1 year))))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
143 (list month day year)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
144
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
145 (defun calendar-persian-date-string (&optional date)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
146 "String of Persian date of Gregorian DATE.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
147 Defaults to today's date if DATE is not given."
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
148 (let* ((persian-date (calendar-persian-from-absolute
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
149 (calendar-absolute-from-gregorian
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
150 (or date (calendar-current-date)))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
151 (y (extract-calendar-year persian-date))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
152 (m (extract-calendar-month persian-date)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
153 (let ((monthname (aref persian-calendar-month-name-array (1- m)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
154 (day (int-to-string (extract-calendar-day persian-date)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
155 (dayname nil)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
156 (month (int-to-string m))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
157 (year (int-to-string y)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
158 (mapconcat 'eval calendar-date-display-form ""))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
159
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
160 (defun calendar-print-persian-date ()
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
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
166 (defun calendar-goto-persian-date (date &optional noecho)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
167 "Move cursor to Persian date DATE.
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
168 Echo Persian date unless NOECHO is t."
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
169 (interactive (persian-prompt-for-date))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
170 (calendar-goto-date (calendar-gregorian-from-absolute
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
171 (calendar-absolute-from-persian date)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
172 (or noecho (calendar-print-persian-date)))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
173
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
174 (defun persian-prompt-for-date ()
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
175 "Ask for a Persian date."
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
176 (let* ((today (calendar-current-date))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
177 (year (calendar-read
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
178 "Persian calendar year (not 0): "
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
179 '(lambda (x) (/= x 0))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
180 (int-to-string
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
181 (extract-calendar-year
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
182 (calendar-persian-from-absolute
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
183 (calendar-absolute-from-gregorian today))))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
184 (completion-ignore-case t)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
185 (month (cdr (assoc
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
186 (capitalize
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
187 (completing-read
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
188 "Persian calendar month name: "
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
189 (mapcar 'list
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
190 (append persian-calendar-month-name-array nil))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
191 nil t))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
192 (calendar-make-alist persian-calendar-month-name-array
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
193 1 'capitalize))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
194 (last (persian-calendar-last-day-of-month month year))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
195 (day (calendar-read
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
196 (format "Persian calendar day (1-%d): " last)
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
197 '(lambda (x) (and (< 0 x) (<= x last))))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
198 (list (list month day year))))
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
199
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
200 (defun diary-persian-date ()
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
201 "Persian calendar equivalent of date diary entry."
17382
41db5b776fe4 (diary-persian-date): Use `date'.
Richard M. Stallman <rms@gnu.org>
parents: 15259
diff changeset
202 (format "Persian date: %s" (calendar-persian-date-string date)))
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
203
15259
984ea4011d7e Renamed from cal-persian.el to avoid 14-character limitation.
Karl Heuer <kwzh@gnu.org>
parents: 15070
diff changeset
204 (provide 'cal-persia)
14914
8fbe0c9dc86f Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
205
15259
984ea4011d7e Renamed from cal-persian.el to avoid 14-character limitation.
Karl Heuer <kwzh@gnu.org>
parents: 15070
diff changeset
206 ;;; cal-persia.el ends here