fix to handle the tiny difference between YEAR and 12*MONTH

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137906 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2004-08-29 03:42:48 +00:00
parent a88c318251
commit 067a1cabd3

View File

@ -28,7 +28,7 @@
* @author Stephen Colebourne
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
* @since 2.0
* @version $Id: DurationFormatUtils.java,v 1.11 2004/08/27 06:45:25 bayard Exp $
* @version $Id: DurationFormatUtils.java,v 1.12 2004/08/29 03:42:48 bayard Exp $
*/
public class DurationFormatUtils {
@ -118,6 +118,11 @@ public static String format(long millis, String format) {
if(Token.containsTokenWithValue(tokens, M) ) {
months = (int) (millis / DateUtils.MILLIS_PER_MONTH);
millis = millis - (months * DateUtils.MILLIS_PER_MONTH);
// as MONTH * 12 != YEAR, this fixes issues
if(months == 12) {
years++;
months = 0;
}
}
if(Token.containsTokenWithValue(tokens, d) ) {
days = (int) (millis / DateUtils.MILLIS_PER_DAY);