
net.yapbam.date.helpers.DeferredValueDateComputer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yapbam-commons Show documentation
Show all versions of yapbam-commons Show documentation
Commons Yapbam classes used by desktop and Android versions.
package net.yapbam.date.helpers;
import java.util.Date;
import java.util.GregorianCalendar;
/** This class allows to compute value date for a deferred operation */
public class DeferredValueDateComputer extends DateStepper {
private int stopDay;
private int debtDay;
public DeferredValueDateComputer(int stopDay, int debtDay) {
super();
this.stopDay = stopDay;
this.debtDay = debtDay;
}
public int getStopDay() {
return stopDay;
}
public int getDebtDay() {
return debtDay;
}
@Override
public Date getNextStep(Date date) {
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(date);
int day = gc.get(GregorianCalendar.DATE);
int month = gc.get(GregorianCalendar.MONTH);
int year = gc.get(GregorianCalendar.YEAR);
if (day>this.stopDay) {
month++;
if (month>gc.getActualMaximum(GregorianCalendar.MONTH)) {
year++;
month = 0;
}
}
if (this.stopDay>this.debtDay){
month++;
if (month>gc.getActualMaximum(GregorianCalendar.MONTH)) {
year++;
month = 0;
}
}
gc.set(year, month, 1);
gc.add(GregorianCalendar.MONTH, 1);
gc.add(GregorianCalendar.DAY_OF_MONTH, -1);
if (debtDay
© 2015 - 2025 Weber Informatics LLC | Privacy Policy