-
Notifications
You must be signed in to change notification settings - Fork 3
/
time.gleam
59 lines (51 loc) · 1.03 KB
/
time.gleam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import gleam/int
import birl
import birl/duration
pub fn in_interval(from: birl.Time, to: birl.Time) -> birl.Time {
let unix_from = birl.to_unix(from)
let unix_to = birl.to_unix(to)
int.random(unix_from, unix_to)
|> birl.from_unix()
}
pub fn symmetric(distance: duration.Duration) {
let now = birl.now()
int.random(
now
|> birl.subtract(distance)
|> birl.to_unix,
now
|> birl.add(distance)
|> birl.to_unix,
)
|> birl.from_unix()
}
pub fn past(
min_distance: duration.Duration,
max_distance: duration.Duration,
) -> birl.Time {
let now = birl.now()
int.random(
now
|> birl.subtract(max_distance)
|> birl.to_unix,
now
|> birl.subtract(min_distance)
|> birl.to_unix,
)
|> birl.from_unix()
}
pub fn future(
min_distance: duration.Duration,
max_distance: duration.Duration,
) -> birl.Time {
let now = birl.now()
int.random(
now
|> birl.add(min_distance)
|> birl.to_unix,
now
|> birl.add(max_distance)
|> birl.to_unix,
)
|> birl.from_unix()
}