Function: todo-read-date

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

Signature

(todo-read-date &optional ARG MO YR)

Documentation

Prompt for Gregorian date and return it in the current format.

With non-nil ARG, prompt for and return only the date component specified by ARG, which can be one of these symbols: month (prompt for name, return name or number according to value of calendar-date-display-form), day of month, or year. The value of each of these components can be *, indicating an unspecified month, day, or year.

When ARG is day, non-nil arguments MO and YR determine the number of the last the day of the month.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
;; Adapted from calendar-read-date and calendar-date-string.
(defun todo-read-date (&optional arg mo yr)
  "Prompt for Gregorian date and return it in the current format.

With non-nil ARG, prompt for and return only the date component
specified by ARG, which can be one of these symbols:
`month' (prompt for name, return name or number according to
value of `calendar-date-display-form'), `day' of month, or
`year'.  The value of each of these components can be `*',
indicating an unspecified month, day, or year.

When ARG is `day', non-nil arguments MO and YR determine the
number of the last the day of the month."
  (calendar-dlet
      (year monthname month day dayname) ;Needed by calendar-date-display-form.
    (when (or (not arg) (eq arg 'year))
      (while (if (natnump year) (< year 1) (not (eq year '*)))
	(setq year (read-from-minibuffer
		    "Year (>0 or RET for this year or * for any year): "
		    nil nil t nil (number-to-string
				   (calendar-extract-year
				    (calendar-current-date)))))))
    (when (or (not arg) (eq arg 'month))
      (let* ((marray todo-month-name-array)
	     (mlist (append marray nil))
	     (mabarray todo-month-abbrev-array)
	     (mablist (append mabarray nil))
	     (completion-ignore-case todo-completion-ignore-case))
	(setq monthname (completing-read
			 "Month name (RET for current month, * for any month): "
			 mlist nil t nil nil
                         (calendar-month-name
                          (calendar-extract-month (calendar-current-date)) t))
	      month (1+ (- (length mlist)
			   (length (or (member monthname mlist)
				       (member monthname mablist))))))
	(setq monthname (aref mabarray (1- month)))))
    (when (or (not arg) (eq arg 'day))
      (let ((last (let ((mm (or month mo))
			(yy (or year yr)))
		    ;; If month is unspecified, use a month with 31
		    ;; days for checking day of month input.  Does
		    ;; Calendar do anything special when * is
		    ;; currently a shorter month?
		    (if (= mm 13) (setq mm 1))
		    ;; If year is unspecified, use a leap year to
		    ;; allow Feb. 29.
		    (if (eq year '*) (setq yy 2012))
		    (calendar-last-day-of-month mm yy))))
	(while (if (natnump day) (or (< day 1) (> day last)) (not (eq day '*)))
	  (setq day (read-from-minibuffer
		     (format "Day (1-%d or RET for today or * for any day): "
			     last)
		     nil nil t nil (number-to-string
				    (calendar-extract-day
				     (calendar-current-date))))))))
    ;; Stringify read values (monthname is already a string).
    (and year (setq year (if (eq year '*)
			     (symbol-name '*)
			   (number-to-string year))))
    (and day (setq day (if (eq day '*)
			   (symbol-name '*)
			 (number-to-string day))))
    (and month (setq month (if (= month 13)
			       (symbol-name '*)
			     (number-to-string month))))
    (if arg
	(cond ((eq arg 'year) year)
	      ((eq arg 'day) day)
	      ((eq arg 'month)
	       (if (memq 'month calendar-date-display-form)
		   month
		 monthname)))
      (mapconcat #'eval calendar-date-display-form))))