function main (userId) now = os.time() working_time = ifInRangeHHMM(now, 20,0,8,0) TRACE("working_time = " .. tostring(working_time)) if working_time then -- Add your code here end end function ifInRangeHHMM(now, start_hour, start_min, end_hour, end_min) -- проверяет текущее время на попадание в диапазон час минута out = false local cur_HH, cur_MM = tonumber(os.date("%H", now)), tonumber(os.date("%M", now)) -- TRACE("now = " .. os.date("%X %x", now) .. " " .. cur_HH .. ":" .. cur_MM) not_splitted_midnight_shift = start_hour < end_hour or start_hour == end_hour and start_min < end_min if not_splitted_midnight_shift then local after_start = (cur_HH > start_hour) or (cur_HH == start_hour and cur_MM >= start_min) local before_end = (cur_HH < end_hour) or (cur_HH == end_hour and cur_MM <= end_min) -- TRACE("after_start =" .. tostring(after_start)) -- TRACE("before_end =" .. tostring(before_end)) out = after_start and before_end ; --TRACE("going to return " .. tostring(out)) else TRACE("ifInRangeHHMM: Range is midnight splitted") out = ifInRangeHHMM(now, start_hour, start_min, 23, 59) or ifInRangeHHMM(now, 0, 0, end_hour, end_min) end return out end