sourcework/xetal-extensions/extensions/clock/lib/Clock.xtl
1⍝│ Clock.xtl -- the facade of the clock extension: wall-clock and
2⍝│ monotonic time, which X_eTaL does not have, for timestamps and timing.
3⍝│ Import: "ck:" u_se< "Clock"
4⍝│ Run with xetal-x (xetal-x --ext DIR puts this directory on XETAL_PATH).
5⍝│ Each signature line is written out by the binding macro (lib/Ffi.xtlm).
6
7"ffi:" u̲se< "Ffi"
8
9⍝│ Seconds since 1970-01-01 UTC, with the fraction.
10"n_ow : unit -> float" ᶠᶠⁱb̲ind< "clock/now"
11⍝│ The current time as ISO 8601 UTC text, to the millisecond.
12"i_so : unit -> text" ᶠᶠⁱb̲ind< "clock/iso"
13⍝│ Unix seconds as ISO 8601 UTC text: ck:i_soOf 0 is 1970-01-01T00:00:00.000Z.
14"i_soOf : float -> text" ᶠᶠⁱb̲ind< "clock/iso_of"
15⍝│ Milliseconds on a monotonic clock (it never goes back).
16"m_illis : unit -> float" ᶠᶠⁱb̲ind< "clock/millis"
17
18⍝│ How many milliseconds f_ x takes: 'r_ange ck:t_ime 1000000 (written in
19⍝│ X_eTaL over m_illis).
20ˡt̲ime ← { f̲ x →
21 a ← ˡm̲illis @
22 r ← f̲ x
23 (ˡm̲illis @) − a
24}
25
26⍝│ The native package behind these functions.
27ˡpackage ← "clock"
ᶠᶠⁱb̲ind< expands to
ˡi̲soOf ← { a → pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:clock/iso_of?float=" c̲at f̲ormat s̲hape a ⎕N̲GET "ext:clock/iso_of" }