该应用程序的主要目的是为医生安排个人预约。 因此,一旦安排了用户的预约,例如5月8日下午4:30,用户应在一小时前收到“提醒警报”,即@ 3:30 PM。
对于如何完成这项工作,我绝对不以为然。 我可以获取用户的日期时间值,并使用 函数 在该日期时间的60分钟之前调用的逻辑。该功能包含我的“警报消息”。 但是怎么做呢?任何人都可以用线索指导我吗?
如果需要任何其他输入,请告诉我......
提前致谢。
答案 0 :(得分:1)
我会采取这样的方法:
<强> 1 强>
将每个约会的详细信息存储为包含JSON或Lua表格数据的.txt文件,如下所示:
{
date = "14:30 01/07/2013";
dateBooked = "09:30 23/06/2013";
venue = "31 Dentist Street";
appointmentType = "Routine Teeth Cleaning";
}
<强> 2 强>
你可以有一个像这样的计时器类
Timer = {}
Timer_mt = { __index = Timer; __add = function(a,b) a:tickBy(b) end ; }
function Timer:new(delayTime,callBack)
local timer = {callBack=callBack}
timer.initTime = os.date() --MM/DD/YY HH:MM:SS
--delayTime = HH:MM:SS
_,_,hour,minute,second = string.find(delayTime,"(%d%d):(%d%d):(%d%d)")
timer.delay = {hour=hour,minute=minute,second=second}
--time the timer started
_,_,hour,minute,second = string.find(timer.initTime,"(%d%d):(%d%d):(%d%d)")
timer.startTime = {hour=hour,minute=minute,second=second}
--time the timer started
timer.initTime = os.date() --MM/DD/YY HH:MM:SS
print(timer.initTime)
_,_,hour,minute,second = string.find(timer.initTime,"(%d%d):(%d%d):(%d%d)")
timer.currentTime = {hour=hour,minute=minute,second=second}
return setmetatable(timer,Timer_mt)
end
function Timer:tick() --returns true if time expired
currTime = os.date() --MM/DD/YY HH:MM:SS
_,_,chour,cminute,csecond = string.find(currTime,"(%d%d):(%d%d):(%d%d)")
if chour - self.startTime.hour >= tonumber(self.delay.hour) and cminute - self.startTime.minute >= tonumber(self.delay.minute) and csecond - self.startTime.second > tonumber(self.delay.second) then
self:callBack()
self.startTime.hour,self.startTime.minute, self.startTime.second = chour,cminute,csecond
--return true
end
--return false
end
t = Timer:new("00:00:02",function () print("DONE") end)
print(t.currentTime.hour,t.currentTime.minute,t.currentTime.second)
while t:tick() or true do
io.read()
end
(我刚刚做了这个,所以我建议你测试一下,但它似乎适合我)。
第3 强>
在启动时,或者在添加新约会时创建一个新计时器,然后在主执行期间的某个时刻tick()
每个计时器,你甚至可以拥有一个计时器,这是你{{1}并且它是回调tick()
其他...无论如何设置每个计时器的回调以显示警报