X-Git-Url: http://plrg.eecs.uci.edu/git/?p=smartthings-infrastructure.git;a=blobdiff_plain;f=Methods%2Fschedule.groovy;h=f4fcf24cc318f2eeebd4d666a5612bb836666948;hp=307b221e25c3f2a89cd3f6f3981ec78648d5252d;hb=43db66bdb5ba7a2f07e9cbb04e0c44fddd6510be;hpb=dc01c1740e0befd5f950904dfb6782014e3601f0 diff --git a/Methods/schedule.groovy b/Methods/schedule.groovy index 307b221..f4fcf24 100644 --- a/Methods/schedule.groovy +++ b/Methods/schedule.groovy @@ -1,49 +1,56 @@ ///////////////////////////////////////////////////////////////////// ////schedule(time, nameOfFunction as String) def schedule(String time, String nameOfFunction) { - //def _inputTime = time.split(':') - //Date date = new Date() - //def _currentTime = date.format("HH:mm:ss").split(':') + /*def _inputTime = time.split(':') + Date date = new Date() + def _currentTime = date.format("HH:mm:ss").split(':') - //Convert input time and current time to minutes - //def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60 - //def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2]) - //def delay + Convert input time and current time to minutes + def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60 + def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2]) + def delay - //if (inputTime < currentTime) { - // delay = 24*60*60-inputTime+currentTime - //} else { - // delay = inputTime-currentTime - //} + if (inputTime < currentTime) { + delay = 24*60*60-inputTime+currentTime + } else { + delay = inputTime-currentTime + } timersFuncList.add(nameOfFunction) timersList.add(new SimulatedTimer()) - def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(/*delay*1000*0*/0) { + def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*1000*0) { "$nameOfFunction"() - } + }*/ + "$nameOfFunction"() +} +///////////////////////////////////////////////////////////////////// +////schedule(Date, nameOfFunction as String) +def schedule(Date date, String nameOfFunction) { + "$nameOfFunction"() } ////schedule(time, nameOfFunction as Closure) def schedule(String time, Closure nameOfFunction) { - //def _inputTime = time.split(':') - //Date date = new Date() - //def _currentTime = date.format("HH:mm:ss").split(':') + /*def _inputTime = time.split(':') + Date date = new Date() + def _currentTime = date.format("HH:mm:ss").split(':') - //Convert input time and current time to minutes - //def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60 - //def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2]) - //def delay + Convert input time and current time to minutes + def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60 + def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2]) + def delay - //if (inputTime < currentTime) { - // delay = 24*60*60-inputTime+currentTime - //} else { - // delay = inputTime-currentTime - //} + if (inputTime < currentTime) { + delay = 24*60*60-inputTime+currentTime + } else { + delay = inputTime-currentTime + } if (timersFuncList.contains(nameOfFunction)) { timersList[timersFuncList.indexOf(nameOfFunction)].cancel() - def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(/*delay*0*/0, nameOfFunction0) + def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(0, nameOfFunction) } else { timersFuncList.add(nameOfFunction) timersList.add(new SimulatedTimer()) - def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(/*delay*0*/0, nameOfFunction) - } + def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(0, nameOfFunction) + }*/ + nameOfFunction() }