You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2006/06/19 14:48:08 UTC
svn commit: r415317 -
/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DurationFormatUtils.java
Author: bayard
Date: Mon Jun 19 05:48:08 2006
New Revision: 415317
URL: http://svn.apache.org/viewvc?rev=415317&view=rev
Log:
Committing fix for LANG-140. By reversing the order of field calculation, Yu Peng's bug goes away
Modified:
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DurationFormatUtils.java
Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DurationFormatUtils.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DurationFormatUtils.java?rev=415317&r1=415316&r2=415317&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DurationFormatUtils.java (original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DurationFormatUtils.java Mon Jun 19 05:48:08 2006
@@ -276,37 +276,38 @@
end.setTime(new Date(endMillis));
// initial estimates
- int years = end.get(Calendar.YEAR) - start.get(Calendar.YEAR);
+ int milliseconds = end.get(Calendar.MILLISECOND) - start.get(Calendar.MILLISECOND);
+ int seconds = end.get(Calendar.SECOND) - start.get(Calendar.SECOND);
+ int minutes = end.get(Calendar.MINUTE) - start.get(Calendar.MINUTE);
+ int hours = end.get(Calendar.HOUR_OF_DAY) - start.get(Calendar.HOUR_OF_DAY);
+ int days = end.get(Calendar.DAY_OF_MONTH) - start.get(Calendar.DAY_OF_MONTH);
int months = end.get(Calendar.MONTH) - start.get(Calendar.MONTH);
+ int years = end.get(Calendar.YEAR) - start.get(Calendar.YEAR);
+
// each initial estimate is adjusted in case it is under 0
- while (months < 0) {
- months += 12;
- years -= 1;
- }
- int days = end.get(Calendar.DAY_OF_MONTH) - start.get(Calendar.DAY_OF_MONTH);
- while (days < 0) {
- days += 31; // such overshooting is taken care of later on
- months -= 1;
+ while (milliseconds < 0) {
+ milliseconds += 1000;
+ seconds -= 1;
}
- int hours = end.get(Calendar.HOUR_OF_DAY) - start.get(Calendar.HOUR_OF_DAY);
- while (hours < 0) {
- hours += 24;
- days -= 1;
+ while (seconds < 0) {
+ seconds += 60;
+ minutes -= 1;
}
- int minutes = end.get(Calendar.MINUTE) - start.get(Calendar.MINUTE);
while (minutes < 0) {
minutes += 60;
hours -= 1;
}
- int seconds = end.get(Calendar.SECOND) - start.get(Calendar.SECOND);
- while (seconds < 0) {
- seconds += 60;
- minutes -= 1;
+ while (hours < 0) {
+ hours += 24;
+ days -= 1;
}
- int milliseconds = end.get(Calendar.MILLISECOND) - start.get(Calendar.MILLISECOND);
- while (milliseconds < 0) {
- milliseconds += 1000;
- seconds -= 1;
+ while (days < 0) {
+ days += 31; // such overshooting is taken care of later on
+ months -= 1;
+ }
+ while (months < 0) {
+ months += 12;
+ years -= 1;
}
// take estimates off of end to see if we can equal start, when it overshoots recalculate
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org