src/Pure/General/time.scala
author wenzelm
Thu May 24 22:07:00 2012 +0200 (2012-05-24)
changeset 47993 135fd6f2dadd
parent 46768 46acd255810d
child 50298 1426d478ccda
permissions -rw-r--r--
less warning in scala-2.10.0-M3;
wenzelm@45674
     1
/*  Title:      Pure/General/time.scala
wenzelm@45673
     2
    Module:     PIDE
wenzelm@40393
     3
    Author:     Makarius
wenzelm@40393
     4
wenzelm@45674
     5
Time based on milliseconds.
wenzelm@40393
     6
*/
wenzelm@40393
     7
wenzelm@40393
     8
package isabelle
wenzelm@40393
     9
wenzelm@45664
    10
wenzelm@40848
    11
object Time
wenzelm@40393
    12
{
wenzelm@47993
    13
  def seconds(s: Double): Time = new Time((s * 1000.0).round)
wenzelm@44699
    14
  def ms(m: Long): Time = new Time(m)
wenzelm@40393
    15
}
wenzelm@40393
    16
wenzelm@46712
    17
final class Time private(val ms: Long)
wenzelm@40848
    18
{
wenzelm@40848
    19
  def seconds: Double = ms / 1000.0
wenzelm@40852
    20
wenzelm@40852
    21
  def min(t: Time): Time = if (ms < t.ms) this else t
wenzelm@40852
    22
  def max(t: Time): Time = if (ms > t.ms) this else t
wenzelm@40852
    23
wenzelm@46768
    24
  def is_relevant: Boolean = ms >= 1
wenzelm@46768
    25
wenzelm@40848
    26
  override def toString =
wenzelm@40848
    27
    String.format(java.util.Locale.ROOT, "%.3f", seconds.asInstanceOf[AnyRef])
wenzelm@46768
    28
wenzelm@40848
    29
  def message: String = toString + "s"
wenzelm@40848
    30
}
wenzelm@40848
    31