diff --git a/org.adempiere.base/src/org/compiere/util/TimeUtil.java b/org.adempiere.base/src/org/compiere/util/TimeUtil.java index 94a300013b..6ef6789b36 100644 --- a/org.adempiere.base/src/org/compiere/util/TimeUtil.java +++ b/org.adempiere.base/src/org/compiere/util/TimeUtil.java @@ -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++; diff --git a/org.idempiere.test/src/org/idempiere/test/base/TimeUtilTest.java b/org.idempiere.test/src/org/idempiere/test/base/TimeUtilTest.java index 0aa28a09eb..3a3dda0e14 100644 --- a/org.idempiere.test/src/org/idempiere/test/base/TimeUtilTest.java +++ b/org.idempiere.test/src/org/idempiere/test/base/TimeUtilTest.java @@ -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())); } }