public Sequence eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv)
throws XQueryException {
Item arg1 = argv.getItem(0);
Item arg2 = argv.getItem(1);
DateTimeValue date = (DateTimeValue) arg1;
DateTimeValue time = (DateTimeValue) arg2;
XMLGregorianCalendar dateValue = date.getValue();
XMLGregorianCalendar newValue = (XMLGregorianCalendar) dateValue.clone();
XMLGregorianCalendar timeValue = time.getValue();
final int timeTz = timeValue.getTimezone();
if(timeTz != DatatypeConstants.FIELD_UNDEFINED) {
final int dateTz = newValue.getTimezone();
if(dateTz != DatatypeConstants.FIELD_UNDEFINED && dateTz != timeTz) {
throw new DynamicError("err:FORG0008", "fn:dateTime(" + date + ", " + time
+ ") for `" + dateValue.getTimeZone(dateTz).getID() + " and `"
+ timeValue.getTimeZone(timeTz).getID() + "` is not allowed.");
}
newValue.setTimezone(timeTz);
}
newValue.setTime(timeValue.getHour(), timeValue.getMinute(), timeValue.getSecond(), timeValue.getMillisecond());
DateTimeValue dt = new DateTimeValue(newValue, DateTimeType.DATETIME);
return dt;
}