forked from jens/Automation
Date time repetition
This commit is contained in:
parent
3dd84220a3
commit
e272338cc6
@ -585,7 +585,45 @@ public class Miscellaneous extends Service
|
||||
|
||||
Miscellaneous.logEvent("i", "TimeCompare", "Default return code. Shouldn't be here.", 5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int compareTimes(Calendar calOne, Calendar calTwo)
|
||||
{
|
||||
if(calOne.get(Calendar.HOUR_OF_DAY) == calTwo.get(Calendar.HOUR_OF_DAY) && calOne.get(Calendar.MINUTE) == calTwo.get((Calendar.MINUTE)))
|
||||
{
|
||||
// Miscellaneous.logEvent("i", "TimeCompare", "Times are equal.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(calOne.get(Calendar.HOUR_OF_DAY) > calTwo.get(Calendar.HOUR_OF_DAY))
|
||||
{
|
||||
// Miscellaneous.logEvent("i", "TimeCompare", "Time1 is bigger/later by hours.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(calOne.get(Calendar.HOUR_OF_DAY) < calTwo.get(Calendar.HOUR_OF_DAY))
|
||||
{
|
||||
// Miscellaneous.logEvent("i", "TimeCompare", "Time2 is bigger/later by hours.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(calOne.get(Calendar.HOUR_OF_DAY) == calTwo.get(Calendar.HOUR_OF_DAY))
|
||||
{
|
||||
if(calOne.get(Calendar.MINUTE) < calTwo.get(Calendar.MINUTE))
|
||||
{
|
||||
// Miscellaneous.logEvent("i", "TimeCompare", "Hours are equal. Time2 is bigger/later by minutes.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(calOne.get(Calendar.MINUTE) > calTwo.get(Calendar.MINUTE))
|
||||
{
|
||||
// Miscellaneous.logEvent("i", "TimeCompare", "Hours are equal. Time1 is bigger/later by minutes.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Miscellaneous.logEvent("i", "TimeCompare", "Default return code. Shouldn't be here.", 5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static String convertStreamToString(InputStream is)
|
||||
|
@ -404,8 +404,8 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
public static Calendar getNextRepeatedExecution(Trigger trigger)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "DateTimeListener", "Checking for next repetition execution after " + Miscellaneous.formatDate(Calendar.getInstance().getTime()), 5);
|
||||
Calendar now = Calendar.getInstance();
|
||||
Miscellaneous.logEvent("i", "DateTimeListener", "Checking for next repetition execution after " + Miscellaneous.formatDate(now.getTime()), 5);
|
||||
Calendar calculationStart, calSchedule = null;
|
||||
TimeFrame tf = new TimeFrame(trigger.getTriggerParameter2());
|
||||
|
||||
@ -465,7 +465,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
{
|
||||
if (!trigger.getTriggerParameter())
|
||||
{
|
||||
if (trigger.getParentRule().getLastExecution() != null)
|
||||
if (trigger.getParentRule().getLastExecution() != null && tf.getDayList().contains(now.get(Calendar.DAY_OF_WEEK)))
|
||||
{
|
||||
calculationStart = (Calendar) trigger.getParentRule().getLastExecution().clone();
|
||||
}
|
||||
@ -491,11 +491,15 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
calculationStart.set(Calendar.MILLISECOND, 0);
|
||||
calSchedule = (Calendar) calculationStart.clone();
|
||||
calSchedule.add(Calendar.SECOND, (int) (tf.getRepetition()));
|
||||
|
||||
if()
|
||||
}
|
||||
}
|
||||
|
||||
if(!areWeInTimeFrame(trigger, new Date()))
|
||||
{
|
||||
if (Miscellaneous.compareTimes(calSchedule, now) > 0)
|
||||
calSchedule.add(Calendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
|
||||
int dayDelta = getDayDelta(now, getNextDayIntForExecution(trigger));
|
||||
calSchedule.add(Calendar.DAY_OF_WEEK, dayDelta);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user