diff options
author | Glenn Morris <rgm@gnu.org> | 2008-02-11 00:28:31 +0000 |
---|---|---|
committer | Glenn Morris <rgm@gnu.org> | 2008-02-11 00:28:31 +0000 |
commit | 9ce1b62f960e9e0bd9d21f2e6ef3968880080e9d (patch) | |
tree | fe230f45f5d53445c5ff08186a794fd5c55e3471 /lisp | |
parent | 238cbdf80bc5300250b21f55aa7d2aa4d11c6e72 (diff) | |
download | emacs-9ce1b62f960e9e0bd9d21f2e6ef3968880080e9d.tar.gz |
(emacs-uptime): New function.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/ChangeLog | 7 | ||||
-rw-r--r-- | lisp/calendar/time-date.el | 34 |
2 files changed, 41 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0e664149b94..4ee7ee0e2ad 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2008-02-11 Glenn Morris <rgm@gnu.org> + + * startup.el (emacs-startup-time): New variable. + (command-line): Set emacs-startup-time. + + * calendar/time-date.el (emacs-uptime): New function. + 2008-02-10 Bastien Guerry <bzg@altern.org> * mail/rmail.el (rmail-nonignored-headers): Allow to be nil. diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el index 58444041725..1f325379a48 100644 --- a/lisp/calendar/time-date.el +++ b/lisp/calendar/time-date.el @@ -254,6 +254,40 @@ If DATE is malformed, return a time value of zeros." (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 |