Mercurial > emacs
changeset 93464:4d4a9542d49c
(increment-calendar-month): Optionally handle systems without 12
months per year.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Mon, 31 Mar 2008 15:59:29 +0000 |
parents | eb60699d02ea |
children | 762c7878a22a |
files | lisp/calendar/calendar.el |
diffstat | 1 files changed, 13 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/calendar/calendar.el Mon Mar 31 15:39:20 2008 +0000 +++ b/lisp/calendar/calendar.el Mon Mar 31 15:59:29 2008 +0000 @@ -1213,20 +1213,23 @@ (defconst cal-hebrew-yahrzeit-buffer "*Yahrzeits*" "Name of the buffer used by `list-yahrzeit-dates'.") -(defmacro increment-calendar-month (mon yr n) +(defmacro increment-calendar-month (mon yr n &optional nmonths) "Increment the variables MON and YR by N months. Forward if N is positive or backward if N is negative. A negative YR is interpreted as BC; -1 being 1 BC, and so on. -This is only appropriate for calendars with 12 months per year." - `(let (macro-y) - ;; FIXME 12 could be an optional arg, if needed. +Optional NMONTHS is the number of months per year (default 12)." + ;; Can view this as a form of base-nmonths arithmetic, in which "a + ;; year" = "ten", and we never bother to use hundreds. + `(let ((nmonths (or ,nmonths 12)) + macro-y) (if (< ,yr 0) (setq ,yr (1+ ,yr))) ; -1 BC -> 0 AD, etc - (setq macro-y (+ (* ,yr 12) ,mon -1 ,n) - ,mon (1+ (mod macro-y 12)) - ,yr (/ macro-y 12)) -;;; (setq macro-y (+ (* ,yr 12) ,mon -1 ,n) -;;; ,yr (/ macro-y 12) -;;; ,mon (- macro-y (* ,yr 12))) + (setq macro-y (+ (* ,yr nmonths) ,mon -1 ,n) + ,mon (1+ (mod macro-y nmonths)) + ,yr (/ macro-y nmonths)) + ;; Alternative: +;;; (setq macro-y (+ (* ,yr nmonths) ,mon -1 ,n) +;;; ,yr (/ macro-y nmonths) +;;; ,mon (- macro-y (* ,yr nmonths))) (and (< macro-y 0) (> ,mon 1) (setq ,yr (1- ,yr))) (if (< ,yr 1) (setq ,yr (1- ,yr))))) ; 0 AD -> -1 BC, etc