[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to read a timestamp?

From: Marcin Borkowski
Subject: Re: How to read a timestamp?
Date: Wed, 19 Aug 2015 23:49:14 +0200

On 2015-08-12, at 02:09, Robert Thorpe <address@hidden> wrote:

> Marcin Borkowski <address@hidden> writes:
>> Hi all,
>> I need to ask the user for a date (with or without time - if no time is
>> supplied, I want to assume 9:00am).  I know that `org-read-date' is
>> quite a powerful way to do it, but what if I do not want to depend on
>> Org-mode?
> You could use calendar-read-date, if you don't want to load org.

Thanks for the suggestion.  For the record, I found safe-date-to-time,
which is even better.  Here is my ask-for-timestamp function.  (Since
the results of safe-date-to-time might be unexpected, the user is asked
for confirmation just to make sure that Emacs got his/her intentions

--8<---------------cut here---------------start------------->8---
(defun ask-for-timestamp ()
  "Ask the user for the timestamp, and return it as Unix time.
If `org-read-date' is present, use that; if not, fall back to
`safe-date-to-time' and augment the result with current time."
   (if (fboundp 'org-read-date)
       (org-read-date nil t)
     (let ((time))
           (progn (setq time (safe-date-to-time (read-string "Date+time: ")))
                    (format-time-string "Time entered: %c. Confirm? " time)))))
--8<---------------cut here---------------end--------------->8---

> BR,
> Robert Thorpe

Thanks and regards,

Marcin Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

reply via email to

[Prev in Thread] Current Thread [Next in Thread]