+val s_cutoff = LargeInt.fromInt 60
+val m_cutoff = LargeInt.fromInt (60 * 60)
+val h_cutoff = LargeInt.fromInt (60 * 60 * 24)
+
+fun diffFromNow t =
+ let
+ val secs = Time.toSeconds (Time.- (Time.now (), t))
+ in
+ if LargeInt.< (secs, s_cutoff) then
+ LargeInt.toString secs ^ " seconds"
+ else if LargeInt.< (secs, m_cutoff) then
+ LargeInt.toString (LargeInt.div (secs, s_cutoff)) ^ " minutes"
+ else if LargeInt.< (secs, h_cutoff) then
+ LargeInt.toString (LargeInt.div (secs, m_cutoff)) ^ " hours"
+ else
+ LargeInt.toString (LargeInt.div (secs, h_cutoff)) ^ " days"
+ end
+