comparison lisp/calendar/diary-lib.el @ 17892:b3514551f08d

(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.
author Richard M. Stallman <rms@gnu.org>
date Tue, 20 May 1997 05:18:15 +0000
parents 68cce262538d
children 7d2a26d2371d
comparison
equal deleted inserted replaced
17891:6eb7095ca7ab 17892:b3514551f08d
938 `european-calendar-style' is nil, and DAY, MONTH, YEAR if 938 `european-calendar-style' is nil, and DAY, MONTH, YEAR if
939 `european-calendar-style' is t. DAY, MONTH, and YEAR 939 `european-calendar-style' is t. DAY, MONTH, and YEAR
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,
952 inclusive. (If `european-calendar-style' is t, the 954 inclusive. (If `european-calendar-style' is t, the
953 order of the parameters should be changed to D1, M1, Y1, 955 order of the parameters should be changed to D1, M1, Y1,
1164 (list m2 d2 y2)))) 1166 (list m2 d2 y2))))
1165 (d (calendar-absolute-from-gregorian date))) 1167 (d (calendar-absolute-from-gregorian date)))
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.
1171 Parameters are MONTH, DAYNAME, N. MONTH can be a list of months, the constant 1173 Parameters are MONTH, DAYNAME, N. MONTH can be a list of months, the constant
1172 t, or an integer. The constant t means all months. If N is negative, count 1174 t, or an integer. The constant t means all months. If N is negative, count
1173 backward from the end of the month." 1175 backward from the end of the month.
1174 (let ((m (extract-calendar-month date)) 1176
1175 (y (extract-calendar-year date))) 1177 An 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.
1185 Entry applies if date is the anniversary of MONTH, DAY, YEAR if 1230 Entry applies if date is the anniversary of MONTH, DAY, YEAR if
1186 `european-calendar-style' is nil, and DAY, MONTH, YEAR if 1231 `european-calendar-style' is nil, and DAY, MONTH, YEAR if