comparison lisp/calendar/time-date.el @ 91737:f9b4ba32c775

(emacs-uptime): New function.
author Glenn Morris <rgm@gnu.org>
date Mon, 11 Feb 2008 00:28:20 +0000
parents 974a828870fe
children 41b16ef40f59
comparison
equal deleted inserted replaced
91736:0e11ef90a122 91737:f9b4ba32c775
252 If DATE is malformed, return a time value of zeros." 252 If DATE is malformed, return a time value of zeros."
253 (condition-case () 253 (condition-case ()
254 (date-to-time date) 254 (date-to-time date)
255 (error '(0 0)))) 255 (error '(0 0))))
256 256
257
258 ;;;###autoload
259 (defun emacs-uptime ()
260 "Return a string giving the uptime of this instance of Emacs."
261 (interactive)
262 (let* ((sec (time-to-seconds
263 (time-subtract (current-time) emacs-startup-time)))
264 (prev)
265 (num)
266 (str
267 ;; cf article-make-date-line in gnus-art.
268 ;; Worth having a general time-date `format-seconds'
269 ;; function that converts a number of seconds into so many
270 ;; years, hours, etc?
271 (mapconcat
272 (lambda (unit)
273 (if (zerop (setq num (floor sec (cdr unit))))
274 ""
275 (setq sec (- sec (* num (cdr unit))))
276 (prog1
277 (format "%s%d %s%s" (if prev ", " "") num
278 (symbol-name (car unit))
279 (if (= num 1) "" "s"))
280 (setq prev t))))
281 '((year . 31536000) ; 365-day year
282 (day . 86400)
283 (hour . 3600)
284 (minute . 60)
285 (second . 1))
286 "")))
287 (if (interactive-p)
288 (message "%s" str)
289 str)))
290
257 (provide 'time-date) 291 (provide 'time-date)
258 292
259 ;;; arch-tag: addcf07b-b20a-465b-af72-550b8ac5190f 293 ;;; arch-tag: addcf07b-b20a-465b-af72-550b8ac5190f
260 ;;; time-date.el ends here 294 ;;; time-date.el ends here