@Test public void calculateGap_DAY() { assertEquals(new Period(1, PeriodUnit.DAY), calculator.calculateGap(2014, 1, 2014, 2)); }
public Period calculateGap(int startYear, int startMonth, int endYear, int endMonth) { int monthDiff = (endYear - startYear) * 12 + (endMonth - startMonth + 1); if (monthDiff <= 2) { return new Period(1, PeriodUnit.DAY); } if (monthDiff <= 12) { return new Period(7, PeriodUnit.DAY); } if (monthDiff <= 60) { return new Period(1, PeriodUnit.MONTH); } if (monthDiff <= 120) { return new Period(6, PeriodUnit.MONTH); } return new Period(1, PeriodUnit.YEAR); }
MonthYearRangeGapCalculator { public Period calculateGap(int startYear, int startMonth, int endYear, int endMonth) { int monthDiff = (endYear - startYear) * 12 + (endMonth - startMonth + 1); if (monthDiff <= 2) { return new Period(1, PeriodUnit.DAY); } if (monthDiff <= 12) { return new Period(7, PeriodUnit.DAY); } if (monthDiff <= 60) { return new Period(1, PeriodUnit.MONTH); } if (monthDiff <= 120) { return new Period(6, PeriodUnit.MONTH); } return new Period(1, PeriodUnit.YEAR); } }
MonthYearRangeGapCalculator { public Period calculateGap(int startYear, int startMonth, int endYear, int endMonth) { int monthDiff = (endYear - startYear) * 12 + (endMonth - startMonth + 1); if (monthDiff <= 2) { return new Period(1, PeriodUnit.DAY); } if (monthDiff <= 12) { return new Period(7, PeriodUnit.DAY); } if (monthDiff <= 60) { return new Period(1, PeriodUnit.MONTH); } if (monthDiff <= 120) { return new Period(6, PeriodUnit.MONTH); } return new Period(1, PeriodUnit.YEAR); }  }
MonthYearRangeGapCalculator { public Period calculateGap(int startYear, int startMonth, int endYear, int endMonth) { int monthDiff = (endYear - startYear) * 12 + (endMonth - startMonth + 1); if (monthDiff <= 2) { return new Period(1, PeriodUnit.DAY); } if (monthDiff <= 12) { return new Period(7, PeriodUnit.DAY); } if (monthDiff <= 60) { return new Period(1, PeriodUnit.MONTH); } if (monthDiff <= 120) { return new Period(6, PeriodUnit.MONTH); } return new Period(1, PeriodUnit.YEAR); }  Period calculateGap(int startYear, int startMonth, int endYear, int endMonth); }
MonthYearRangeGapCalculator { public Period calculateGap(int startYear, int startMonth, int endYear, int endMonth) { int monthDiff = (endYear - startYear) * 12 + (endMonth - startMonth + 1); if (monthDiff <= 2) { return new Period(1, PeriodUnit.DAY); } if (monthDiff <= 12) { return new Period(7, PeriodUnit.DAY); } if (monthDiff <= 60) { return new Period(1, PeriodUnit.MONTH); } if (monthDiff <= 120) { return new Period(6, PeriodUnit.MONTH); } return new Period(1, PeriodUnit.YEAR); }  Period calculateGap(int startYear, int startMonth, int endYear, int endMonth);  }