help-gnu-emacs
[Top][All Lists]
Advanced

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

elisp Q: round & display time in 5-min. increments


From: Edward
Subject: elisp Q: round & display time in 5-min. increments
Date: Tue, 27 Nov 2007 16:01:57 -0800 (PST)
User-agent: G2/1.0

Currently I'm using the following snippet to generate the time
rounded
to the nearest 5-min. increment:

(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.


Thanks,


Edward




reply via email to

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