diff options
| author | Sam Steingold | 2014-05-12 12:14:24 -0400 |
|---|---|---|
| committer | Sam Steingold | 2014-05-12 12:14:24 -0400 |
| commit | ecaf7f4dc06335ee50521c27fbd7aaacae366a02 (patch) | |
| tree | 784b8a17e0a2a8265edb138d883f52b23a3a804e | |
| parent | 79e502ca440272836c04ffb9c18acbc1128e5064 (diff) | |
| download | emacs-ecaf7f4dc06335ee50521c27fbd7aaacae366a02.tar.gz emacs-ecaf7f4dc06335ee50521c27fbd7aaacae366a02.zip | |
(seconds-to-string): New function to pretty print time delay in seconds.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/calendar/time-date.el | 17 |
2 files changed, 22 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 4f5d0734aec..0e6013a839c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2014-05-12 Sam Steingold <sds@gnu.org> | ||
| 2 | |||
| 3 | * calendar/time-date.el (seconds-to-string): New function to | ||
| 4 | pretty print time delay in seconds. | ||
| 5 | |||
| 1 | 2014-05-12 Stefan Monnier <monnier@iro.umontreal.ca> | 6 | 2014-05-12 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 7 | ||
| 3 | * mpc.el (mpc-format): Trim Date to the year. | 8 | * mpc.el (mpc-format): Trim Date to the year. |
diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el index 3d62c5d789a..eb534b6b89f 100644 --- a/lisp/calendar/time-date.el +++ b/lisp/calendar/time-date.el | |||
| @@ -388,6 +388,23 @@ This function does not work for SECONDS greater than `most-positive-fixnum'." | |||
| 388 | t t string)))))) | 388 | t t string)))))) |
| 389 | (replace-regexp-in-string "%%" "%" string)) | 389 | (replace-regexp-in-string "%%" "%" string)) |
| 390 | 390 | ||
| 391 | (defvar seconds-to-string | ||
| 392 | (list (list 1 "ms" 0.001) | ||
| 393 | (list 100 "s" 1) | ||
| 394 | (list (* 60 100) "m" 60.0) | ||
| 395 | (list (* 3600 30) "h" 3600.0) | ||
| 396 | (list (* 3600 24 400) "d" (* 3600.0 24.0)) | ||
| 397 | (list nil "y" (* 365.25 24 3600))) | ||
| 398 | "Formatting used by the function `seconds-to-string'.") | ||
| 399 | ;;;###autoload | ||
| 400 | (defun seconds-to-string (delay) | ||
| 401 | "Convert the time interval in seconds to a short string." | ||
| 402 | (cond ((> 0 delay) (concat "-" (seconds-to-string (- delay)))) | ||
| 403 | ((= 0 delay) "0s") | ||
| 404 | (t (let ((sts seconds-to-string) here) | ||
| 405 | (while (and (car (setq here (pop sts))) | ||
| 406 | (<= (car here) delay))) | ||
| 407 | (concat (format "%.2f" (/ delay (third here))) (second here)))))) | ||
| 391 | 408 | ||
| 392 | (provide 'time-date) | 409 | (provide 'time-date) |
| 393 | 410 | ||