• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Tibia Time Comparision.

tarjei

Necronian Engineer
Joined
May 25, 2008
Messages
505
Reaction score
126
Location
Poland
Hello. I come up with writing this small lib. Its easy to use, I will present it below.
How it works? It gets time range (from hour to hour) and check if current time is in this range.
It may contain small error, but if you have some skils you can easily fix this.

Code:
TimeRange = {}

function TimeRange:new(time1, time2)
 local obj = {}
 
 obj.timestart = {hours = time1.hours, minutes = time1.minutes}
 obj.timeend = {hours = time2.hours, minutes = time2.minutes}
 self.__index = self
 
 return setmetatable(obj,self)
end

function TimeRange:changeToMinutes(t)
	return t.hours*60 + t.minutes
end

function TimeRange:isBetween()
	local timeinseconds =  self:changeToMinutes(getTibiaTime())
	local timestart = self:changeToMinutes(self.timestart)
	local timeend = self:changeToMinutes(self.timeend)
        local t1 = math.min(timestart, timeend)
	local t2 = math.max(timestart, timeend)
	
	print(t1,t2,timeinseconds)
	if(t1 == timestart) then
		print("t1 tstart")
		return (timeinseconds >= t1 and timeinseconds <= t2)
	elseif (t1 == timeend) then
	    print("t2 tstart")
		return not((timeinseconds > t1 and timeinseconds < t2))
	end

	return false
end

Usage:
Code:
local timeSample =TimeRange:new({hours = 1, minutes = 21},{hours = 1, minutes = 50})
print("Is current time in range? " .. tostring(timeSample:isBetween()))
 
it checks if current tibia time is between some time range like now is 1AM you want to check if this hour is betwen 12PM and 3PM it will return false, beacosue its not between this range.
 
Back
Top