* How to read a timestamp?
@ 2015-08-11 21:27 Marcin Borkowski
2015-08-12 0:09 ` Robert Thorpe
2015-08-12 2:56 ` Emanuel Berg
0 siblings, 2 replies; 6+ messages in thread
From: Marcin Borkowski @ 2015-08-11 21:27 UTC (permalink / raw)
To: Help Gnu Emacs mailing list
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?
TIA,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to read a timestamp?
2015-08-11 21:27 How to read a timestamp? Marcin Borkowski
@ 2015-08-12 0:09 ` Robert Thorpe
2015-08-19 21:49 ` Marcin Borkowski
2015-08-12 2:56 ` Emanuel Berg
1 sibling, 1 reply; 6+ messages in thread
From: Robert Thorpe @ 2015-08-12 0:09 UTC (permalink / raw)
To: Marcin Borkowski; +Cc: help-gnu-emacs
Marcin Borkowski <mbork@mbork.pl> 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.
BR,
Robert Thorpe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to read a timestamp?
2015-08-11 21:27 How to read a timestamp? Marcin Borkowski
2015-08-12 0:09 ` Robert Thorpe
@ 2015-08-12 2:56 ` Emanuel Berg
2015-08-19 21:42 ` Marcin Borkowski
1 sibling, 1 reply; 6+ messages in thread
From: Emanuel Berg @ 2015-08-12 2:56 UTC (permalink / raw)
To: help-gnu-emacs
Marcin Borkowski <mbork@mbork.pl> writes:
> 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?
I wrote something to that extent a while back:
http://user.it.uu.se/~embe8573/conf/emacs-init/time-my.el
Here is the relevant Elisp. (To add "time", change the
arguments to `encode-time'.)
(defun time-between-times (year1 month1 day1
year2 month2 day2)
(let*((seconds-then (float-time (encode-time 0 0 0 day1 month1 year1)))
(seconds-now (float-time (encode-time 0 0 0 day2 month2 year2)))
(seconds-diff (- seconds-now seconds-then)) )
(format-seconds "%Y, %D" seconds-diff)))
(defun print-time-since (year month day)
(format-seconds "%Y, %D" (float-time
(time-since (encode-time 0 0 0 day month year)))) )
;; test:
;; (time-between-times 2010 4 15 2015 3 16)
;; (print-time-since 2010 4 15)
You are welcome :)
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to read a timestamp?
2015-08-12 2:56 ` Emanuel Berg
@ 2015-08-19 21:42 ` Marcin Borkowski
2015-08-21 19:20 ` Emanuel Berg
0 siblings, 1 reply; 6+ messages in thread
From: Marcin Borkowski @ 2015-08-19 21:42 UTC (permalink / raw)
To: help-gnu-emacs
On 2015-08-12, at 04:56, Emanuel Berg <embe8573@student.uu.se> wrote:
> Marcin Borkowski <mbork@mbork.pl> writes:
>
>> 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?
>
> I wrote something to that extent a while back:
It seems you misunderstood my question. I want to read a timestamp from
the minibuffer, not display it.
Best,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to read a timestamp?
2015-08-12 0:09 ` Robert Thorpe
@ 2015-08-19 21:49 ` Marcin Borkowski
0 siblings, 0 replies; 6+ messages in thread
From: Marcin Borkowski @ 2015-08-19 21:49 UTC (permalink / raw)
To: help-gnu-emacs
On 2015-08-12, at 02:09, Robert Thorpe <rt@robertthorpeconsulting.com> wrote:
> Marcin Borkowski <mbork@mbork.pl> 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
right.)
--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."
(time-to-seconds
(if (fboundp 'org-read-date)
(org-read-date nil t)
(let ((time))
(while
(progn (setq time (safe-date-to-time (read-string "Date+time: ")))
(not
(y-or-n-p
(format-time-string "Time entered: %c. Confirm? " time)))))
time))))
--8<---------------cut here---------------end--------------->8---
> BR,
> Robert Thorpe
Thanks and regards,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to read a timestamp?
2015-08-19 21:42 ` Marcin Borkowski
@ 2015-08-21 19:20 ` Emanuel Berg
0 siblings, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2015-08-21 19:20 UTC (permalink / raw)
To: help-gnu-emacs
Marcin Borkowski <mbork@mbork.pl> writes:
> It seems you misunderstood my question. I want to read
> a timestamp from the minibuffer, not display it.
You can either do that with a normal interactive
function which reads digits one by one, or you can
have the user input the whole string and then do
a parsing. Then you can use `encode-time' just as in
my code to get internal time.
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-08-21 19:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-11 21:27 How to read a timestamp? Marcin Borkowski
2015-08-12 0:09 ` Robert Thorpe
2015-08-19 21:49 ` Marcin Borkowski
2015-08-12 2:56 ` Emanuel Berg
2015-08-19 21:42 ` Marcin Borkowski
2015-08-21 19:20 ` Emanuel Berg
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.