author | paulson <lp15@cam.ac.uk> |
Wed, 18 Mar 2015 14:13:27 +0000 | |
changeset 59741 | 5b762cd73a8e |
parent 57912 | dd9550f84106 |
child 61528 | 053f7083b3eb |
permissions | -rw-r--r-- |
45674 | 1 |
/* Title: Pure/General/time.scala |
45673
cd41e3903fbf
separate compilation of PIDE vs. Pure sources, which enables independent Scala library;
wenzelm
parents:
45667
diff
changeset
|
2 |
Module: PIDE |
40393 | 3 |
Author: Makarius |
4 |
||
45674 | 5 |
Time based on milliseconds. |
40393 | 6 |
*/ |
7 |
||
8 |
package isabelle |
|
9 |
||
45664 | 10 |
|
50298 | 11 |
import java.util.Locale |
12 |
||
13 |
||
40848
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents:
40393
diff
changeset
|
14 |
object Time |
40393 | 15 |
{ |
47993 | 16 |
def seconds(s: Double): Time = new Time((s * 1000.0).round) |
44699
5199ee17c7d7
property "tooltip-dismiss-delay" is edited in ms, not seconds;
wenzelm
parents:
40852
diff
changeset
|
17 |
def ms(m: Long): Time = new Time(m) |
51587 | 18 |
val zero: Time = ms(0) |
56691 | 19 |
def now(): Time = ms(System.currentTimeMillis()) |
51533 | 20 |
|
21 |
def print_seconds(s: Double): String = |
|
22 |
String.format(Locale.ROOT, "%.3f", s.asInstanceOf[AnyRef]) |
|
40393 | 23 |
} |
24 |
||
56351 | 25 |
final class Time private(val ms: Long) extends AnyVal |
40848
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents:
40393
diff
changeset
|
26 |
{ |
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents:
40393
diff
changeset
|
27 |
def seconds: Double = ms / 1000.0 |
40852 | 28 |
|
56691 | 29 |
def + (t: Time): Time = new Time(ms + t.ms) |
30 |
def - (t: Time): Time = new Time(ms - t.ms) |
|
31 |
||
32 |
def < (t: Time): Boolean = ms < t.ms |
|
33 |
def <= (t: Time): Boolean = ms <= t.ms |
|
34 |
def > (t: Time): Boolean = ms > t.ms |
|
35 |
def >= (t: Time): Boolean = ms >= t.ms |
|
36 |
||
37 |
def min(t: Time): Time = if (this < t) this else t |
|
38 |
def max(t: Time): Time = if (this > t) this else t |
|
40852 | 39 |
|
53292
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
51587
diff
changeset
|
40 |
def is_zero: Boolean = ms == 0 |
46768 | 41 |
def is_relevant: Boolean = ms >= 1 |
42 |
||
57912 | 43 |
override def toString: String = Time.print_seconds(seconds) |
46768 | 44 |
|
40848
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents:
40393
diff
changeset
|
45 |
def message: String = toString + "s" |
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents:
40393
diff
changeset
|
46 |
} |
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents:
40393
diff
changeset
|
47 |