Fixing bug in Mobile Presence class
[smartthings-infrastructure.git] / Methods / schedule.groovy
1 /////////////////////////////////////////////////////////////////////
2 ////schedule(time, nameOfFunction as String)
3 def schedule(String time, String nameOfFunction) {
4         /*def _inputTime = time.split(':')
5         Date date = new Date()  
6         def _currentTime = date.format("HH:mm:ss").split(':')
7
8         Convert input time and current time to minutes
9         def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
10         def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
11         def delay
12
13         if (inputTime < currentTime) {
14                 delay = 24*60*60-inputTime+currentTime
15         } else {
16                 delay = inputTime-currentTime
17         }
18         timersFuncList.add(nameOfFunction)
19         timersList.add(new SimulatedTimer())
20         def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*1000*0) {
21                 "$nameOfFunction"()
22         }*/
23         "$nameOfFunction"()
24 }
25 /////////////////////////////////////////////////////////////////////
26 ////schedule(Date, nameOfFunction as String)
27 def schedule(Date date, String nameOfFunction) {
28         "$nameOfFunction"()
29 }
30 ////schedule(time, nameOfFunction as Closure)
31 def schedule(String time, Closure nameOfFunction) {
32         /*def _inputTime = time.split(':')
33         Date date = new Date()  
34         def _currentTime = date.format("HH:mm:ss").split(':')
35
36         Convert input time and current time to minutes
37         def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
38         def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
39         def delay
40
41         if (inputTime < currentTime) {
42                 delay = 24*60*60-inputTime+currentTime
43         } else {
44                 delay = inputTime-currentTime
45         }
46
47         if (timersFuncList.contains(nameOfFunction)) {
48                 timersList[timersFuncList.indexOf(nameOfFunction)].cancel()
49                 def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(0, nameOfFunction)
50         } else {
51                 timersFuncList.add(nameOfFunction)
52                 timersList.add(new SimulatedTimer())
53                 def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(0, nameOfFunction)
54         }*/
55         nameOfFunction()
56 }