Function: org-timestamp

org-timestamp is an interactive and byte-compiled function defined in org.el.gz.

Signature

(org-timestamp ARG &optional INACTIVE)

Documentation

Prompt for a date/time and insert a time stamp.

If the user specifies a time like HH:MM or if this command is called with at least one prefix argument, the time stamp contains the date and the time. Otherwise, only the date is included.

All parts of a date not specified by the user are filled in from the timestamp at point, if any, or the current date/time otherwise.

If there is already a timestamp at the cursor, it is replaced.

With two universal prefix arguments, insert an active timestamp with the current time without prompting the user.

When called from Lisp, the timestamp is inactive if INACTIVE is non-nil.

Key Bindings

Aliases

org-time-stamp

Source Code

;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-timestamp (arg &optional inactive)
  "Prompt for a date/time and insert a time stamp.

If the user specifies a time like HH:MM or if this command is
called with at least one prefix argument, the time stamp contains
the date and the time.  Otherwise, only the date is included.

All parts of a date not specified by the user are filled in from
the timestamp at point, if any, or the current date/time
otherwise.

If there is already a timestamp at the cursor, it is replaced.

With two universal prefix arguments, insert an active timestamp
with the current time without prompting the user.

When called from Lisp, the timestamp is inactive if INACTIVE is
non-nil."
  (interactive "P")
  (let* ((ts (cond
	      ((org-at-date-range-p t)
	       (match-string (if (< (point) (- (match-beginning 2) 2)) 1 2)))
	      ((org-at-timestamp-p 'lax) (match-string 0))))
	 ;; Default time is either the timestamp at point or today.
	 ;; When entering a range, only the range start is considered.
         (default-time (and ts (org-time-string-to-time ts)))
         (default-input (and ts (org-get-compact-tod ts)))
         (repeater (and ts
			(string-match "\\([.+-]+[0-9]+[hdwmy] ?\\)+" ts)
			(match-string 0 ts)))
	 org-time-was-given
	 org-end-time-was-given
	 (time
	  (if (equal arg '(16)) (current-time)
	    ;; Preserve `this-command' and `last-command'.
	    (let ((this-command this-command)
		  (last-command last-command))
	      (org-read-date
	       arg 'totime nil nil default-time default-input
	       inactive)))))
    (cond
     ((and ts
           (memq last-command '( org-time-stamp org-time-stamp-inactive
                                 org-timestamp org-timestamp-inactive))
           (memq this-command '( org-time-stamp org-time-stamp-inactive
                                 org-timestamp org-timestamp-inactive)))
      (insert "--")
      (org-insert-timestamp time (or org-time-was-given arg) inactive))
     (ts
      ;; Make sure we're on a timestamp.  When in the middle of a date
      ;; range, move arbitrarily to range end.
      (unless (org-at-timestamp-p 'lax)
	(skip-chars-forward "-")
	(org-at-timestamp-p 'lax))
      (replace-match "")
      (setq org-last-changed-timestamp
	    (org-insert-timestamp
	     time (or org-time-was-given arg)
	     inactive nil nil (list org-end-time-was-given)))
      (when repeater
	(backward-char)
	(insert " " repeater)
	(setq org-last-changed-timestamp
	      (concat (substring org-last-inserted-timestamp 0 -1)
		      " " repeater ">")))
      (message "Timestamp updated"))
     ((equal arg '(16)) (org-insert-timestamp time t inactive))
     (t (org-insert-timestamp
	 time (or org-time-was-given arg) inactive nil nil
	 (list org-end-time-was-given))))))