Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix_3818] Wrong calculation in test rollCalendarAfterHolidays if day is near to end-of-year #3819

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading