diff options
| author | Richard M. Stallman | 1997-05-20 05:17:49 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-05-20 05:17:49 +0000 |
| commit | 151eeaa7c4f9ceea7b9c1560a13b9639b73a7a2f (patch) | |
| tree | c11641c72b841879f604e033ba3ed89cee1d4afe | |
| parent | 4abfba1faa600d0928f0a807ef803fc2f78f4bd5 (diff) | |
| download | emacs-151eeaa7c4f9ceea7b9c1560a13b9639b73a7a2f.tar.gz emacs-151eeaa7c4f9ceea7b9c1560a13b9639b73a7a2f.zip | |
(holiday-float): Rewritten to fix bug when base date
of holiday and holiday date are in different months.
| -rw-r--r-- | lisp/calendar/holidays.el | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/lisp/calendar/holidays.el b/lisp/calendar/holidays.el index e7077e96ecf..eeae46b9401 100644 --- a/lisp/calendar/holidays.el +++ b/lisp/calendar/holidays.el | |||
| @@ -310,20 +310,57 @@ STRING)). Returns nil if it is not visible in the current calendar window." | |||
| 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. |