author | wenzelm |
Thu, 06 Feb 2025 13:29:28 +0100 | |
changeset 82093 | a0b2cd020a8b |
parent 82092 | 93195437fdee |
permissions | -rw-r--r-- |
73383
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/General/time.scala |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
3 |
|
82093 | 4 |
Time based on nanoseconds (idealized), printed as milliseconds. |
73383
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
5 |
*) |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
6 |
|
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
7 |
signature TIME = |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
8 |
sig |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
9 |
include TIME |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
10 |
val min: time * time -> time |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
11 |
val max: time * time -> time |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
12 |
val scale: real -> time -> time |
82092 | 13 |
val parse: string -> time |
14 |
val print: time -> string |
|
15 |
val message: time -> string |
|
73383
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
16 |
end; |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
17 |
|
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
18 |
structure Time: TIME = |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
19 |
struct |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
20 |
|
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
21 |
open Time; |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
22 |
|
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
23 |
fun min (t1, t2) = if t1 < t2 then t1 else t2; |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
24 |
fun max (t1, t2) = if t1 > t2 then t1 else t2; |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
25 |
|
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
26 |
fun scale s t = Time.fromNanoseconds (Real.ceil (s * Real.fromInt (Time.toNanoseconds t))); |
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
27 |
|
82092 | 28 |
fun parse s = |
29 |
(case Time.fromString s of |
|
30 |
SOME t => t |
|
31 |
| NONE => raise Fail ("Bad time " ^ quote s)); |
|
32 |
||
33 |
fun print t = |
|
34 |
if t < Time.zeroTime then "-" ^ Time.toString (Time.zeroTime - t) |
|
35 |
else Time.toString t; |
|
36 |
||
37 |
fun message t = print t ^ "s"; |
|
38 |
||
73383
6b104dc069de
clarified signature --- augment existing structure Time;
wenzelm
parents:
diff
changeset
|
39 |
end; |