ASF Bugzilla – Attachment 34505 Details for
Bug 60452
[PATCH] WorkdayCalculator calculateWorkdays does return wrong value for same day input
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for WorkdayCalculator
Workday_Calculator_SameDay_fix.patch (text/plain), 3.78 KB, created by
Fabio
on 2016-12-07 17:06:23 UTC
(
hide
)
Description:
Patch for WorkdayCalculator
Filename:
MIME Type:
Creator:
Fabio
Created:
2016-12-07 17:06:23 UTC
Size:
3.78 KB
patch
obsolete
>Index: src/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java (revision 74ab8da0fda0cb2814dbc29a535a5b035469ba36) >+++ src/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java (revision ) >@@ -38,7 +38,7 @@ > > /** > * Calculate how many workdays are there between a start and an end date, as excel representations, considering a range of holidays. >- * >+ * > * @param start start date. > * @param end end date. > * @param holidays an array of holidays. >@@ -53,7 +53,7 @@ > > /** > * Calculate the workday past x workdays from a starting date, considering a range of holidays. >- * >+ * > * @param start start date. > * @param workdays number of workdays to be past from starting date. > * @param holidays an array of holidays. >@@ -76,10 +76,10 @@ > } > return endDate.getTime(); > } >- >+ > /** > * Calculates how many days of week past between a start and an end date. >- * >+ * > * @param start start date. > * @param end end date. > * @param dayOfWeek a day of week as represented by {@link Calendar} constants. >@@ -96,12 +96,12 @@ > pastDaysOfWeek++; > } > } >- return start < end ? pastDaysOfWeek : -pastDaysOfWeek; >+ return start <= end ? pastDaysOfWeek : -pastDaysOfWeek; > } > > /** > * Calculates how many holidays in a list are workdays, considering an interval of dates. >- * >+ * > * @param start start date. > * @param end end date. > * @param holidays an array of holidays. >@@ -118,7 +118,7 @@ > } > } > } >- return start < end ? nonWeekendHolidays : -nonWeekendHolidays; >+ return start <= end ? nonWeekendHolidays : -nonWeekendHolidays; > } > > /** >Index: src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java (revision 74ab8da0fda0cb2814dbc29a535a5b035469ba36) >+++ src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java (revision ) >@@ -67,6 +67,24 @@ > assertEquals(4, WorkdayCalculator.instance.calculateWorkdays(A_FRIDAY, A_WEDNESDAY, new double[]{ A_SATURDAY, A_SUNDAY })); > } > >+ @Test >+ public void testCalculateWorkdaysOnSameDayShouldReturn1ForWeekdays() { >+ final double A_MONDAY = DateUtil.getExcelDate(d(2017, 1, 2)); >+ assertEquals(1, WorkdayCalculator.instance.calculateWorkdays(A_MONDAY, A_MONDAY, new double[0])); >+ } >+ >+ @Test >+ public void testCalculateWorkdaysOnSameDayShouldReturn0ForHolidays() { >+ final double A_MONDAY = DateUtil.getExcelDate(d(2017, 1, 2)); >+ assertEquals(0, WorkdayCalculator.instance.calculateWorkdays(A_MONDAY, A_MONDAY, new double[]{ A_MONDAY })); >+ } >+ >+ @Test >+ public void testCalculateWorkdaysOnSameDayShouldReturn0ForWeekends() { >+ final double A_SUNDAY = DateUtil.getExcelDate(d(2017, 1, 1)); >+ assertEquals(0, WorkdayCalculator.instance.calculateWorkdays(A_SUNDAY, A_SUNDAY, new double[0])); >+ } >+ > @Test > public void testCalculateWorkdaysNumberOfDays() { > double start = 41553.0; >@@ -108,7 +126,7 @@ > final double A_SATURDAY = DateUtil.getExcelDate(d(2011, 12, 10)); > assertEquals(1, WorkdayCalculator.instance.pastDaysOfWeek(A_THURSDAY, A_SATURDAY, SATURDAY)); > } >- >+ > private static Date d(int year, int month, int day) { > Calendar cal = LocaleUtil.getLocaleCalendar(year, month-1, day, 0, 0, 0); > return cal.getTime();
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 60452
: 34505