Skip to content

Commit

Permalink
[Fix_3818] Wrong calculation in test rollCalendarAfterHolidays if day is
Browse files Browse the repository at this point in the history
near to end-of-year
  • Loading branch information
gmunozfe committed Dec 30, 2024
1 parent 3ecc10d commit 1ef03a8
Showing 1 changed file with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,41 @@ void rollCalendarToNightlyWorkingHour() {
}

@Test
void rollCalendarAfterHolidays() {
Instant now = Instant.now();
int holidayLeft = 4;
Instant startHolidayInstant = now.minus(2, DAYS);
Instant endHolidayInstant = now.plus(holidayLeft, DAYS);
Date startHoliday = Date.from(startHolidayInstant);
Date endHoliday = Date.from(endHolidayInstant);
List<BusinessCalendarImpl.TimePeriod> holidays = Collections.singletonList(new BusinessCalendarImpl.TimePeriod(startHoliday, endHoliday));
void rollCalendarAfterHolidaysWithoutYearRollover() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_YEAR, 360);
calendar.set(Calendar.YEAR, 2025);
Instant currentInstant = calendar.toInstant();

Instant startHolidayInstant = currentInstant.minus(2, DAYS);
Instant endHolidayInstant = currentInstant.plus(4, DAYS);
List<BusinessCalendarImpl.TimePeriod> holidays = Collections.singletonList(
new BusinessCalendarImpl.TimePeriod(Date.from(startHolidayInstant), Date.from(endHolidayInstant)));
List<Integer> weekendDays = Collections.emptyList();

BusinessCalendarImpl.rollCalendarAfterHolidays(calendar, holidays, weekendDays, false);

int expectedDayOfYear = 360 + 4 + 1; //last day of the year, as it is not leap year
assertThat(calendar.get(Calendar.DAY_OF_YEAR)).isEqualTo(expectedDayOfYear);
}

@Test
void rollCalendarAfterHolidaysWithYearRollover() {
Calendar calendar = Calendar.getInstance();
int currentDayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
calendar.set(Calendar.DAY_OF_YEAR, 361);
calendar.set(Calendar.YEAR, 2025);
Instant currentInstant = calendar.toInstant();

Instant startHolidayInstant = currentInstant.minus(2, DAYS);
Instant endHolidayInstant = currentInstant.plus(4, DAYS);
List<BusinessCalendarImpl.TimePeriod> holidays = Collections.singletonList(
new BusinessCalendarImpl.TimePeriod(Date.from(startHolidayInstant), Date.from(endHolidayInstant)));
List<Integer> weekendDays = Collections.emptyList();

BusinessCalendarImpl.rollCalendarAfterHolidays(calendar, holidays, weekendDays, false);
int expected = currentDayOfYear + holidayLeft + 1;
assertThat(calendar.get(Calendar.DAY_OF_YEAR)).isEqualTo(expected);

int expectedDayOfYear = 1; //since 2025 is not leap year
assertThat(calendar.get(Calendar.DAY_OF_YEAR)).isEqualTo(expectedDayOfYear);
}

@Test
Expand Down

0 comments on commit 1ef03a8

Please sign in to comment.