Skip to content

Commit

Permalink
Additional tests to verify correct handling of seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
martinweiler committed Nov 28, 2024
1 parent 4f151f8 commit f045d82
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,24 @@ public void testCalculateMinutesBeforeStartHour() {
assertThat(formatDate("yyyy-MM-dd HH:mm:ss", result)).isEqualTo(expectedDate);
}

@Test
public void testCalculateSecondsBeforeStartHour() {
Properties config = new Properties();
config.setProperty(BusinessCalendarImpl.HOURS_PER_DAY, "4");
config.setProperty(BusinessCalendarImpl.START_HOUR, "14");
config.setProperty(BusinessCalendarImpl.END_HOUR, "18");
String currentDate = "2024-11-28 10:48:33.000";
String duration = "10s";
String expectedDate = "2024-11-28 14:00:10";

SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTimeAndMillis(currentDate).getTime());
BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock);

Date result = businessCal.calculateBusinessTimeAsDate(duration);

assertThat(formatDate("yyyy-MM-dd HH:mm:ss", result)).isEqualTo(expectedDate);
}

@Test
public void testCalculateMinutesBeforeEndHour() {
Properties config = new Properties();
Expand All @@ -404,6 +422,24 @@ public void testCalculateMinutesBeforeEndHour() {
assertThat(formatDate("yyyy-MM-dd HH:mm:ss", result)).isEqualTo(expectedDate);
}

@Test
public void testCalculateSecondsBeforeEndHour() {
Properties config = new Properties();
config.setProperty(BusinessCalendarImpl.HOURS_PER_DAY, "4");
config.setProperty(BusinessCalendarImpl.START_HOUR, "14");
config.setProperty(BusinessCalendarImpl.END_HOUR, "18");
String currentDate = "2024-11-28 17:59:33.000";
String duration = "50s";
String expectedDate = "2024-11-29 14:00:23";

SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTimeAndMillis(currentDate).getTime());
BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock);

Date result = businessCal.calculateBusinessTimeAsDate(duration);

assertThat(formatDate("yyyy-MM-dd HH:mm:ss", result)).isEqualTo(expectedDate);
}

private Date parseToDate(String dateString) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

Expand Down

0 comments on commit f045d82

Please sign in to comment.