emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r117093: (seconds-to-string): New function to pretty


From: Sam Steingold
Subject: [Emacs-diffs] trunk r117093: (seconds-to-string): New function to pretty print time delay in seconds.
Date: Mon, 12 May 2014 16:14:26 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117093
revision-id: address@hidden
parent: address@hidden
committer: Sam Steingold <address@hidden>
branch nick: trunk
timestamp: Mon 2014-05-12 12:14:24 -0400
message:
  (seconds-to-string): New function to pretty print time delay in seconds.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/calendar/time-date.el     
timedate.el-20091113204419-o5vbwnq5f7feedwu-2380
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-05-12 13:25:53 +0000
+++ b/lisp/ChangeLog    2014-05-12 16:14:24 +0000
@@ -1,3 +1,8 @@
+2014-05-12  Sam Steingold  <address@hidden>
+
+       * calendar/time-date.el (seconds-to-string): New function to
+       pretty print time delay in seconds.
+
 2014-05-12  Stefan Monnier  <address@hidden>
 
        * mpc.el (mpc-format): Trim Date to the year.

=== modified file 'lisp/calendar/time-date.el'
--- a/lisp/calendar/time-date.el        2014-01-01 07:43:34 +0000
+++ b/lisp/calendar/time-date.el        2014-05-12 16:14:24 +0000
@@ -388,6 +388,23 @@
                  t t string))))))
   (replace-regexp-in-string "%%" "%" string))
 
+(defvar seconds-to-string
+  (list (list 1 "ms" 0.001)
+        (list 100 "s" 1)
+        (list (* 60 100) "m" 60.0)
+        (list (* 3600 30) "h" 3600.0)
+        (list (* 3600 24 400) "d" (* 3600.0 24.0))
+        (list nil "y" (* 365.25 24 3600)))
+  "Formatting used by the function `seconds-to-string'.")
+;;;###autoload
+(defun seconds-to-string (delay)
+  "Convert the time interval in seconds to a short string."
+  (cond ((> 0 delay) (concat "-" (seconds-to-string (- delay))))
+        ((= 0 delay) "0s")
+        (t (let ((sts seconds-to-string) here)
+             (while (and (car (setq here (pop sts)))
+                         (<= (car here) delay)))
+             (concat (format "%.2f" (/ delay (third here))) (second here))))))
 
 (provide 'time-date)
 


reply via email to

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