jomarko commented on code in PR #3795:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3795#discussion_r1862985264
##########
jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/timer/BusinessCalendarImpl.java:
##########
@@ -293,7 +299,9 @@ public Date calculateBusinessTimeAsDate(String
timeExpression) {
c.set(Calendar.HOUR_OF_DAY, startHour);
c.add(Calendar.HOUR_OF_DAY, currentCalHour - endHour);
} else if (currentCalHour < startHour) {
- c.add(Calendar.HOUR_OF_DAY, startHour);
+ c.add(Calendar.HOUR_OF_DAY, startHour - currentCalHour);
Review Comment:
As we change construction of `HOUR_OF_DAY`, maybe it would be worth to add
also `*hour*` tests?
During my brief check, I didn't find such tests. Also, I didn't check if
`tring duration = "2h";` is a correct duration value. I wrote the code below
just in github comment.
If you think, such tests are not needed, feel free to proceed without adding
such tests.
```
@Test
public void testCalculateHoursBeforeStartHour() {
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 = "2h";
String expectedDate = "2024-11-28 16:00:00";
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 testCalculateHoursBeforeEndHour() {
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:58:33.000";
String duration = "2h";
String expectedDate = "2024-11-29 15:58:33";
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);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]