aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-05-20 05:18:15 +0000
committerRichard M. Stallman1997-05-20 05:18:15 +0000
commit9b58d1444342caebbf21015a905a0b05c0d2d2ab (patch)
tree0c819179609442ead142440762f0bfc80799342d
parent151eeaa7c4f9ceea7b9c1560a13b9639b73a7a2f (diff)
downloademacs-9b58d1444342caebbf21015a905a0b05c0d2d2ab.tar.gz
emacs-9b58d1444342caebbf21015a905a0b05c0d2d2ab.zip
(diary-float): Rewritten to fix bug when base date
of entry and entry date are in different months. Added optional parameter DAY. (list-sexp-diary-entries): Revise description of diary-float.
-rw-r--r--lisp/calendar/diary-lib.el69
1 files changed, 57 insertions, 12 deletions
diff --git a/lisp/calendar/diary-lib.el b/lisp/calendar/diary-lib.el
index 1046296bcaf..70a03fa26d7 100644
--- a/lisp/calendar/diary-lib.el
+++ b/lisp/calendar/diary-lib.el
@@ -940,12 +940,14 @@ A number of built-in functions are available for this type of diary entry:
940 can be lists of integers, the constant t, or an integer. 940 can be lists of integers, the constant t, or an integer.
941 The constant t means all values. 941 The constant t means all values.
942 942
943 %%(diary-float MONTH DAYNAME N) text 943 %%(diary-float MONTH DAYNAME N &optional DAY) text
944 Entry will appear on the Nth DAYNAME of MONTH. 944 Entry will appear on the Nth DAYNAME of MONTH.
945 (DAYNAME=0 means Sunday, 1 means Monday, and so on; 945 (DAYNAME=0 means Sunday, 1 means Monday, and so on;
946 if N is negative it counts backward from the end of 946 if N is negative it counts backward from the end of
947 the month. MONTH can be a list of months, a single 947 the month. MONTH can be a list of months, a single
948 month, or t to specify all months. 948 month, or t to specify all months. Optional DAY means
949 Nth DAYNAME of MONTH on or after/before DAY. DAY defaults
950 to 1 if N>0 and the last day of the month if N<0.
949 951
950 %%(diary-block M1 D1 Y1 M2 D2 Y2) text 952 %%(diary-block M1 D1 Y1 M2 D2 Y2) text
951 Entry will appear on dates between M1/D1/Y1 and M2/D2/Y2, 953 Entry will appear on dates between M1/D1/Y1 and M2/D2/Y2,
@@ -1166,19 +1168,62 @@ D1, M1, Y1, D2, M2, Y2 if `european-calendar-style' is t."
1166 (if (and (<= date1 d) (<= d date2)) 1168 (if (and (<= date1 d) (<= d date2))
1167 entry))) 1169 entry)))
1168 1170
1169(defun diary-float (month dayname n) 1171(defun diary-float (month dayname n &optional day)
1170 "Floating diary entry--entry applies if date is the nth dayname of month. 1172 "Floating diary entry--entry applies if date is the nth dayname of month.
1171Parameters are MONTH, DAYNAME, N. MONTH can be a list of months, the constant 1173Parameters are MONTH, DAYNAME, N. MONTH can be a list of months, the constant
1172t, or an integer. The constant t means all months. If N is negative, count 1174t, or an integer. The constant t means all months. If N is negative, count
1173backward from the end of the month." 1175backward from the end of the month.
1174 (let ((m (extract-calendar-month date)) 1176
1175 (y (extract-calendar-year date))) 1177An optional parameter DAY means the Nth DAYNAME on or after/before MONTH DAY."
1176 (if (and 1178;; This is messy because the diary entry may apply, but the date on which it
1177 (or (and (listp month) (memq m month)) 1179;; is based can be in a different month/year. For example, asking for the
1178 (equal m month) 1180;; first Monday after December 30. For large values of |n| the problem is
1179 (eq month t)) 1181;; more grotesque.
1180 (calendar-date-equal date (calendar-nth-named-day n dayname m y))) 1182 (and (= dayname (calendar-day-of-week date))
1181 entry))) 1183 (let* ((m (extract-calendar-month date))
1184 (d (extract-calendar-day date))
1185 (y (extract-calendar-year date))
1186 (limit; last (n>0) or first (n<0) possible base date for entry
1187 (calendar-nth-named-absday (- n) dayname m y d))
1188 (last-abs (if (> n 0) limit (+ limit 6)))
1189 (first-abs (if (> n 0) (- limit 6) limit))
1190 (last (calendar-gregorian-from-absolute last-abs))
1191 (first (calendar-gregorian-from-absolute first-abs))
1192 ; m1, d1 is first possible base date
1193 (m1 (extract-calendar-month first))
1194 (d1 (extract-calendar-day first))
1195 (y1 (extract-calendar-year first))
1196 ; m2, d2 is last possible base date
1197 (m2 (extract-calendar-month last))
1198 (d2 (extract-calendar-day last))
1199 (y2 (extract-calendar-year last)))
1200 (or (and (= m1 m2); only possible base dates in one month
1201 (or (and (listp month) (memq m1 month))
1202 (= m1 month)
1203 (eq month t))
1204 (let ((d (or day (if (> n 0)
1205 1
1206 (calendar-last-day-of-month m1 y1)))))
1207 (and (<= d1 day) (<= day d2))))
1208 (and (< m1 m2); only possible base dates straddle two months
1209 (or
1210 ; m1, d1 works is a base date
1211 (and
1212 (or (and (listp month) (memq m1 month))
1213 (= m1 month)
1214 (eq month t))
1215 (<= d1 (or day (if (> n 0)
1216 1
1217 (calendar-last-day-of-month m1 y1)))))
1218 ; m2, d2 works is a base date
1219 (and (or (and (listp month) (memq m2 month))
1220 (= m2 month)
1221 (eq month t))
1222 (<= (or day (if (> n 0)
1223 1
1224 (calendar-last-day-of-month m2 y2)))
1225 d2)))))
1226 entry)))
1182 1227
1183(defun diary-anniversary (month day year) 1228(defun diary-anniversary (month day year)
1184 "Anniversary diary entry. 1229 "Anniversary diary entry.