garydgregory commented on a change in pull request #723:
URL: https://github.com/apache/commons-lang/pull/723#discussion_r585056995
##########
File path: src/main/java/org/apache/commons/lang3/time/DateUtils.java
##########
@@ -950,6 +958,156 @@ public static Date ceiling(final Object date, final int
field) {
}
}
+ public static long truncateCalendar(final Calendar val, final int field,
final Object obj){
+
+ // ----------------- Fix for LANG-59 ---------------------- START
---------------
+ // see https://issues.apache.org/jira/browse/LANG-59
+ //
+ // Manually truncate milliseconds, seconds and minutes, rather than
using
+ // Calendar methods.
+
+ final Date date = val.getTime();
+ long time = date.getTime();
+ boolean done = false;
+
+ ModifyType modType = (ModifyType) obj;
+
+ // truncate milliseconds
+ final int millisecs = val.get(Calendar.MILLISECOND);
+ if (ModifyType.TRUNCATE == modType || millisecs < 500) {
+ time = time - millisecs;
+ }
+ if (field == Calendar.SECOND) {
+ done = true;
+ }
+
+ // truncate seconds
+ final int seconds = val.get(Calendar.SECOND);
+ if (!done && (ModifyType.TRUNCATE == modType || seconds < 30)) {
+ time = time - (seconds * 1000L);
+ }
+ if (field == Calendar.MINUTE) {
+ done = true;
+ }
+
+ // truncate minutes
+ final int minutes = val.get(Calendar.MINUTE);
+ if (!done && (ModifyType.TRUNCATE == modType || minutes < 30)) {
+ time = time - (minutes * 60000L);
+ }
+
+ return time;
+ }
+ private static void modify2Version(final Calendar val, final int field,
final ModifyType modType) {
+ if (val.get(Calendar.YEAR) > 280000000) {
+ throw new ArithmeticException("Calendar value too large for
accurate calculations");
+ }
+
+ if (field == Calendar.MILLISECOND) {
+ return;
+ }
+
+ long time = truncateCalendar(val, field, modType);
+
+ final Date date = val.getTime();
+
+ // reset time
+ if (date.getTime() != time) {
+ date.setTime(time);
+ val.setTime(date);
+ }
+ // ----------------- Fix for LANG-59 ----------------------- END
----------------
+
+ boolean roundUp = false;
+ for (final int[] aField : fields) {
+ for (final int element : aField) {
+ if (element == field) {
+ //This is our field... we stop looping
+ if (modType == ModifyType.CEILING || modType ==
ModifyType.ROUND && roundUp) {
+ if (field == SEMI_MONTH) {
+ //This is a special case that's hard to generalize
+ //If the date is 1, we round up to 16, otherwise
+ // we subtract 15 days and add 1 month
+ if (val.get(Calendar.DATE) == 1) {
+ val.add(Calendar.DATE, 15);
+ } else {
+ val.add(Calendar.DATE, -15);
+ val.add(Calendar.MONTH, 1);
+ }
+// ----------------- Fix for LANG-440 ---------------------- START
---------------
Review comment:
No comments like this please.
##########
File path:
src/test/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyleMockingTest.java
##########
@@ -0,0 +1,130 @@
+package org.apache.commons.lang3.builder;
+
Review comment:
Missing header file break the build. Check the Actions tab.
##########
File path: pom.xml
##########
@@ -528,6 +528,12 @@
<!-- Lang should depend on very little -->
<dependencies>
<!-- testing -->
+ <dependency>
Review comment:
Use the current version of Mockito if you need it, not some random
antique version please.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]