comparison lisp/calendar/calendar.el @ 93497:258266315e25

(calendar-nongregorian-visible-p): New function.
author Glenn Morris <rgm@gnu.org>
date Tue, 01 Apr 2008 02:55:03 +0000
parents 2fe1b51b8771
children 9105df157c3a
comparison
equal deleted inserted replaced
93496:cdfc8242a666 93497:258266315e25
2320 (< (abs (calendar-interval 2320 (< (abs (calendar-interval
2321 displayed-month displayed-year 2321 displayed-month displayed-year
2322 (extract-calendar-month date) (extract-calendar-year date))) 2322 (extract-calendar-month date) (extract-calendar-year date)))
2323 2))) 2323 2)))
2324 2324
2325 (defun calendar-nongregorian-visible-p (month day toabs fromabs switch)
2326 "Return non-nil if MONTH, DAY is visible in the calendar window.
2327 MONTH and DAY are in some non-Gregorian calendar system. The
2328 functions TOABS and FROMABS convert that system to and from
2329 absolute, respectively. SWITCH is a function that takes a single
2330 argument (a local month number). It applies when the local year
2331 changes across the calendar window, and returns non-nil if the
2332 specified month should be associated with the higher year.
2333 Returns the corresponding Gregorian date."
2334 ;; We need to choose the local year associated with month and day
2335 ;; that might make them visible.
2336 (let* ((m1 displayed-month)
2337 (y1 displayed-year)
2338 (m2 displayed-month)
2339 (y2 displayed-year)
2340 ;; Absolute date of first/last dates in calendar window.
2341 (start-date (progn
2342 (increment-calendar-month m1 y1 -1)
2343 (calendar-absolute-from-gregorian (list m1 1 y1))))
2344 (end-date (progn
2345 (increment-calendar-month m2 y2 1)
2346 (calendar-absolute-from-gregorian
2347 (list m2 (calendar-last-day-of-month m2 y2) y2))))
2348 ;; Local date of first/last date in calendar window.
2349 (local-start (funcall fromabs start-date))
2350 (local-end (funcall fromabs end-date))
2351 ;; Local year of first/last dates.
2352 ;; Can only differ if displayed-month = 12, 1, 2.
2353 (local-y1 (extract-calendar-year local-start))
2354 (local-y2 (extract-calendar-year local-end))
2355 ;; Choose which year might be visible in the window.
2356 ;; Obviously it only matters when y1 and y2 differ, ie
2357 ;; when the _local_ new year is visible.
2358 (year (if (funcall switch month) local-y2 local-y1))
2359 (date (calendar-gregorian-from-absolute
2360 (funcall toabs (list month day year)))))
2361 (if (calendar-date-is-visible-p date)
2362 date)))
2363
2325 (defun calendar-date-is-valid-p (date) 2364 (defun calendar-date-is-valid-p (date)
2326 "Return t if DATE is a valid date." 2365 "Return t if DATE is a valid date."
2327 (let ((month (extract-calendar-month date)) 2366 (let ((month (extract-calendar-month date))
2328 (day (extract-calendar-day date)) 2367 (day (extract-calendar-day date))
2329 (year (extract-calendar-year date))) 2368 (year (extract-calendar-year date)))