Function: calendar-read-date

calendar-read-date is a byte-compiled function defined in calendar.el.gz.

Signature

(calendar-read-date &optional NODAY DEFAULT-DATE)

Documentation

Prompt for Gregorian date. Return a list (month day year).

If optional NODAY is t, does not ask for day, but just returns
(month 1 year); if NODAY is any other non-nil value the value
returned is (month year).

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/calendar.el.gz
(defun calendar-read-date (&optional noday default-date)
  "Prompt for Gregorian date.  Return a list (month day year).
If optional NODAY is t, does not ask for day, but just returns
\(month 1 year); if NODAY is any other non-nil value the value
returned is (month year)."
  (unless default-date (setq default-date (calendar-current-date)))
  (let* ((defyear (calendar-extract-year default-date))
         (year (calendar-read-sexp "Year (>0)"
                                   (lambda (x) (> x 0))
                                   defyear))
         (month-array calendar-month-name-array)
         (defmon (aref month-array (1- (calendar-extract-month default-date))))
         (month (cdr (assoc-string
                      (completing-read
                       (format-prompt "Month name" defmon)
                       (completion-table-with-metadata
                        (completion-table-case-fold
                         (append month-array nil))
                        `((category . calendar-month)
                          (display-sort-function . identity)))
                       nil t nil nil defmon)
                      (calendar-make-alist month-array 1) t)))
         (defday (calendar-extract-day default-date))
         (last (calendar-last-day-of-month month year)))
    (if noday
        (if (eq noday t)
            (list month 1 year)
          (list month year))
      (list month
            (calendar-read-sexp "Day (1-%d)"
                                (lambda (x) (and (< 0 x) (<= x last)))
                                ;; Don't offer today's day as default
                                ;; if it's not valid for the chosen
                                ;; month/year.
                                (if (<= defday last) defday) last)
            year))))