Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schedule the next occurrence with respect to restrictions #42

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions smartapps/ady624/webcore-piston.src/webcore-piston.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1935,22 +1935,17 @@ private scheduleTimeCondition(rtData, condition) {
def v2 = trigger ? v1 : ((comparison.p > 1) ? (evaluateExpression(rtData, evaluateOperand(rtData, null, condition.ro2, null, false, true), 'datetime').v + (tv2 ? evaluateExpression(rtData, [t: 'duration', v: tv2.v, vt: tv2.vt]).v : 0)) : (condition.lo.v == 'time' ? getMidnightTime(rtData) : v1))
def n = now() + 2000
if (condition.lo.v == 'time') {
//v1 = (v1 % 86400000) + getMidnightTime()
//v2 = (v2 % 86400000) + getMidnightTime()
while (v1 < n) v1 += 86400000
while (v2 < n) v2 += 86400000
/* int cnt = 100
error "checking restrictions for $condition.lo", rtData
while (cnt) {
//repeat until we find a day that's matching the restrictions
n = v1 < v2 ? v1 : v2
if (checkTimeRestrictions(rtData, condition.lo, n, 5, 1) == 0) break
long n2 = localToUtcTime(utcToLocalTime(n) + 86400000)
error "adding a day, $n >>> $n2", rtData
v1 = (v1 == n) ? n2 : v1
v2 = (v2 == n) ? n2 : v2
cnt = cnt - 1
}*/
int cnt = 366
while (cnt) {
//repeat until we find a day that's matching the restrictions
n = v1 < v2 ? v1 : v2
if (checkTimeRestrictions(rtData, condition.lo, n, 5, 1) == 0) break
v1 = localToUtcTime(utcToLocalTime(v1) + 86400000)
v2 = localToUtcTime(utcToLocalTime(v2) + 86400000)
cnt = cnt - 1
}
}
//figure out the next time
v1 = (v1 < n) ? v2 : v1
Expand Down