Skip to content

Commit 035bef4

Browse files
committed
Fix formatting and function sorting
1 parent c923588 commit 035bef4

File tree

1 file changed

+83
-77
lines changed

1 file changed

+83
-77
lines changed

docs/modules/time.md

Lines changed: 83 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,79 @@
1-
# Timer Module
1+
# Time/NTP Module
22
| Since | Origin / Contributor | Maintainer | Source |
33
| :----- | :-------------------- | :---------- | :------ |
44
| 2018-11-25 | [Skirmantas Lauzikas](https://github.com/x-logLT) | [Skirmantas Lauzikas](https://github.com/x-logLT) | [time.c](../../components/modules/time.c)|
55

6-
This module offers facilities for coverting beteen unix time and calendar, setting/getting system time, locale and controll of NTP client.
6+
This module offers facilities for converting between Unix time and calendar, setting/getting system time, locale and control of NTP client.
77

8-
## time.set()
9-
Sets system time to a given timestamp in the Unix epoch (i.e. seconds from midnight 1970/01/01).
8+
## time.cal2epoch()
9+
Converts calendar table to a timestamp in Unix epoch
1010

1111
#### Syntax
12-
`time.set(time)`
12+
`time.cal2epoch(calendar)`
13+
14+
#### Parameters
15+
- `calendar` Table containing calendar info.
16+
- `year` 1970 ~ 2038
17+
- `mon` month 1 ~ 12 in current year
18+
- `day` day 1 ~ 31 in current month
19+
- `hour`
20+
- `min`
21+
- `sec`
22+
23+
#### Returns
24+
number of seconds since the Epoch
25+
26+
#### Example
27+
28+
```lua
29+
calendar={}
30+
calendar.year = 2018-11-20
31+
calendar.mon = 11
32+
calendar.day = 20
33+
calendar.hour = 1
34+
calendar.min = 40
35+
calendar.sec = 50
36+
37+
timestamp = time.cal2epoch(calendar)
38+
time.set(timestamp)
39+
```
40+
41+
42+
## time.epoch2cal()
43+
Converts timestamp in Unix epoch to calendar format
44+
45+
#### Syntax
46+
`time.epoch2cal(time)
1347

1448
#### Parameters
1549
- `time` number of seconds since the Epoch
1650

1751
#### Returns
18-
`nil'
52+
A table containing the fields:
53+
54+
- `year` 1970 ~ 2038
55+
- `mon` month 1 ~ 12 in current year
56+
- `day` day 1 ~ 31 in current month
57+
- `hour`
58+
- `min`
59+
- `sec`
60+
- `yday` day 1 ~ 366 in current year
61+
- `wday` day 1 ~ 7 in current weak (Sunday is 1)
62+
- `dst` day time adjustment:
63+
- 1 (DST in effect, i.e. daylight time)
64+
- 0 (DST not in effect, i.e. standard time)
65+
- -1 (Unknown DST status)
1966

2067
#### Example
2168
```lua
22-
--set time to 2018-11-20 01:40:50
23-
time.set(1542678050)
69+
--Gets current time calendar format, no locale adjustment
70+
time = time.epoch2cal(time.get())
71+
print(string.format("%04d-%02d-%02d %02d:%02d:%02d DST:%d", time["year"], time["mon"], time["day"], time["hour"], time["min"], time["sec"], time["dst"]))
2472
```
2573

26-
#### See also
27-
[`time.cal2epoc()`](#timecal2epoch)
2874

2975
## time.get()
30-
Returns current system time in the Unix epoch (i.e. seconds from midnight 1970/01/01).
76+
Returns current system time in the Unix epoch (seconds from midnight 1970/01/01).
3177

3278
#### Syntax
3379
time.get()
@@ -49,6 +95,7 @@ sec, usec = time.get()
4995
#### See also
5096
[`time.epch2cal()`](#timeepoch2cal)
5197

98+
5299
## time.getlocal()
53100
Returns current system time adjusted for the locale in calendar format.
54101

@@ -80,32 +127,14 @@ localTime = time.getlocal()
80127
print(string.format("%04d-%02d-%02d %02d:%02d:%02d DST:%d", localTime["year"], localTime["mon"], localTime["day"], localTime["hour"], localTime["min"], localTime["sec"], localTime["dst"]))
81128
```
82129

83-
## time.settimezone()
84-
Sets correct format for Time Zone locale
85-
86-
#### Syntax
87-
`time.settimezone(timezone)`
88-
89-
#### Parameters
90-
- `timezone` a string representing timezone, can also include DST adjustment. For full syntax see [TZ variable documentation](http://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html).
91-
92-
#### Returns
93-
`nil`
94-
95-
#### Example
96-
```lua
97-
--set timezone to Eastern Standard Time
98-
time.settimezone("EST+5")
99-
```
100-
101130
## time.initntp()
102-
Initializes and starts ntp client
131+
Initializes and starts NTP client
103132

104133
#### Syntax
105134
`time.initntp([ntpAddr])`
106135

107136
#### Parameters
108-
- `ntpAddr` address of a ntp server, defaults to "pool.ntp.org" if none is specified
137+
- `ntpAddr` address of a NTP server, defaults to "pool.ntp.org" if none is specified
109138

110139
#### Returns
111140
`nil`
@@ -115,8 +144,9 @@ Initializes and starts ntp client
115144
time.initntp("pool.ntp.org")
116145
```
117146

147+
118148
## time.ntpenabled()
119-
Checks if ntp client is enabled.
149+
Checks if NTP client is enabled.
120150

121151
#### Syntax
122152
`time.ntpenabled()`
@@ -125,10 +155,11 @@ Checks if ntp client is enabled.
125155
none
126156

127157
#### Returns
128-
`true' if ntp client is enabled.
158+
`true' if NTP client is enabled.
159+
129160

130161
## time.ntpstop()
131-
Stops ntp client.
162+
Stops NTP client.
132163

133164
#### Syntax
134165
`time.ntpstop()`
@@ -139,68 +170,43 @@ none
139170
#### Returns
140171
`nil`
141172

142-
## time.epoch2cal()
143-
Converts timestamp in Unix epoch to calendar format
173+
174+
## time.set()
175+
Sets system time to a given timestamp in the Unix epoch (seconds from midnight 1970/01/01).
144176

145177
#### Syntax
146-
`time.epoch2cal(time)
178+
`time.set(time)`
147179

148180
#### Parameters
149181
- `time` number of seconds since the Epoch
150182

151183
#### Returns
152-
A table containing the fields:
153-
154-
- `year` 1970 ~ 2038
155-
- `mon` month 1 ~ 12 in current year
156-
- `day` day 1 ~ 31 in current month
157-
- `hour`
158-
- `min`
159-
- `sec`
160-
- `yday` day 1 ~ 366 in current year
161-
- `wday` day 1 ~ 7 in current weak (Sunday is 1)
162-
- `dst` day time adjustment:
163-
- 1 (DST in effect, i.e. daylight time)
164-
- 0 (DST not in effect, i.e. standard time)
165-
- -1 (Unknown DST status)
184+
`nil`
166185

167186
#### Example
168187
```lua
169-
--Gets current time calendar format, no locale adjustment
170-
time = time.epoch2cal(time.get())
171-
print(string.format("%04d-%02d-%02d %02d:%02d:%02d DST:%d", time["year"], time["mon"], time["day"], time["hour"], time["min"], time["sec"], time["dst"]))
188+
--set time to 2018-11-20 01:40:50
189+
time.set(1542678050)
172190
```
173191

174-
## time.cal2epoch()
175-
Converts calendar table to a timestamp in Unix epoch
192+
#### See also
193+
[`time.cal2epoc()`](#timecal2epoch)
194+
195+
196+
## time.settimezone()
197+
Sets correct format for Time Zone locale
176198

177199
#### Syntax
178-
`time.cal2epoch(calendar)`
200+
`time.settimezone(timezone)`
179201

180202
#### Parameters
181-
- `calendar` Table containing calendar info.
182-
- `year` 1970 ~ 2038
183-
- `mon` month 1 ~ 12 in current year
184-
- `day` day 1 ~ 31 in current month
185-
- `hour`
186-
- `min`
187-
- `sec`
203+
- `timezone` a string representing timezone, can also include DST adjustment. For full syntax see [TZ variable documentation](http://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html).
188204

189205
#### Returns
190-
number of seconds since the Epoch
206+
`nil`
191207

192208
#### Example
193-
194209
```lua
195-
calendar={}
196-
calendar.year = 2018-11-20
197-
calendar.mon = 11
198-
calendar.day = 20
199-
calendar.hour = 1
200-
calendar.min = 40
201-
calendar.sec = 50
202-
203-
timestamp = time.cal2epoch(calendar)
204-
time.set(timestamp)
210+
--set timezone to Eastern Standard Time
211+
time.settimezone("EST+5")
205212
```
206-

0 commit comments

Comments
 (0)