fix TriggerRecurringTime #2

This commit is contained in:
Milos Kozak 2020-05-24 21:10:44 +02:00
parent 1cb648c09a
commit 0a33f4c0db
3 changed files with 8 additions and 7 deletions

View file

@ -34,8 +34,8 @@ class TriggerRecurringTime(injector: HasAndroidInjector) : Trigger(injector) {
return this
}
override fun shouldRun(): Boolean {
val currentMinSinceMidnight = getMinSinceMidnight(DateUtil.now())
override fun shouldRun() : Boolean {
val currentMinSinceMidnight = getMinSinceMidnight(dateUtil._now())
val scheduledDayOfWeek = Calendar.getInstance()[Calendar.DAY_OF_WEEK]
if (days.isSet(Objects.requireNonNull(InputWeekDay.DayOfWeek.fromCalendarInt(scheduledDayOfWeek)))) {
if (currentMinSinceMidnight >= time.value && currentMinSinceMidnight - time.value < 5) {

View file

@ -17,11 +17,7 @@ class TriggerRecurringTimeTest : TriggerTestBase() {
var now = 1514766900000L // 95 min from midnight
@Before fun mock() {
PowerMockito.mockStatic(DateUtil::class.java)
PowerMockito.`when`(DateUtil.now()).thenReturn(now)
// val calendar = GregorianCalendar()
// calendar.timeInMillis = now
// PowerMockito.`when`(DateUtil.gregorianCalendar()).thenReturn(calendar)
PowerMockito.`when`(dateUtil._now()).thenReturn(now)
}
@Test fun shouldRunTest() {

View file

@ -261,6 +261,10 @@ public class DateUtil {
return timeFrameString(timestamp - System.currentTimeMillis(), resourceHelper);
}
public long _now() {
return System.currentTimeMillis();
}
public static long now() {
return System.currentTimeMillis();
}
@ -358,6 +362,7 @@ public class DateUtil {
// singletons to avoid repeated allocation
private static DecimalFormatSymbols dfs;
private static DecimalFormat df;
public static String qs(double x, int digits) {
if (digits == -1) {