ItEr43S10SoporteImpresionMultiplesPaxinasItEr42S15: Pulling up calculateIntervalWithMinimum. Using getMinimumPeriod method to compute it.
This commit is contained in:
parent
31f7eae8df
commit
80a7d4fa14
4 changed files with 29 additions and 76 deletions
|
|
@ -28,7 +28,6 @@ import org.joda.time.DateTime;
|
|||
import org.joda.time.Days;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.ReadablePeriod;
|
||||
import org.joda.time.Weeks;
|
||||
import org.zkoss.ganttz.util.Interval;
|
||||
|
||||
/**
|
||||
|
|
@ -121,26 +120,8 @@ public class DetailFiveTimeTrackerState extends TimeTrackerStateUsingJodaTime {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Interval calculateIntervalWithMinimum(Interval candidateInterval) {
|
||||
Interval resultInterval;
|
||||
LocalDate startDate = LocalDate.fromDateFields(candidateInterval.getStart());
|
||||
LocalDate endDate = LocalDate.fromDateFields(candidateInterval.getFinish());
|
||||
Days numberOfDays = Days.daysBetween(startDate.toDateTimeAtCurrentTime(),
|
||||
endDate.toDateTimeAtCurrentTime());
|
||||
|
||||
if (numberOfDays.getDays() < this.NUMBER_OF_DAYS_MINIMUM) {
|
||||
LocalDate endIntervalDate = LocalDate.fromDateFields(candidateInterval.
|
||||
getStart()).
|
||||
toDateMidnight().
|
||||
plusWeeks(this.NUMBER_OF_DAYS_MINIMUM).toLocalDate();
|
||||
LocalDate roundedEndIntervalDate = roundToNextYear(endIntervalDate);
|
||||
resultInterval = new Interval(candidateInterval.getStart(),
|
||||
roundedEndIntervalDate.toDateMidnight().toDate());
|
||||
} else {
|
||||
resultInterval = candidateInterval;
|
||||
}
|
||||
|
||||
return resultInterval;
|
||||
protected Days getMinimumPeriod() {
|
||||
return Days.days(NUMBER_OF_DAYS_MINIMUM);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -20,13 +20,12 @@
|
|||
|
||||
package org.zkoss.ganttz.timetracker.zoom;
|
||||
|
||||
import org.jfree.data.time.Month;
|
||||
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.zkoss.ganttz.util.Interval;
|
||||
|
||||
/**
|
||||
* Zoom level for months and years and weeks in the second level
|
||||
|
|
@ -95,27 +94,8 @@ public class DetailFourTimeTrackerState extends TimeTrackerStateUsingJodaTime {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Interval calculateIntervalWithMinimum(Interval candidateInterval) {
|
||||
Interval resultInterval;
|
||||
LocalDate startDate = LocalDate.fromDateFields(candidateInterval.getStart());
|
||||
LocalDate endDate = LocalDate.fromDateFields(candidateInterval.getFinish());
|
||||
Weeks numberOfWeeks = Weeks.weeksBetween(startDate.toDateTimeAtCurrentTime(),
|
||||
endDate.toDateTimeAtCurrentTime());
|
||||
|
||||
if (numberOfWeeks.getWeeks() < this.NUMBER_OF_WEEKS_MINIMUM) {
|
||||
LocalDate endIntervalDate = LocalDate.fromDateFields(candidateInterval.
|
||||
getStart()).
|
||||
toDateMidnight().
|
||||
plusWeeks(this.NUMBER_OF_WEEKS_MINIMUM).toLocalDate();
|
||||
LocalDate roundedEndIntervalDate = roundToNextYear(endIntervalDate);
|
||||
|
||||
resultInterval = new Interval(candidateInterval.getStart(),
|
||||
roundedEndIntervalDate.toDateMidnight().toDate());
|
||||
} else {
|
||||
resultInterval = candidateInterval;
|
||||
}
|
||||
|
||||
return resultInterval;
|
||||
protected Days getMinimumPeriod() {
|
||||
return Days.days(7 * NUMBER_OF_WEEKS_MINIMUM);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,13 +20,11 @@
|
|||
|
||||
package org.zkoss.ganttz.timetracker.zoom;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
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.zkoss.ganttz.util.Interval;
|
||||
import org.zkoss.util.Locales;
|
||||
|
||||
/**
|
||||
|
|
@ -111,26 +109,8 @@ public class DetailThreeTimeTrackerState extends TimeTrackerStateUsingJodaTime {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Interval calculateIntervalWithMinimum(Interval candidateInterval) {
|
||||
Interval resultInterval;
|
||||
LocalDate startDate = LocalDate.fromDateFields(candidateInterval.getStart());
|
||||
LocalDate endDate = LocalDate.fromDateFields(candidateInterval.getFinish());
|
||||
Months numberOfMonths =
|
||||
Months.monthsBetween(startDate.toDateTimeAtCurrentTime(),
|
||||
endDate.toDateTimeAtCurrentTime());
|
||||
|
||||
if (numberOfMonths.getMonths() < this.NUMBER_OF_MONTHS_MINIMUM) {
|
||||
LocalDate endIntervalDate = LocalDate.fromDateFields(candidateInterval.
|
||||
getStart()).
|
||||
toDateMidnight().
|
||||
plusMonths(this.NUMBER_OF_MONTHS_MINIMUM).toLocalDate();
|
||||
LocalDate roundedEndIntervalDate = roundToNextYear(endIntervalDate);
|
||||
resultInterval = new Interval(candidateInterval.getStart(),
|
||||
roundedEndIntervalDate.toDateMidnight().toDate());
|
||||
} else {
|
||||
resultInterval = candidateInterval;
|
||||
}
|
||||
|
||||
return resultInterval;
|
||||
protected Days getMinimumPeriod() {
|
||||
return Days.days(NUMBER_OF_MONTHS_MINIMUM * 31);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -25,8 +25,8 @@ import java.util.Collection;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.jfree.data.time.Month;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Days;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.ReadablePeriod;
|
||||
import org.zkoss.ganttz.util.Interval;
|
||||
|
|
@ -88,7 +88,25 @@ public abstract class TimeTrackerStateUsingJodaTime extends TimeTrackerState {
|
|||
|
||||
protected abstract LocalDate round(LocalDate date, boolean down);
|
||||
|
||||
protected abstract Interval calculateIntervalWithMinimum(Interval candidateInterval);
|
||||
protected abstract Days getMinimumPeriod();
|
||||
|
||||
private Interval calculateIntervalWithMinimum(Interval interval) {
|
||||
ReadablePeriod minimumPeriod = getMinimumPeriod();
|
||||
Days intervalDays = asPeriod(interval);
|
||||
if (intervalDays.compareTo(minimumPeriod) >= 0) {
|
||||
return interval;
|
||||
}
|
||||
LocalDate newEnd = new LocalDate(interval.getStart())
|
||||
.plus(minimumPeriod);
|
||||
return new Interval(interval.getStart(), newEnd
|
||||
.toDateTimeAtStartOfDay().toDate());
|
||||
}
|
||||
|
||||
private Days asPeriod(Interval interval) {
|
||||
DateTime start = new DateTime(interval.getStart());
|
||||
DateTime finish = new DateTime(interval.getFinish());
|
||||
return Days.daysBetween(start, finish);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Interval getRealIntervalFor(Interval testInterval) {
|
||||
|
|
@ -103,10 +121,4 @@ public abstract class TimeTrackerStateUsingJodaTime extends TimeTrackerState {
|
|||
.toDateTimeAtStartOfDay().toDate());
|
||||
return result;
|
||||
}
|
||||
|
||||
protected LocalDate roundToNextYear(LocalDate date) {
|
||||
LocalDate dateNextYear = date.withYear(date.getYear()+1).
|
||||
withMonthOfYear(Month.JANUARY).withDayOfMonth(1);
|
||||
return dateNextYear;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue