Skip to content

Commit ab230e4

Browse files
docs(timeutil): generate API docs (#7)
Co-authored-by: haithium <128622475+haithium@users.noreply.github.com>
1 parent 6040536 commit ab230e4

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

docs/src/timeutil/timeutil.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
description: "Wall-clock time, monotonic time, and native sleep utilities."
3+
---
4+
5+
# `timeutil`
6+
7+
Wall-clock time, monotonic time, and native sleep utilities.
8+
9+
```lua
10+
local timeutil = require("timeutil")
11+
local start = timeutil.mono()
12+
timeutil.sleep(0.1)
13+
print(timeutil.now() - start)
14+
```
15+
16+
## Functions
17+
18+
<a id="fn-mono"></a>
19+
20+
### `mono()`
21+
22+
Returns monotonic elapsed time in seconds.
23+
24+
**Return**:
25+
26+
- `seconds` (`number`)
27+
28+
**Example**:
29+
30+
```lua
31+
local time = require("timeutil")
32+
local monotime = time.mono
33+
34+
local start = monotime()
35+
time.sleep(0.5)
36+
local stop = monotime()
37+
38+
local elapsed_ms = math.floor((stop - start) * 1000)
39+
print(elapsed_ms.."ms") --> 500ms
40+
```
41+
42+
<a id="fn-now"></a>
43+
44+
### `now()`
45+
46+
Returns wall-clock Unix time in seconds.
47+
48+
**Return**:
49+
50+
- `seconds` (`number`)
51+
52+
**Example**:
53+
54+
```lua
55+
local time = require("timeutil")
56+
local now = time.now()
57+
local seconds = math.floor(now)
58+
local ms = math.floor((now - seconds) * 1000)
59+
local dt = string.format("%s.%03d", os.date("%Y-%m-%d %H:%M:%S", seconds), ms)
60+
print(dt) --> YYYY-MM-DD HH:mm:ss.SSS
61+
```
62+
63+
<a id="fn-sleep"></a>
64+
65+
### `sleep(seconds)`
66+
67+
Blocks the current thread for the requested non-negative duration.
68+
69+
**Parameters**:
70+
71+
- `seconds` (`number`)
72+
73+
**Example**:
74+
75+
```lua
76+
local time = require("timeutil")
77+
time.sleep(1.5) -- sleep for 1.5 seconds
78+
```

0 commit comments

Comments
 (0)