Function: icalendar-date/time-add

icalendar-date/time-add is a byte-compiled function defined in icalendar-utils.el.gz.

Signature

(icalendar-date/time-add DT UNIT N &optional VTIMEZONE)

Documentation

Add N UNITs to DT.

DT should be an icalendar-date or icalendar-date-time. UNIT should be :year, :month, :week, :day, :hour, :minute, or :second; time units will be ignored if DT is an icalendar-date. N may be a positive or negative integer.

Other relevant functions are documented in the icalendar group.

Shortdoc

;; icalendar
(icalendar-date/time-add '(11 11 2024) :month 2)
    => (1 11 2025)
  (icalendar-date/time-add '(0 0 10 11 11 2024 1 -1 nil) :hour -3)
    => (0 0 7 11 11 2024 1 -1 nil)

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/icalendar-utils.el.gz
;; TODO: rework so that it's possible to add dur-values to plain dates.
;; Perhaps rename this to "date/time-inc" or so, or use kwargs to allow
;; multiple units, or...
(defun ical:date/time-add (dt unit n &optional vtimezone)
  "Add N UNITs to DT.

DT should be an `icalendar-date' or `icalendar-date-time'.  UNIT should
be `:year', `:month', `:week', `:day', `:hour', `:minute', or `:second';
time units will be ignored if DT is an `icalendar-date'.  N may be a
positive or negative integer."
  (cl-typecase dt
    (ical:date-time
     (let ((delta (if (eq unit :week) (make-decoded-time :day (* 7 n))
                    (make-decoded-time unit n))))
       (ical:date-time-add dt delta vtimezone)))
    (ical:date (ical:date-add dt unit n))))