From: Ari Roponen <ari.roponen@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: elisp Q: round & display time in 5-min. increments
Date: Fri, 30 Nov 2007 09:51:58 +0200 [thread overview]
Message-ID: <m3sl2orx0h.fsf@gmail.com> (raw)
In-Reply-To: 59c4e557-3273-4a7a-a773-a4da0260a084@i12g2000prf.googlegroups.com
Hi,
Edward <edward.dodge@gmail.com> writes:
> (concat
> (format-time-string "%H" (current-time))
> ":"
> (int-to-string
> (* (round (string-to-number (format-time-string
> "%M" (current-
> time))) 5) 5))
> " ")
>
> This works for most times, but it doesn't cover any edge conditions.
> For example, between the 55th minute and the end of the hour, it
> rounds to "60" and doesn't carry to the hour. Around the 5th minute,
> it generates "5", but it doesn't pad with a zero.
>
>
> Does anyone know of some pre-existing code in Emacs that does what
> I'm
> trying to do? Or failing that, does anyone have an elegant snippet
> of code that accomplishes this task while meeting these edge-
> conditions? I'm not worried about the midnight edge-condition, but
> if you know of code that does that too, so much the better.
I don't know about the existing code, but this seems to do what you
want:
(format-time-string
"%H:%M "
(apply 'encode-time
(let* ((time (decode-time
(time-add (current-time)
(seconds-to-time 150)))) ;2m30s
(mins (cadr time)))
(setcar (cdr time) (- mins (mod mins 5)))
time)))
--
Ari Roponen
prev parent reply other threads:[~2007-11-30 7:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-28 0:01 elisp Q: round & display time in 5-min. increments Edward
2007-11-30 7:51 ` Ari Roponen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3sl2orx0h.fsf@gmail.com \
--to=ari.roponen@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.