Module posix.time
Time and Clock Functions.
Functions
| clock_getres (clk) | Find the precision of a clock. |
| clock_gettime (clk) | Read a clock. |
| gmtime (t) | Convert epoch time value to a broken-down UTC time. |
| localtime (t) | Convert epoch time value to a broken-down local time. |
| mktime (broken) | Convert a broken-down localtime table into an epoch time. |
| nanosleep (requested) | Sleep with nanosecond precision. |
| strftime (format, tm) | Return a time string according to format. |
| strptime (s, format) | Parse a date string. |
| time () | Get current time. |
| tzset () | Apply the TZ environment variable to the timezone information used by
functions such as localtime, mktime and strftime. |
Tables
| PosixTimespec | Timespec record. |
| PosixTm | Datetime record. |
Constants
| posix.time | Standard constants. |
Functions
- clock_getres (clk)
-
Find the precision of a clock.
Parameters:
- clk
int
name of clock, one of
CLOCK_REALTIME,CLOCK_PROCESS_CPUTIME_ID,CLOCK_MONOTONICorCLOCK_THREAD_CPUTIME_ID
Returns:
-
PosixTimespec
resolution of clk, if successful
Or
- nil
- string error message
- int errnum
See also:
- clk
int
name of clock, one of
- clock_gettime (clk)
-
Read a clock.
Parameters:
- clk
int
name of clock, one of
CLOCK_REALTIME,CLOCK_PROCESS_CPUTIME_ID,CLOCK_MONOTONICorCLOCK_THREAD_CPUTIME_ID
Returns:
-
PosixTimespec
current value of clk, if successful
Or
- nil
- string error message
- int errnum
See also:
- clk
int
name of clock, one of
- gmtime (t)
-
Convert epoch time value to a broken-down UTC time.
Parameters:
- t int seconds since epoch
Returns:
-
PosixTm
broken-down time, if successful
Or
- nil
- string error message
- int errnum
See also:
- localtime (t)
-
Convert epoch time value to a broken-down local time.
Parameters:
- t int seconds since epoch
Returns:
-
PosixTm
broken-down time, if successful
Or
- nil
- string error message
- int errnum
See also:
- mktime (broken)
-
Convert a broken-down localtime table into an epoch time.
Parameters:
- broken PosixTm -down localtime
Returns:
-
int
seconds since epoch
See also:
- nanosleep (requested)
-
Sleep with nanosecond precision.
Parameters:
- requested PosixTimespec sleep time
Returns:
-
int
0if requested time has elapsed, if successfulOr
- nil
- string error message
- int errnum
- PosixTimespec unslept time remaining, if interrupted
See also:
- strftime (format, tm)
-
Return a time string according to format.
Note that if your host POSIX library provides a
strftimethat assumes the local timezone, %z will always print the local UTC offset, regardless of thetm_gmoffsetfield value passed in.Parameters:
Returns:
-
string
format with place-holders plugged with tm values
See also:
- strptime (s, format)
-
Parse a date string.
Parameters:
Returns:
- PosixTm broken-down local time
- int next index of first character not parsed as part of the date, if successful
Or
-
nil
See also:
Usage:
posix.strptime('20','%d').monthday == 20
- time ()
-
Get current time.
Returns:
-
int
time in seconds since epoch, if successful
Or
- nil
- string error message
- int errnum
See also:
- tzset ()
-
Apply the
TZenvironment variable to the timezone information used by functions such as localtime, mktime and strftime.Some C libraries, such as the GNU one, do not notice a change of
TZmade with posix.stdlib.setenv untiltzsetis called.See also:
Usage:
local stdlib = require "posix.stdlib" local time = require "posix.time" stdlib.setenv("TZ", "UTC0") time.tzset()
Tables
- PosixTimespec
-
Timespec record.
Fields:
- tv_sec int seconds
- tv_nsec int nanoseconds
See also:
- PosixTm
-
Datetime record.
Fields:
- tm_sec int second [0,60]
- tm_min int minute [0,59]
- tm_hour int hour [0,23]
- tm_mday int day of month [1, 31]
- tm_mon int month of year [0,11]
- tm_year int years since 1900
- tm_wday int day of week [0=Sunday,6]
- tm_yday int day of year [0,365[
- tm_isdst int 0 if daylight savings time is not in effect
Constants
- posix.time
-
Standard constants.
Any constants not available in the underlying system will be
nilvalued.Fields:
- CLOCK_MONOTONIC int the identifier for the system-wide monotonic clock
- CLOCK_PROCESS_CPUTIME_ID int the identifier for the current process CPU-time clock
- CLOCK_REALTIME int the identifier for the system-wide realtime clock
- CLOCK_THREAD_CPUTIME_ID int the identifier for the current thread CPU-time clock
Usage:
-- Print posix.time constants supported on this host. for name, value in pairs (require "posix.time") do if type (value) == "number" then print (name, value) end end