diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTime.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTime.kt index 08343a3c94..5f6db0494d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTime.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTime.kt @@ -37,9 +37,8 @@ class TriggerRecurringTime(injector: HasAndroidInjector) : Trigger(injector) { override fun shouldRun(): Boolean { val currentMinSinceMidnight = getMinSinceMidnight(DateUtil.now()) val scheduledDayOfWeek = Calendar.getInstance()[Calendar.DAY_OF_WEEK] - val scheduled = getMinSinceMidnight(time.value.toLong()) if (days.isSet(Objects.requireNonNull(InputWeekDay.DayOfWeek.fromCalendarInt(scheduledDayOfWeek)))) { - if (currentMinSinceMidnight >= scheduled && currentMinSinceMidnight - scheduled < 5) { + if (currentMinSinceMidnight >= time.value && currentMinSinceMidnight - time.value < 5) { aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription()) return true } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTimeTest.kt index 566a0b4c7b..ca20e1cee3 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTimeTest.kt @@ -14,7 +14,7 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(DateUtil::class) class TriggerRecurringTimeTest : TriggerTestBase() { - var now = 1514766900000L + var now = 1514766900000L // 95 min from midnight @Before fun mock() { PowerMockito.mockStatic(DateUtil::class.java) @@ -26,20 +26,14 @@ class TriggerRecurringTimeTest : TriggerTestBase() { @Test fun shouldRunTest() { - // limit by validTo - var t: TriggerRecurringTime = TriggerRecurringTime(injector).time(94) + var t: TriggerRecurringTime = TriggerRecurringTime(injector).time(89) t.days.setAll(true) Assert.assertFalse(t.shouldRun()) // scheduled 1 min before -// t = new TriggerRecurringTime().hour(1).minute(34); -// t.setAll(true); -// Assert.assertTrue(t.shouldRun()); - - // already run t = TriggerRecurringTime(injector).time(94) t.days.setAll(true) - Assert.assertFalse(t.shouldRun()) + Assert.assertTrue(t.shouldRun()) } private var timeJson = "{\"data\":{\"WEDNESDAY\":false,\"MONDAY\":false,\"THURSDAY\":false,\"SUNDAY\":false,\"TUESDAY\":false,\"FRIDAY\":false,\"SATURDAY\":false,\"time\":4444},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerRecurringTime\"}"