sb.append(':').append(hours != 0 ? hours : "");
sb.append(':').append(minutes != 0 ? minutes : "");
sb.append(':').append(seconds != 0 ? seconds : "");
sb.append(':').append(milliseconds != 0 ? milliseconds : "");
String durationString = years + ":" + months + ":" + days + ":" + hours + ":" + minutes + ":" + seconds + ":" + milliseconds;
TimeDuration stringDuration = TimeDuration.parseDuration(sb.toString());
right.setTimeInMillis(0);
if (years != 0) {
right.set(Calendar.YEAR, 1970 + Math.abs(years));
}
if (months != 0) {
right.set(Calendar.MONTH, Math.abs(months));
}
right.set(Calendar.DAY_OF_MONTH, Math.abs(days) + 1);
if (hours != 0) {
right.set(Calendar.HOUR, Math.abs(hours));
}
if (minutes != 0) {
right.set(Calendar.MINUTE, Math.abs(minutes));
}
if (seconds != 0) {
right.set(Calendar.SECOND, Math.abs(seconds));
}
if (milliseconds != 0) {
right.set(Calendar.MILLISECOND, Math.abs(milliseconds));
}
TimeDuration calDuration = isNegative ? new TimeDuration(right, zero) : new TimeDuration(zero, right);
assertDurationFields(label + "(parseString[0])", years, months, days, hours, minutes, seconds, milliseconds, durationString, TimeDuration.parseDuration(durationString), isNegative, false);
assertDurationFields(label + "(parseString)", years, months, days, hours, minutes, seconds, milliseconds, durationString, stringDuration, isNegative, false);
assertDurationFields(label + "(cal)", years, months, days, hours, minutes, seconds, milliseconds, durationString, calDuration, isNegative, false);
Calendar added = calDuration.addToCalendar((Calendar) zero.clone());
TimeDuration addDuration = new TimeDuration(zero, added);
assertDurationFields(label + "(cal[add])", years, months, days, hours, minutes, seconds, milliseconds, durationString, addDuration, isNegative, false);
assertEquals(label + ".compareTo(string, cal)", 0, doCompare(stringDuration, calDuration));
assertEquals(label + ".compareTo(string, string)", 0, doCompare(stringDuration, stringDuration));
assertEquals(label + ".compareTo(cal, cal)", 0, doCompare(calDuration, calDuration));
assertEquals(label + ".compareTo(cal, string)", 0, doCompare(calDuration, stringDuration));