silo:std.temporal
Source src/silo:std.temporal
1
2
3
4
5
6
7
8
9
10
11
12
13:use
14 :open core AnyInt Bool Ordering
15 :open traits Add Sub Mul Div Eq Ord
16:end
17
18
19:record(pub) IDuration .nanos AnyInt :end
20
21
22
23
24
25:record(pub) UDuration .nanos AnyInt :end
26
27
28:record(pub) Instant .nanos AnyInt :end
29
30
31
32
33
34
35
36
37
38
39
40
41:impl IDuration
42 .secs ( IDuration -> AnyInt )
43 .nanos 1000000000 / ;
44 .millis ( IDuration -> AnyInt )
45 .nanos 1000000 / ;
46 .micros ( IDuration -> AnyInt )
47 .nanos 1000 / ;
48 .is-zero ( IDuration -> Bool )
49 .nanos 0 = ;
50
51
52
53
54
55 .subsec-nanos ( IDuration -> AnyInt )
56 .nanos 1000000000 mod 1000000000 + 1000000000 mod ;
57 .subsec-micros ( IDuration -> AnyInt )
58 .nanos 1000 / 1000000 mod 1000000 + 1000000 mod ;
59 .subsec-millis ( IDuration -> AnyInt )
60 .nanos 1000000 / 1000 mod 1000 + 1000 mod ;
61:end
62
63
64
65
66
67:fn(pub) duration-from-secs ( AnyInt -> IDuration )
68 1000000000 * IDuration
69:end
70
71:fn(pub) duration-from-millis ( AnyInt -> IDuration )
72 1000000 * IDuration
73:end
74
75:fn(pub) duration-from-micros ( AnyInt -> IDuration )
76 1000 * IDuration
77:end
78
79:fn(pub) duration-from-nanos ( AnyInt -> IDuration )
80 IDuration
81:end
82
83:fn(pub) uduration-from-secs ( AnyInt -> UDuration )
84 1000000000 * UDuration
85:end
86
87:fn(pub) uduration-from-millis ( AnyInt -> UDuration )
88 1000000 * UDuration
89:end
90
91:fn(pub) uduration-from-micros ( AnyInt -> UDuration )
92 1000 * UDuration
93:end
94
95:fn(pub) uduration-from-nanos ( AnyInt -> UDuration )
96 UDuration
97:end
98
99
100
101
102:impl UDuration
103 .subsec-nanos ( UDuration -> AnyInt )
104 .nanos 1000000000 mod ;
105 .subsec-micros ( UDuration -> AnyInt )
106 .nanos 1000 / 1000000 mod ;
107 .subsec-millis ( UDuration -> AnyInt )
108 .nanos 1000000 / 1000 mod ;
109:end
110
111
112:impl Eq IDuration IDuration
113 .= ( IDuration IDuration -> Bool )
114 pop-> b pop-> a
115 a .nanos b .nanos = ;
116:end
117
118:impl Ord IDuration IDuration
119 .< ( IDuration IDuration -> Bool )
120 pop-> b pop-> a
121 a .nanos b .nanos < ;
122 .> ( IDuration IDuration -> Bool )
123 pop-> b pop-> a
124 a .nanos b .nanos > ;
125:end
126
127
128:impl Eq Instant Instant
129 .= ( Instant Instant -> Bool )
130 pop-> b pop-> a
131 a .nanos b .nanos = ;
132:end
133
134:impl Ord Instant Instant
135 .< ( Instant Instant -> Bool )
136 pop-> b pop-> a
137 a .nanos b .nanos < ;
138 .> ( Instant Instant -> Bool )
139 pop-> b pop-> a
140 a .nanos b .nanos > ;
141:end
142
143
144:impl Instant
145 .duration-since ( Instant Instant -> IDuration )
146 pop-> earlier pop-> later
147 later .nanos earlier .nanos - IDuration ;
148:end