Module lua-nucleo.timestamp

Timestamp-related utilities

This file is a part of lua-nucleo library

Info:

  • Copyright: lua-nucleo authors (see file COPYRIGHT for the license)

Fields

MAX_TIMESTAMP Unix/POSIX time of the latest possible point of time in the future beyond which calculations are impossible by the module.

Local Functions

get_day_timestamp (timestamp)
get_yesterday_timestamp (timestamp)
get_tomorrow_timestamp (timestamp)
get_quarter_timestamp (timestamp)
get_minute_timestamp (timestamp)
get_decasecond_timestamp (timestamp)
unpack_timestamp ([timestamp=os_time()]) Convert Unix time to the (year, month, day, hour, minute, second) tuple.
make_timestamp_from_string (str[, format="^(%d%d)%.(%d%d)%.(%d%d%d%d) (%d%d):(%d%d):(%d%d)"]) Parses the input string according to datetime format.


Fields

MAX_TIMESTAMP
Unix/POSIX time of the latest possible point of time in the future beyond which calculations are impossible by the module.

Local Functions

get_day_timestamp (timestamp)

Parameters:

  • timestamp number

Returns:

    number,number
get_yesterday_timestamp (timestamp)

Parameters:

  • timestamp number

Returns:

    number,number
get_tomorrow_timestamp (timestamp)

Parameters:

  • timestamp number

Returns:

    number,number
get_quarter_timestamp (timestamp)

Parameters:

  • timestamp number

Returns:

    number
get_minute_timestamp (timestamp)

Parameters:

  • timestamp number

Returns:

    number
get_decasecond_timestamp (timestamp)

Parameters:

  • timestamp number

Returns:

    number
unpack_timestamp ([timestamp=os_time()])
Convert Unix time to the (year, month, day, hour, minute, second) tuple.

Parameters:

  • timestamp number Optional timestamp in the Unix/POSIX time format. (default os_time())

Returns:

    number,number,number,number,number,number Year, month, day of month, hour, minute and second of the timestamp was being provided or the current time if not.

Usage:

    local unpack_timestamp
          = import 'lua-nucleo/timestamp.lua'
          {
            'unpack_timestamp'
          }
    
    local push_date = function(year, month, day, hour, minute, second)
      -- do something
    end
    
    push_date(unpack_timestamp())
make_timestamp_from_string (str[, format="^(%d%d)%.(%d%d)%.(%d%d%d%d) (%d%d):(%d%d):(%d%d)"])
Parses the input string according to datetime format. Calculates a Unit/POSIX timestamp using parsed values.

Parameters:

  • str string A string to be parsed.
  • format string A format to be used by the parser in a form of the Lua string pattern where first 6 six captures should be defined in the following order:
    • day of month
    • month number by count
    • four digits year
    • 24h format hour
    • minute
    • second
    Each of the captures should be parsable to number. (default "^(%d%d)%.(%d%d)%.(%d%d%d%d) (%d%d):(%d%d):(%d%d)")

Returns:

    number Resulted timestamp.

Or

    nil If parse errors are occurred.

Usage:

    local make_timestamp_from_string
          = import 'lua-nucleo/timestamp.lua'
          {
            'make_timestamp_from_string'
          }
    
    local time1 = make_timestamp_from_string('04.02.2021 09:18:03')
    
    local format = '^d=(%d+),m=(%d+),y=(%d+) time="(%d%d):(%d%d):(%d%d)"'
    local time2 = make_timestamp_from_string(
        'd=4,m=2,y=2021 time="09:18:03"',
        format
      )
generated by LDoc 1.4.6 Last updated 2021-04-22 13:57:02