TriggerTimeRange extends Trigger { @Override public boolean shouldRun() { int currentMinSinceMidnight = getMinSinceMidnight(DateUtil.now()); if (lastRun > DateUtil.now() - T.mins(5).msecs()) return false; boolean doRun = false; if (start < end && start < currentMinSinceMidnight && currentMinSinceMidnight < end) doRun = true; else if (start > end && (start < currentMinSinceMidnight || currentMinSinceMidnight < end)) doRun = true; if (doRun) { if (L.isEnabled(L.AUTOMATION)) log.debug("Ready for execution: " + friendlyDescription()); return true; } return false; } TriggerTimeRange(); private  TriggerTimeRange(TriggerTimeRange triggerTimeRange); @Override boolean shouldRun(); @Override String toJSON(); @Override int friendlyName(); @Override String friendlyDescription(); @Override Optional<Integer> icon(); @Override Trigger duplicate(); int getMinSinceMidnight(long time); @Override void generateDialog(LinearLayout root, FragmentManager fragmentManager);  }
@Test public void shouldRunTest() { TriggerTimeRange t; now = now + timeZoneOffset; t = new TriggerTimeRange().period(now + 1 - timeZoneOffset, now + 30 - timeZoneOffset); Assert.assertEquals(false, t.shouldRun()); t = new TriggerTimeRange().period(now - 30 - timeZoneOffset, now + 30 - timeZoneOffset); Assert.assertEquals(true, t.shouldRun()); t = new TriggerTimeRange().period(1, 1440); Assert.assertEquals(true, t.shouldRun()); t = new TriggerTimeRange().lastRun((long) (now - 1)*60000); Assert.assertFalse(t.shouldRun()); }