| author | wenzelm | 
| Thu, 13 Oct 2016 23:44:40 +0200 | |
| changeset 64202 | 967515846691 | 
| parent 64058 | ea528dc9962d | 
| child 64370 | 865b39487b5d | 
| 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  | 
| 64056 | 12  | 
import java.time.Instant  | 
| 50298 | 13  | 
|
14  | 
||
| 
40848
 
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
 
wenzelm 
parents: 
40393 
diff
changeset
 | 
15  | 
object Time  | 
| 40393 | 16  | 
{
 | 
| 47993 | 17  | 
def seconds(s: Double): Time = new Time((s * 1000.0).round)  | 
| 63700 | 18  | 
def minutes(s: Double): Time = new Time((s * 60000.0).round)  | 
| 
44699
 
5199ee17c7d7
property "tooltip-dismiss-delay" is edited in ms, not seconds;
 
wenzelm 
parents: 
40852 
diff
changeset
 | 
19  | 
def ms(m: Long): Time = new Time(m)  | 
| 63700 | 20  | 
def hms(h: Int, m: Int, s: Double): Time = seconds(s + 60 * m + 3600 * h)  | 
| 63686 | 21  | 
|
| 61528 | 22  | 
def now(): Time = ms(System.currentTimeMillis())  | 
23  | 
||
| 51587 | 24  | 
val zero: Time = ms(0)  | 
| 61528 | 25  | 
val start: Time = now()  | 
| 51533 | 26  | 
|
27  | 
def print_seconds(s: Double): String =  | 
|
28  | 
String.format(Locale.ROOT, "%.3f", s.asInstanceOf[AnyRef])  | 
|
| 64056 | 29  | 
|
| 64058 | 30  | 
def instant(t: Instant): Time = ms(t.getEpochSecond * 1000L + t.getNano / 1000000L)  | 
| 40393 | 31  | 
}  | 
32  | 
||
| 56351 | 33  | 
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
 | 
34  | 
{
 | 
| 
 
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
 
wenzelm 
parents: 
40393 
diff
changeset
 | 
35  | 
def seconds: Double = ms / 1000.0  | 
| 
63688
 
cc57255bf6ae
gnuplot presentation similar to former isatest-statistics;
 
wenzelm 
parents: 
63686 
diff
changeset
 | 
36  | 
def minutes: Double = ms / 60000.0  | 
| 40852 | 37  | 
|
| 56691 | 38  | 
def + (t: Time): Time = new Time(ms + t.ms)  | 
39  | 
def - (t: Time): Time = new Time(ms - t.ms)  | 
|
40  | 
||
| 61602 | 41  | 
def compare(t: Time): Int = ms compare t.ms  | 
| 56691 | 42  | 
def < (t: Time): Boolean = ms < t.ms  | 
43  | 
def <= (t: Time): Boolean = ms <= t.ms  | 
|
44  | 
def > (t: Time): Boolean = ms > t.ms  | 
|
45  | 
def >= (t: Time): Boolean = ms >= t.ms  | 
|
46  | 
||
47  | 
def min(t: Time): Time = if (this < t) this else t  | 
|
48  | 
def max(t: Time): Time = if (this > t) this else t  | 
|
| 40852 | 49  | 
|
| 
53292
 
f567c1c7b180
option to insert unique completion immediately into buffer;
 
wenzelm 
parents: 
51587 
diff
changeset
 | 
50  | 
def is_zero: Boolean = ms == 0  | 
| 46768 | 51  | 
def is_relevant: Boolean = ms >= 1  | 
52  | 
||
| 57912 | 53  | 
override def toString: String = Time.print_seconds(seconds)  | 
| 46768 | 54  | 
|
| 
40848
 
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
 
wenzelm 
parents: 
40393 
diff
changeset
 | 
55  | 
def message: String = toString + "s"  | 
| 62571 | 56  | 
|
57  | 
def message_hms: String =  | 
|
58  | 
  {
 | 
|
59  | 
val s = ms / 1000  | 
|
60  | 
String.format(Locale.ROOT, "%d:%02d:%02d",  | 
|
61  | 
new java.lang.Long(s / 3600), new java.lang.Long((s / 60) % 60), new java.lang.Long(s % 60))  | 
|
62  | 
}  | 
|
| 64056 | 63  | 
|
64  | 
def instant: Instant = Instant.ofEpochMilli(ms)  | 
|
| 
40848
 
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
 
wenzelm 
parents: 
40393 
diff
changeset
 | 
65  | 
}  |