Skip to main content

Time

time.is_between#

-- @param timestamp number UNIX timestamp
-- @param since string in "hh:mm" 24h format
-- @param till string in "hh:mm" 24h format
-- @param timezone number timezone of since/till in seconds, e.g. -2*60*60 for "UTC-02:00"
function time.is_between(timestamp, since, till, timezone)
end

Checks if the timestamp is between the given interval boundaries. Interval is a timeframe in a clockwise direction. We start at since and finish at till.

note

You can use predefined constant TIMEZONE as timezone parameter value.

Example#

-- using UTC since and till values
local result = time.is_between(1657076400, '00:00', '02:00', 0)
enapter.log('03:00 is between 00:00 and 02:00: ' .. tostring(result))
-- 03:00 is between 00:00 and 02:00: false
-- using since and till values in local site's timezone
local result = time.is_between(1657076400, '02:00', '00:00', 0)
enapter.log('03:00 is between 02:00 and 00:00: ' .. tostring(result))
-- 03:00 is between 02:00 and 00:00: true

time.is_now_between#

-- @param since string in "hh:mm" 24h format
-- @param till string in "hh:mm" 24h format
-- @param timezone number timezone of since/till in seconds, e.g. -2*60*60 for "UTC-02:00"
function time.is_now_between(since, till, timezone)
end

The same as time.is_between, but uses os.time() for the target timestamp.

note

You can use predefined constant TIMEZONE as timezone parameter value.

Example#

-- using since and till values in local site's timezone
local result = time.is_now_between('08:00', '10:00', 0)
enapter.log('Current time is between 08:00 and 10:00: ' .. tostring(result))
-- Current time is between 00:00 and 02:00: false
Hardware diversity is welcome. Integrate any device into a unified energy network.
© 2022 Enapter
Developer toolkit
DocumentationReference
Community
GithubTindie