Function: calendar-increment-month
calendar-increment-month is a macro defined in calendar.el.gz.
Signature
(calendar-increment-month MON YR N &optional NMONTHS)
Documentation
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. Optional NMONTHS is the number of months per year (default 12).
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/calendar.el.gz
(defmacro calendar-increment-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.
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 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