You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2010/02/17 18:20:05 UTC

svn commit: r911082 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/TimeDuration.java

Author: doogie
Date: Wed Feb 17 17:20:04 2010
New Revision: 911082

URL: http://svn.apache.org/viewvc?rev=911082&view=rev
Log:
Move the calendar helper methods to right after the constructor.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/TimeDuration.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/TimeDuration.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/TimeDuration.java?rev=911082&r1=911081&r2=911082&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/TimeDuration.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/TimeDuration.java Wed Feb 17 17:20:04 2010
@@ -129,6 +129,46 @@
         }
     }
 
+    private static long computeDeltaMillis(long start, long end) {
+        if (start < 0) {
+            return end + (-start);
+        }
+        return end - start;
+    }
+
+    private static int advanceCalendar(Calendar start, Calendar end, int units, int type) {
+        if (units >= 1) {
+            // Bother, the below needs explanation.
+            //
+            // If start has a day value of 31, and you add to the month,
+            // and the target month is not allowed to have 31 as the day
+            // value, then the day will be changed to a value that is in
+            // range.  But, when the code needs to then subtract 1 from
+            // the month, because it has advanced to far, the day is *not*
+            // set back to the original value of 31.
+            //
+            // This bug can be triggered by having a duration of -1 day,
+            // then adding this duration to a calendar that represents 0
+            // milliseconds, then creating a new duration by using the 2
+            // Calendar constructor, with cal1 being 0, and cal2 being the
+            // new calendar that you added the duration to.
+            //
+            // To solve this problem, we make a temporary copy of the
+            // start calendar, and only modify it if we actually have to.
+            Calendar tmp = (Calendar) start.clone();
+            int tmpUnits = units;
+            tmp.add(type, tmpUnits);
+            while (tmp.after(end)) {
+                tmp.add(type, -1);
+                units--;
+            }
+            if (units != 0) {
+                start.add(type, units);
+            }
+        }
+        return units;
+    }
+
     @Override
     public boolean equals(Object obj) {
         if (obj == this) {
@@ -229,46 +269,6 @@
         return cal;
     }
 
-    private static long computeDeltaMillis(long start, long end) {
-        if (start < 0) {
-            return end + (-start);
-        }
-        return end - start;
-    }
-
-    private static int advanceCalendar(Calendar start, Calendar end, int units, int type) {
-        if (units >= 1) {
-            // Bother, the below needs explanation.
-            //
-            // If start has a day value of 31, and you add to the month,
-            // and the target month is not allowed to have 31 as the day
-            // value, then the day will be changed to a value that is in
-            // range.  But, when the code needs to then subtract 1 from
-            // the month, because it has advanced to far, the day is *not*
-            // set back to the original value of 31.
-            //
-            // This bug can be triggered by having a duration of -1 day,
-            // then adding this duration to a calendar that represents 0
-            // milliseconds, then creating a new duration by using the 2
-            // Calendar constructor, with cal1 being 0, and cal2 being the
-            // new calendar that you added the duration to.
-            //
-            // To solve this problem, we make a temporary copy of the
-            // start calendar, and only modify it if we actually have to.
-            Calendar tmp = (Calendar) start.clone();
-            int tmpUnits = units;
-            tmp.add(type, tmpUnits);
-            while (tmp.after(end)) {
-                tmp.add(type, -1);
-                units--;
-            }
-            if (units != 0) {
-                start.add(type, units);
-            }
-        }
-        return units;
-    }
-
     protected void makeNegative() {
         this.millis = Math.min(this.millis, -this.millis);
         this.seconds = Math.min(this.seconds, -this.seconds);