join: use generic sendmail instead of exim4
[hcoop/portal.git] / util.sml
index ee6c872..9c269c1 100644 (file)
--- a/util.sml
+++ b/util.sml
@@ -29,8 +29,12 @@ fun makeSet f items =
 
 fun neg (r : real) = ~r
 fun add (r1 : real, r2) = r1 + r2
+fun sub (r1 : real, r2) = r1 - r2
 fun mult (r1, r2) = real r1 * r2
 
+fun lt (r1 : real, r2) = r1 < r2
+fun ge (r1 : real, r2) = r1 >= r2
+
 fun isIdent ch = Char.isLower ch orelse Char.isDigit ch orelse ch = #"-"
 
 fun validHost s =
@@ -87,4 +91,22 @@ fun normEmail s = case String.tokens Char.isSpace (allLower s) of
                      s :: _ => s
                    | [] => ""
 
+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
+
 end