Mercurial > emacs
comparison lisp/calendar/holidays.el @ 17891:6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
of holiday and holiday date are in different months.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 20 May 1997 05:17:49 +0000 |
parents | fd27882450bd |
children | d179de7ad92e |
comparison
equal
deleted
inserted
replaced
17890:200058b61996 | 17891:6eb7095ca7ab |
---|---|
308 (increment-calendar-month m y (- 11 month)) | 308 (increment-calendar-month m y (- 11 month)) |
309 (if (> m 9) | 309 (if (> m 9) |
310 (list (list (list month day y) string))))) | 310 (list (list (list month day y) string))))) |
311 | 311 |
312 (defun holiday-float (month dayname n string &optional day) | 312 (defun holiday-float (month dayname n string &optional day) |
313 "Holiday on MONTH, DAYNAME (Nth occurrence, Gregorian) called STRING. | 313 "Holiday on MONTH, DAYNAME (Nth occurrence) called STRING. |
314 If the Nth DAYNAME in MONTH is visible, the value returned is the list | 314 If the Nth DAYNAME in MONTH is visible, the value returned is the list |
315 \(((MONTH DAY year) STRING)). | 315 \(((MONTH DAY year) STRING)). |
316 | 316 |
317 If N<0, count backward from the end of MONTH. | 317 If N<0, count backward from the end of MONTH. |
318 | 318 |
319 An optional parameter DAY means the Nth DAYNAME after/before MONTH DAY. | 319 An optional parameter DAY means the Nth DAYNAME on or after/before MONTH DAY. |
320 | 320 |
321 Returns nil if it is not visible in the current calendar window." | 321 Returns nil if it is not visible in the current calendar window." |
322 (let ((m displayed-month) | 322 ;; This is messy because the holiday may be visible, while the date on which |
323 (y displayed-year)) | 323 ;; it is based is not. For example, the first Monday after December 30 may be |
324 (increment-calendar-month m y (- 11 month)) | 324 ;; visible when January is not. For large values of |n| the problem is more |
325 (if (> m 9) | 325 ;; grotesque. If we didn't have to worry about such cases, we could just use |
326 (list (list (calendar-nth-named-day n dayname month y day) string))))) | 326 |
327 ;; (let ((m displayed-month) | |
328 ;; (y displayed-year)) | |
329 ;; (increment-calendar-month m y (- 11 month)) | |
330 ;; (if (> m 9); month in year y is visible | |
331 ;; (list (list (calendar-nth-named-day n dayname month y day) string))))) | |
332 | |
333 ;; which is the way the function was originally written. | |
334 | |
335 (let* ((m1 displayed-month) | |
336 (y1 displayed-year) | |
337 (m2 m1) | |
338 (y2 y1)) | |
339 (increment-calendar-month m1 y1 -1) | |
340 (increment-calendar-month m2 y2 1) | |
341 (let* ((d1; first possible base date for holiday | |
342 (+ (calendar-nth-named-absday 1 dayname m1 y1) | |
343 (* -7 n) | |
344 (if (> n 0) 1 -7))) | |
345 (d2; last possible base date for holiday | |
346 (+ (calendar-nth-named-absday -1 dayname m2 y2) | |
347 (* -7 n) | |
348 (if (> n 0) 7 -1))) | |
349 (y1 (extract-calendar-year (calendar-gregorian-from-absolute d1))) | |
350 (y2 (extract-calendar-year (calendar-gregorian-from-absolute d2))) | |
351 (y; year of base date | |
352 (if (or (= y1 y2) (> month 9)) | |
353 y1 | |
354 y2)) | |
355 (d; day of base date | |
356 (or day (if (> n 0) | |
357 1 | |
358 (calendar-last-day-of-month month y)))) | |
359 (date; base date for holiday | |
360 (calendar-absolute-from-gregorian (list month d y)))) | |
361 (if (and (<= d1 date) (<= date d2)) | |
362 (list (list (calendar-nth-named-day n dayname month y d) | |
363 string)))))) | |
327 | 364 |
328 (defun holiday-sexp (sexp string) | 365 (defun holiday-sexp (sexp string) |
329 "Sexp holiday for dates in the calendar window. | 366 "Sexp holiday for dates in the calendar window. |
330 SEXP is an expression in variable `year' evaluates to `date'. | 367 SEXP is an expression in variable `year' evaluates to `date'. |
331 | 368 |