kz.greetgo.scheduling.trigger.atoms.TriggerPeriodInDayRepeat Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of greetgo.scheduling Show documentation
Show all versions of greetgo.scheduling Show documentation
Scheduler using in greetgo!
package kz.greetgo.scheduling.trigger.atoms;
import kz.greetgo.scheduling.trigger.inner_logic.Trigger;
import static kz.greetgo.scheduling.util.TimeUtil.millisFromDayBegin;
public class TriggerPeriodInDayRepeat implements Trigger {
private final TriggerPeriodInDay period;
private final long delayMillis;
public TriggerPeriodInDayRepeat(TriggerPeriodInDay period, long delayMillis) {
this.period = period;
this.delayMillis = delayMillis;
}
@Override
public boolean isHit(long schedulerStartedAtMillis, long timeMillisFrom, long timeMillisTo) {
boolean periodHit = period.isHit(schedulerStartedAtMillis, timeMillisFrom, timeMillisTo);
if (!periodHit) {
return false;
}
long delta = timeMillisTo - timeMillisFrom;
long millisFrom = millisFromDayBegin(timeMillisFrom);
long millisTo = millisFrom + delta;
long fromTimes = millisFrom / delayMillis;
long toTimes = millisTo / delayMillis;
return fromTimes != toTimes;
}
@Override
public boolean isDotty() {
return true;
}
@Override
public String toString() {
return "PeriodInDayRepeat{" + period.toString() + " repeat " + delayMillis + "}";
}
}