IDEMPIERE-5794: New param for getBusinessDaysBetween to include/exlud… (#1928)

* IDEMPIERE-5794: New param for getBusinessDaysBetween to include/exlude end date

https://idempiere.atlassian.net/browse/IDEMPIERE-5794

* IDEMPIERE-5794: New param for getBusinessDaysBetween to include/exlude end date - Unit tests

Co-Authored-By: hengsin <152246+hengsin@users.noreply.github.com>

---------

Co-authored-by: hengsin <152246+hengsin@users.noreply.github.com>
This commit is contained in:
Nicolas Micoud 2023-07-10 08:41:39 +02:00 committed by GitHub
parent b7c089fc1d
commit b28735509d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View File

@ -812,9 +812,23 @@ public class TimeUtil
*/
public static int getBusinessDaysBetween(Timestamp startDate, Timestamp endDate, int clientID, String trxName)
{
return getBusinessDaysBetween(startDate, endDate, clientID, MCountry.getDefault().getC_Country_ID(), trxName);
return getBusinessDaysBetween(startDate, endDate, clientID, false, trxName);
}
/**
*
* @param startDate
* @param endDate
* @param clientID
* @param includeEndDate
* @param trxName
* @return number of business days between 2 dates for the country based on current default country
*/
public static int getBusinessDaysBetween(Timestamp startDate, Timestamp endDate, int clientID, boolean includeEndDate, String trxName)
{
return getBusinessDaysBetween(startDate, endDate, clientID, MCountry.getDefault().getC_Country_ID(), includeEndDate, trxName);
}
/**
*
* @param startDate
@ -825,6 +839,21 @@ public class TimeUtil
* @return number of business days between 2 dates for a specified country
*/
public static int getBusinessDaysBetween(Timestamp startDate, Timestamp endDate, int clientID, int countryID, String trxName)
{
return getBusinessDaysBetween(startDate, endDate, clientID, countryID, false, trxName);
}
/**
*
* @param startDate
* @param endDate
* @param clientID
* @param countryID
* @param includeEndDate
* @param trxName
* @return number of business days between 2 dates for a specified country, with ability to include the end date in the count
*/
public static int getBusinessDaysBetween(Timestamp startDate, Timestamp endDate, int clientID, int countryID, boolean includeEndDate, String trxName)
{
int retValue = 0;
@ -856,7 +885,7 @@ public class TimeUtil
calEnd.set(Calendar.SECOND, 0);
calEnd.set(Calendar.MILLISECOND, 0);
while (cal.before(calEnd)) {
while (cal.before(calEnd) || (includeEndDate && cal.equals(calEnd))) {
if (nbd == null || !nbd.contains(new Timestamp(cal.getTimeInMillis()))) {
if (cal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && cal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
retValue++;

View File

@ -265,8 +265,10 @@ public class TimeUtilTest extends AbstractTestCase {
//get business days
to = expected;
assertEquals(2, TimeUtil.getBusinessDaysBetween(from, to, getAD_Client_ID(), getTrxName()));
assertEquals(3, TimeUtil.getBusinessDaysBetween(from, to, getAD_Client_ID(), true, getTrxName()));
nbd.deleteEx(true);
assertEquals(3, TimeUtil.getBusinessDaysBetween(from, to, getAD_Client_ID(), getTrxName()));
assertEquals(4, TimeUtil.getBusinessDaysBetween(from, to, getAD_Client_ID(), true, getTrxName()));
}
}