emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] Changes to emacs/lisp/calendar/time-date.el,v


From: Glenn Morris
Subject: [Emacs-diffs] Changes to emacs/lisp/calendar/time-date.el,v
Date: Mon, 11 Feb 2008 00:28:20 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Glenn Morris <gm>       08/02/11 00:28:20

Index: time-date.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/calendar/time-date.el,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- time-date.el        8 Jan 2008 20:44:05 -0000       1.21
+++ time-date.el        11 Feb 2008 00:28:20 -0000      1.22
@@ -254,6 +254,40 @@
       (date-to-time date)
     (error '(0 0))))
 
+
+;;;###autoload
+(defun emacs-uptime ()
+  "Return a string giving the uptime of this instance of Emacs."
+  (interactive)
+  (let* ((sec (time-to-seconds
+               (time-subtract (current-time) emacs-startup-time)))
+         (prev)
+         (num)
+         (str
+          ;; cf article-make-date-line in gnus-art.
+          ;; Worth having a general time-date `format-seconds'
+          ;; function that converts a number of seconds into so many
+          ;; years, hours, etc?
+          (mapconcat
+           (lambda (unit)
+             (if (zerop (setq num (floor sec (cdr unit))))
+                 ""
+               (setq sec (- sec (* num (cdr unit))))
+              (prog1
+                  (format "%s%d %s%s" (if prev ", " "") num
+                          (symbol-name (car unit))
+                          (if (= num 1) "" "s"))
+                (setq prev t))))
+           '((year   . 31536000)        ; 365-day year
+             (day    .    86400)
+             (hour   .     3600)
+             (minute .       60)
+             (second .        1))
+           "")))
+    (if (interactive-p)
+        (message "%s" str)
+      str)))
+
 (provide 'time-date)
 
 ;;; arch-tag: addcf07b-b20a-465b-af72-550b8ac5190f




reply via email to

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