Commit 035bef40 authored by Marcel Stör's avatar Marcel Stör
Browse files

Fix formatting and function sorting

parent c923588b
# Timer Module # Time/NTP Module
| Since | Origin / Contributor | Maintainer | Source | | Since | Origin / Contributor | Maintainer | Source |
| :----- | :-------------------- | :---------- | :------ | | :----- | :-------------------- | :---------- | :------ |
| 2018-11-25 | [Skirmantas Lauzikas](https://github.com/x-logLT) | [Skirmantas Lauzikas](https://github.com/x-logLT) | [time.c](../../components/modules/time.c)| | 2018-11-25 | [Skirmantas Lauzikas](https://github.com/x-logLT) | [Skirmantas Lauzikas](https://github.com/x-logLT) | [time.c](../../components/modules/time.c)|
This module offers facilities for coverting beteen unix time and calendar, setting/getting system time, locale and controll of NTP client. This module offers facilities for converting between Unix time and calendar, setting/getting system time, locale and control of NTP client.
## time.set() ## time.cal2epoch()
Sets system time to a given timestamp in the Unix epoch (i.e. seconds from midnight 1970/01/01). Converts calendar table to a timestamp in Unix epoch
#### Syntax #### Syntax
`time.set(time)` `time.cal2epoch(calendar)`
#### Parameters
- `calendar` Table containing calendar info.
- `year` 1970 ~ 2038
- `mon` month 1 ~ 12 in current year
- `day` day 1 ~ 31 in current month
- `hour`
- `min`
- `sec`
#### Returns
number of seconds since the Epoch
#### Example
```lua
calendar={}
calendar.year = 2018-11-20
calendar.mon = 11
calendar.day = 20
calendar.hour = 1
calendar.min = 40
calendar.sec = 50
timestamp = time.cal2epoch(calendar)
time.set(timestamp)
```
## time.epoch2cal()
Converts timestamp in Unix epoch to calendar format
#### Syntax
`time.epoch2cal(time)
#### Parameters #### Parameters
- `time` number of seconds since the Epoch - `time` number of seconds since the Epoch
#### Returns #### Returns
`nil' A table containing the fields:
- `year` 1970 ~ 2038
- `mon` month 1 ~ 12 in current year
- `day` day 1 ~ 31 in current month
- `hour`
- `min`
- `sec`
- `yday` day 1 ~ 366 in current year
- `wday` day 1 ~ 7 in current weak (Sunday is 1)
- `dst` day time adjustment:
- 1 (DST in effect, i.e. daylight time)
- 0 (DST not in effect, i.e. standard time)
- -1 (Unknown DST status)
#### Example #### Example
```lua ```lua
--set time to 2018-11-20 01:40:50 --Gets current time calendar format, no locale adjustment
time.set(1542678050) time = time.epoch2cal(time.get())
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"]))
``` ```
#### See also
[`time.cal2epoc()`](#timecal2epoch)
## time.get() ## time.get()
Returns current system time in the Unix epoch (i.e. seconds from midnight 1970/01/01). Returns current system time in the Unix epoch (seconds from midnight 1970/01/01).
#### Syntax #### Syntax
time.get() time.get()
...@@ -49,6 +95,7 @@ sec, usec = time.get() ...@@ -49,6 +95,7 @@ sec, usec = time.get()
#### See also #### See also
[`time.epch2cal()`](#timeepoch2cal) [`time.epch2cal()`](#timeepoch2cal)
## time.getlocal() ## time.getlocal()
Returns current system time adjusted for the locale in calendar format. Returns current system time adjusted for the locale in calendar format.
...@@ -80,32 +127,14 @@ localTime = time.getlocal() ...@@ -80,32 +127,14 @@ localTime = time.getlocal()
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"])) 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"]))
``` ```
## time.settimezone()
Sets correct format for Time Zone locale
#### Syntax
`time.settimezone(timezone)`
#### Parameters
- `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).
#### Returns
`nil`
#### Example
```lua
--set timezone to Eastern Standard Time
time.settimezone("EST+5")
```
## time.initntp() ## time.initntp()
Initializes and starts ntp client Initializes and starts NTP client
#### Syntax #### Syntax
`time.initntp([ntpAddr])` `time.initntp([ntpAddr])`
#### Parameters #### Parameters
- `ntpAddr` address of a ntp server, defaults to "pool.ntp.org" if none is specified - `ntpAddr` address of a NTP server, defaults to "pool.ntp.org" if none is specified
#### Returns #### Returns
`nil` `nil`
...@@ -115,8 +144,9 @@ Initializes and starts ntp client ...@@ -115,8 +144,9 @@ Initializes and starts ntp client
time.initntp("pool.ntp.org") time.initntp("pool.ntp.org")
``` ```
## time.ntpenabled() ## time.ntpenabled()
Checks if ntp client is enabled. Checks if NTP client is enabled.
#### Syntax #### Syntax
`time.ntpenabled()` `time.ntpenabled()`
...@@ -125,10 +155,11 @@ Checks if ntp client is enabled. ...@@ -125,10 +155,11 @@ Checks if ntp client is enabled.
none none
#### Returns #### Returns
`true' if ntp client is enabled. `true' if NTP client is enabled.
## time.ntpstop() ## time.ntpstop()
Stops ntp client. Stops NTP client.
#### Syntax #### Syntax
`time.ntpstop()` `time.ntpstop()`
...@@ -139,68 +170,43 @@ none ...@@ -139,68 +170,43 @@ none
#### Returns #### Returns
`nil` `nil`
## time.epoch2cal()
Converts timestamp in Unix epoch to calendar format ## time.set()
Sets system time to a given timestamp in the Unix epoch (seconds from midnight 1970/01/01).
#### Syntax #### Syntax
`time.epoch2cal(time) `time.set(time)`
#### Parameters #### Parameters
- `time` number of seconds since the Epoch - `time` number of seconds since the Epoch
#### Returns #### Returns
A table containing the fields: `nil`
- `year` 1970 ~ 2038
- `mon` month 1 ~ 12 in current year
- `day` day 1 ~ 31 in current month
- `hour`
- `min`
- `sec`
- `yday` day 1 ~ 366 in current year
- `wday` day 1 ~ 7 in current weak (Sunday is 1)
- `dst` day time adjustment:
- 1 (DST in effect, i.e. daylight time)
- 0 (DST not in effect, i.e. standard time)
- -1 (Unknown DST status)
#### Example #### Example
```lua ```lua
--Gets current time calendar format, no locale adjustment --set time to 2018-11-20 01:40:50
time = time.epoch2cal(time.get()) time.set(1542678050)
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"]))
``` ```
## time.cal2epoch() #### See also
Converts calendar table to a timestamp in Unix epoch [`time.cal2epoc()`](#timecal2epoch)
## time.settimezone()
Sets correct format for Time Zone locale
#### Syntax #### Syntax
`time.cal2epoch(calendar)` `time.settimezone(timezone)`
#### Parameters #### Parameters
- `calendar` Table containing calendar info. - `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).
- `year` 1970 ~ 2038
- `mon` month 1 ~ 12 in current year
- `day` day 1 ~ 31 in current month
- `hour`
- `min`
- `sec`
#### Returns #### Returns
number of seconds since the Epoch `nil`
#### Example #### Example
```lua ```lua
calendar={} --set timezone to Eastern Standard Time
calendar.year = 2018-11-20 time.settimezone("EST+5")
calendar.mon = 11
calendar.day = 20
calendar.hour = 1
calendar.min = 40
calendar.sec = 50
timestamp = time.cal2epoch(calendar)
time.set(timestamp)
``` ```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment