Код: Выделить всё
--Format CheckTime(HH:MM-HH:MM,W-W,DD-DD,MM-MM,YYYY-YYYY)
--Возвращает True, если текущее время входит в заданные рамки.
CheckTime = function(time,weekday,day,month,year)
local date ={
["hourbegin"]=tonumber(string.sub(time,1,2)),
["hourend"]=tonumber(string.sub(time,-5,-4)),
["minutebegin"]=tonumber(string.sub(time,4,5)),
["minuteend"]=tonumber(string.sub(time,-2,-1)),
["weekdaybegin"]=tonumber(string.sub(weekday,1,1)),
["weekdayend"]=tonumber(string.sub(weekday,-1)),
["daybegin"]=tonumber(string.sub(day,1,2)),
["dayend"]=tonumber(string.sub(day,-2,-1)),
["monthbegin"]=tonumber(string.sub(month,1,2)),
["monthend"]=tonumber(string.sub(month,-2,-1)),
["yearbegin"]=tonumber(string.sub(year,1,4)),
["yearend"]=tonumber(string.sub(year,-4,-1))
}
local datenow ={
["hour"]=tonumber(os.date("%H")),
["minute"]=tonumber(os.date("%M")),
["weekday"]=tonumber(os.date("%w")),
["day"]=tonumber(os.date("%d")),
["month"]=tonumber(os.date("%m")),
["year"]=tonumber(os.date("%Y"))
}
if ((datenow.minute<date.minutebegin) and (datenow.hour<date.hourbegin)) or ((datenow.minute>date.minuteend) and (datenow.hour>date.hourend)) then
return false;
elseif (datenow.weekday<date.weekdaybegin) or (datenow.weekday>date.weekdayend) then
return false;
elseif (datenow.day<date.daybegin) or (datenow.day>date.dayend) then
return false;
elseif (datenow.month<date.monthbegin) or (datenow.month>date.monthend) then
return false;
elseif (datenow.year<date.yearbegin) or (datenow.year>date.yearend) then
return false;
else
return true;
end;
end;