src/ez/timer.bend
ezx@1.11.0.0 · 55 lines · 7 definitions
1
2
3
4
5
6import Base
7import snap@1.4.0.0/main.bend as R
8import ezx@1.11.0.0/src/share/env.bend as Env
9import ezx@1.11.0.0/src/ez/clock.bend as Clock
10
11
12
13
14def seconds() -> IO(String):
15 Env.var("EZ_DEADLINE", "300")
16
17
18
19def by(+secs: String) -> IO(String):
20 do IO<String>:
21 +out : String <- R.exec(["date", "-d", "+" ++ secs ++ " seconds", "+%s"])
22 return String.trim(R.text(out))
23
24
25def start.go(keep: Bool, +secs: String) -> IO(String):
26 match keep:
27 case False{}:
28 IO.pure(String, "")
29 case True{}:
30 by(secs)
31
32
33def start(+secs: String) -> IO(String):
34 start.go(Clock.on(secs), secs)
35
36
37def over.now(+deadline: String) -> IO(Bool):
38 do IO<Bool>:
39 +now : String <- R.exec(["date", "+%s"])
40 +cmp : String <- R.exec(["test", String.trim(R.text(now)), "-gt", deadline])
41 return R.ok(cmp)
42
43
44
45def over.go(none: Bool, +deadline: String) -> IO(Bool):
46 match none:
47 case True{}:
48 IO.pure(Bool, False{})
49 case False{}:
50 over.now(deadline)
51
52
53
54def over(+deadline: String) -> IO(Bool):
55 over.go(String.is_empty(deadline), deadline)