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:
parent
b7c089fc1d
commit
b28735509d
|
@ -812,7 +812,21 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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++;
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue