ServiceSettings { static long getNextNextStartTimeFor(long start, long end) { DateTime now = DateTime.now(); Interval interval = SyncthingUtils.getIntervalForRange(now, start, end); if (interval.isAfter(now)) { return interval.getStartMillis(); } else { return interval.getStart().plusDays(1).getMillis(); } } @Inject  ServiceSettings(
            @ForApplication Context appContext,
            ConnectivityManager cm,
            WifiManager wm,
            @Named("settingsAuthority") String authority,
            ReceiverHelper receiverHelper
    ); void release(); void setCached(boolean cached); boolean isDisabled(); boolean isEnabled(); void setEnabled(boolean enabled); boolean isInitialised(); void setInitialized(boolean initialized); String runWhen(); void setRunWhen(String runWhen); boolean onlyWhenCharging(); void setOnlyWhenCharging(boolean onlyWhenCharging); String getScheduledStartTime(); void setScheduledStartTime(String time); String getScheduledEndTime(); void setScheduledEndTime(String time); boolean onlyOnWifi(); void setOnlyOnWifi(boolean onlyOnWifi); Set<String> allowedWifiNetworks(); void setAllowedWifiNetworks(Set<String> networks); Uri getInitializedUri(); static final String ENABLED; static final String INITIALISED; static final String RUN_WHEN; static final String ALWAYS; static final String SCHEDULED; static final String RANGE_START; static final String RANGE_END; static final String ONLY_WIFI; static final String WIFI_NETWORKS; static final String ONLY_CHARGING; }
@Test public void testGetNextStartTimeFor() { long now = DateTime.parse("2015-03-21T14:12:00").getMillis(); DateTimeUtils.setCurrentMillisFixed(now); long start = parseTime("15:12"); long end = parseTime("16:12"); assertThat(getNextNextStartTimeFor(start, end)).isEqualTo(DateTime.parse("2015-03-21T15:12:00").getMillis()); start = parseTime("13:12"); end = parseTime("16:12"); assertThat(getNextNextStartTimeFor(start, end)).isEqualTo(DateTime.parse("2015-03-22T13:12:00").getMillis()); start = parseTime("10:12"); end = parseTime("13:12"); assertThat(getNextNextStartTimeFor(start, end)).isEqualTo(DateTime.parse("2015-03-22T10:12:00").getMillis()); start = parseTime("13:12"); end = parseTime("12:12"); assertThat(getNextNextStartTimeFor(start, end)).isEqualTo(DateTime.parse("2015-03-22T13:12:00").getMillis()); start = parseTime("15:12"); end = parseTime("10:12"); assertThat(getNextNextStartTimeFor(start, end)).isEqualTo(DateTime.parse("2015-03-21T15:12:00").getMillis()); }