rl_lang/docs/entries/stdlib/time/
mod.rs1use crate::docs::entry::{FnEntry, StdEntry};
2
3pub static TIME: StdEntry = StdEntry {
4 name: "time",
5 description: "functions for getting the current time, formatting timestamps, and time arithmetic",
6 functions: FUNCTIONS,
7 since: None,
8 unstable: false,
9};
10
11static FUNCTIONS: &[&FnEntry] = &[
12 &NOW,
13 &NOW_MS,
14 &FORMAT_TIME,
15 &DATE_STR,
16 &TIME_STR,
17 &TIME_ADD,
18 &TIME_DIFF,
19 &TIME_PARTS,
20];
21
22static NOW: FnEntry = FnEntry {
23 signature: "time_now()",
24 description: "returns the current unix timestamp as an int (seconds since epoch)",
25 example: "get std::time::time_now\n\ntime_now() // 1719000000",
26 expected_output: None,
27 returns: "",
28 errors: None,
29 see_also: &[],
30 since: None,
31};
32
33static NOW_MS: FnEntry = FnEntry {
34 signature: "time_now_ms()",
35 description: "returns the current unix timestamp in milliseconds, useful for generating unique IDs",
36 example: "get std::time::time_now_ms\n\ntime_now_ms() // 1719000000000",
37 expected_output: None,
38 returns: "",
39 errors: None,
40 see_also: &[],
41 since: None,
42};
43
44static FORMAT_TIME: FnEntry = FnEntry {
45 signature: "format_time(timestamp, pattern)",
46 description: "formats a unix timestamp into a readable string using a pattern. supported tokens: %Y (year), %m (month), %d (day), %H (hour), %M (minute), %S (second)",
47 example: "get std::time::format_time\n\nformat_time(1719000000, \"%Y-%m-%d %H:%M:%S\") // \"2024-06-21 20:00:00\"",
48 expected_output: None,
49 returns: "",
50 errors: None,
51 see_also: &[],
52 since: None,
53};
54
55static DATE_STR: FnEntry = FnEntry {
56 signature: "format_date_str(timestamp)",
57 description: "shorthand for format_time with \"%Y-%m-%d\", returns the date portion of a unix timestamp",
58 example: "get std::time::format_date_str\n\nformat_date_str(1719000000) // \"2024-06-21\"",
59 expected_output: None,
60 returns: "",
61 errors: None,
62 see_also: &[],
63 since: None,
64};
65
66static TIME_STR: FnEntry = FnEntry {
67 signature: "format_time_str(timestamp)",
68 description: "shorthand for format_time with \"%H:%M:%S\", returns the time portion of a unix timestamp",
69 example: "get std::time::format_time_str\n\nformat_time_str(1719000000) // \"20:00:00\"",
70 expected_output: None,
71 returns: "",
72 errors: None,
73 see_also: &[],
74 since: None,
75};
76
77static TIME_ADD: FnEntry = FnEntry {
78 signature: "time_add(timestamp, seconds)",
79 description: "adds a number of seconds to a timestamp and returns the new timestamp",
80 example: "get std::time::time_add\n\ntime_add(1719000000, 3600) // 1719003600 (one hour later)",
81 expected_output: None,
82 returns: "",
83 errors: None,
84 see_also: &[],
85 since: None,
86};
87
88static TIME_DIFF: FnEntry = FnEntry {
89 signature: "time_diff(a, b)",
90 description: "returns the difference between two timestamps in seconds (a - b)",
91 example: "get std::time::time_diff\n\ntime_diff(1719003600, 1719000000) // 3600",
92 expected_output: None,
93 returns: "",
94 errors: None,
95 see_also: &[],
96 since: None,
97};
98
99static TIME_PARTS: FnEntry = FnEntry {
100 signature: "time_parts(timestamp)",
101 description: "returns an array of [year, month, day, hour, minute, second] for the given unix timestamp (UTC)",
102 example: "get std::time::time_parts\n\ntime_parts(1719000000) // [2024, 6, 21, 20, 0, 0]",
103 expected_output: None,
104 returns: "",
105 errors: None,
106 see_also: &[],
107 since: None,
108};