break;
}
case ID_DATETIME_ADD_YEARMONTHDURATION:
case ID_DATETIME_SUBTRACT_YEARMONTHDURATION: {
DateTimeAttribute dateTime = (DateTimeAttribute) argValues[0];
YearMonthDurationAttribute duration = (YearMonthDurationAttribute) argValues[1];
// Decide what sign goes with duration
int sign = 1;
if (getFunctionId() == ID_DATETIME_SUBTRACT_YEARMONTHDURATION)
sign = -sign;
if (duration.isNegative())
sign = -sign;
// Add (or subtract) the years and months.
Calendar cal = new GregorianCalendar();
cal.setTime(dateTime.getValue());
long years = sign * duration.getYears();
long months = sign * duration.getMonths();
if ((years > Integer.MAX_VALUE) || (years < Integer.MIN_VALUE))
return makeProcessingError("years too large");
if ((months > Integer.MAX_VALUE) || (months < Integer.MIN_VALUE))
return makeProcessingError("months too large");
cal.add(Calendar.YEAR, (int) years);
cal.add(Calendar.MONTH, (int) months);
attrResult = new DateTimeAttribute(cal.getTime(), dateTime.getNanoseconds(), dateTime
.getTimeZone(), dateTime.getDefaultedTimeZone());
break;
}
case ID_DATE_ADD_YEARMONTHDURATION:
case ID_DATE_SUBTRACT_YEARMONTHDURATION: {
DateAttribute date = (DateAttribute) argValues[0];
YearMonthDurationAttribute duration = (YearMonthDurationAttribute) argValues[1];
// Decide what sign goes with duration
int sign = 1;
if (getFunctionId() == ID_DATE_SUBTRACT_YEARMONTHDURATION)
sign = -sign;
if (duration.isNegative())
sign = -sign;
// Add (or subtract) the years and months.
Calendar cal = new GregorianCalendar();
cal.setTime(date.getValue());
long years = sign * duration.getYears();
long months = sign * duration.getMonths();
if ((years > Integer.MAX_VALUE) || (years < Integer.MIN_VALUE))
return makeProcessingError("years too large");
if ((months > Integer.MAX_VALUE) || (months < Integer.MIN_VALUE))
return makeProcessingError("months too large");