Use a less restrictive type specifying the minimun period
FEA: ItEr61S08TimeUnitConfigurablePlanning
This commit is contained in:
parent
719ce60fbf
commit
0e8a61715f
5 changed files with 102 additions and 14 deletions
|
|
@ -93,8 +93,8 @@ public class DetailFiveTimeTrackerState extends TimeTrackerStateUsingJodaTime {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Days getMinimumPeriod() {
|
||||
return Days.days(NUMBER_OF_DAYS_MINIMUM);
|
||||
protected Period getMinimumPeriod() {
|
||||
return PeriodType.DAYS.amount(NUMBER_OF_DAYS_MINIMUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -114,8 +114,8 @@ public class DetailFourTimeTrackerState extends TimeTrackerStateUsingJodaTime {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Days getMinimumPeriod() {
|
||||
return Days.days(7 * NUMBER_OF_WEEKS_MINIMUM);
|
||||
protected Period getMinimumPeriod() {
|
||||
return PeriodType.WEEKS.amount(NUMBER_OF_WEEKS_MINIMUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -93,8 +93,8 @@ public class DetailSixTimeTrackerState extends TimeTrackerStateUsingJodaTime {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Days getMinimumPeriod() {
|
||||
return Days.days(NUMBER_OF_DAYS_MINIMUM);
|
||||
protected Period getMinimumPeriod() {
|
||||
return PeriodType.DAYS.amount(NUMBER_OF_DAYS_MINIMUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
package org.zkoss.ganttz.timetracker.zoom;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Days;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.Months;
|
||||
import org.joda.time.ReadablePeriod;
|
||||
|
|
@ -110,8 +109,8 @@ public class DetailThreeTimeTrackerState extends TimeTrackerStateUsingJodaTime {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Days getMinimumPeriod() {
|
||||
return Days.days(NUMBER_OF_MONTHS_MINIMUM * 31);
|
||||
protected Period getMinimumPeriod() {
|
||||
return PeriodType.MONTHS.amount(NUMBER_OF_MONTHS_MINIMUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -28,7 +28,11 @@ import java.util.List;
|
|||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Days;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.Months;
|
||||
import org.joda.time.ReadablePeriod;
|
||||
import org.joda.time.Weeks;
|
||||
import org.joda.time.Years;
|
||||
import org.joda.time.base.BaseSingleFieldPeriod;
|
||||
import org.zkoss.ganttz.util.Interval;
|
||||
|
||||
/**
|
||||
|
|
@ -88,16 +92,101 @@ public abstract class TimeTrackerStateUsingJodaTime extends TimeTrackerState {
|
|||
|
||||
protected abstract LocalDate round(LocalDate date, boolean down);
|
||||
|
||||
protected abstract Days getMinimumPeriod();
|
||||
public enum PeriodType {
|
||||
YEARS {
|
||||
@Override
|
||||
public ReadablePeriod toPeriod(int amount) {
|
||||
return Years.years(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Years differenceBetween(LocalDate start,
|
||||
LocalDate end) {
|
||||
return Years.yearsBetween(start, end);
|
||||
}
|
||||
},
|
||||
MONTHS {
|
||||
@Override
|
||||
public ReadablePeriod toPeriod(int amount) {
|
||||
return Months.months(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Months differenceBetween(LocalDate start,
|
||||
LocalDate end) {
|
||||
return Months.monthsBetween(start, end);
|
||||
}
|
||||
},
|
||||
WEEKS {
|
||||
@Override
|
||||
public ReadablePeriod toPeriod(int amount) {
|
||||
return Weeks.weeks(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Weeks differenceBetween(LocalDate start,
|
||||
LocalDate end) {
|
||||
return Weeks.weeksBetween(start, end);
|
||||
}
|
||||
},
|
||||
DAYS {
|
||||
@Override
|
||||
public ReadablePeriod toPeriod(int amount) {
|
||||
return Days.days(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Days differenceBetween(LocalDate start,
|
||||
LocalDate end) {
|
||||
return Days.daysBetween(start, end);
|
||||
}
|
||||
};
|
||||
|
||||
public abstract ReadablePeriod toPeriod(int amount);
|
||||
|
||||
public abstract BaseSingleFieldPeriod differenceBetween(LocalDate start,
|
||||
LocalDate end);
|
||||
|
||||
public Period amount(int amount) {
|
||||
return new Period(this, amount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class Period {
|
||||
|
||||
private final PeriodType type;
|
||||
|
||||
private final int amount;
|
||||
|
||||
private Period(PeriodType type, int amount) {
|
||||
this.type = type;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
ReadablePeriod toPeriod() {
|
||||
return this.type.toPeriod(amount);
|
||||
}
|
||||
|
||||
BaseSingleFieldPeriod asPeriod(Interval interval) {
|
||||
LocalDate start = LocalDate.fromDateFields(interval.getStart());
|
||||
LocalDate end = LocalDate.fromDateFields(interval.getFinish());
|
||||
return type.differenceBetween(start, end);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Period getMinimumPeriod();
|
||||
|
||||
private Interval calculateIntervalWithMinimum(Interval interval) {
|
||||
ReadablePeriod minimumPeriod = getMinimumPeriod();
|
||||
Days intervalDays = asPeriod(interval);
|
||||
if (intervalDays.compareTo(minimumPeriod) >= 0) {
|
||||
Period minimumPeriod = getMinimumPeriod();
|
||||
BaseSingleFieldPeriod intervalAsPeriod = minimumPeriod
|
||||
.asPeriod(interval);
|
||||
if (intervalAsPeriod
|
||||
.compareTo(minimumPeriod.toPeriod()) >= 0) {
|
||||
return interval;
|
||||
}
|
||||
LocalDate newEnd = new LocalDate(interval.getStart())
|
||||
.plus(minimumPeriod);
|
||||
.plus(minimumPeriod.toPeriod());
|
||||
return new Interval(interval.getStart(), newEnd
|
||||
.toDateTimeAtStartOfDay().toDate());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue