XMLGregorianCalendar cal1 = nv1.getDateTime() ;
XMLGregorianCalendar cal2 = nv2.getDateTime() ;
boolean isDef1 = ( cal1.getTimezone() == FIELD_UNDEFINED ) ;
boolean isDef2 = ( cal2.getTimezone() == FIELD_UNDEFINED ) ;
if ( ( isDef1 && !isDef2 ) || ( !isDef1 && isDef2 ) )
throw new ExprEvalTypeException("Operator '-': can't substract timezone/non-timezone values") ;
// Inspect duration and force to better type? xsd:dayTimeDuration
return NodeValue.makeDuration(xsd_substract(cal1, cal2));
}
// Loose style. Subtract any duration to any date or time value.
if ( vs1.equals(VSPACE_DATETIME) && vs2.equals(VSPACE_DURATION) )
{
XMLGregorianCalendar cal = nv1.getDateTime() ;
// add-negation
XMLGregorianCalendar result = xsd_subtract(cal, nv2.getDuration()) ;
NodeValue r = NodeValue.makeDateTime(result) ;
return r ;
}
if ( vs1.equals(VSPACE_DATE) && vs2.equals(VSPACE_DURATION) )
{
XMLGregorianCalendar cal = nv1.getDateTime() ;
// add-negation
XMLGregorianCalendar result = xsd_subtract(cal, nv2.getDuration()) ;
NodeValue r = NodeValue.makeDate(result) ;
return r ;
}
if ( vs1.equals(VSPACE_TIME) && vs2.equals(VSPACE_DURATION) )
{
XMLGregorianCalendar cal = nv1.getDateTime() ;
// add-negation
XMLGregorianCalendar result = xsd_subtract(cal, nv2.getDuration()) ;
NodeValue r = NodeValue.makeNode(result.toXMLFormat(), XSDDatatype.XSDtime) ;
return r ;
}
throw new ExprEvalTypeException("Operator '-' : Undefined subtraction: "+nv1+" and "+nv2) ;
}