December 9th, 2006

uptime

(defpackage #:zpb
  (:use #:cl)
  (:export #:uptime))

(in-package #:zpb)

(defun uptime-values ()
  (let ((seconds (truncate (get-internal-real-time)
                           internal-time-units-per-second)))
    (multiple-value-bind (days seconds)
        (truncate seconds 86400)
      (multiple-value-bind (hours seconds)
          (truncate seconds 3600)
        (multiple-value-bind (minutes seconds)
            (truncate seconds 60)
          (values days hours minutes seconds))))))

(defun uptime ()
  (multiple-value-bind (days hours minutes seconds)
      (uptime-values)
    (format t "~[~:;~:*~D days ~]~
               ~[~:;~:*~D hours ~]~
               ~[~:;~:*~D minutes ~]~
               ~[~:;~:*~D seconds~]~%"
            days hours minutes seconds)))

Here's my best uptime:

PK(13): (zpb:uptime)
146 days 7 hours 50 minutes 36 seconds

That's for PK Bass & Tackle. What's your best image uptime?

Update Oops. get-internal-real-time is not specified to start from 0, it just happens to do so on my implementation. Sorry!