Sequence result;
if (args.length == 0 || args[0].isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
final Sequence arg = args[0];
final AbstractDateTimeValue date = (AbstractDateTimeValue) arg.itemAt(0);
if (isCalledAs("day-from-dateTime") || isCalledAs("day-from-date")) {
result = new IntegerValue(date.getPart(DateValue.DAY), Type.INTEGER);
} else if (isCalledAs("month-from-dateTime") || isCalledAs("month-from-date")) {
result = new IntegerValue(date.getPart(DateValue.MONTH),
Type.INTEGER);
} else if (isCalledAs("year-from-dateTime") || isCalledAs("year-from-date")) {
result = new IntegerValue(date.getPart(DateValue.YEAR),
Type.INTEGER);
} else if (isCalledAs("hours-from-dateTime") || isCalledAs("hours-from-time")) {
result = new IntegerValue(date.getPart(DateValue.HOUR),
Type.INTEGER);
} else if (isCalledAs("minutes-from-dateTime") || isCalledAs("minutes-from-time")) {
result = new IntegerValue(date.getPart(DateValue.MINUTE),
Type.INTEGER);
} else if (isCalledAs("seconds-from-dateTime") || isCalledAs("seconds-from-time")) {
result = new IntegerValue(date.calendar.getSecond()).convertTo(Type.DECIMAL);
if (date.calendar.getFractionalSecond() != null)
{result = ((DecimalValue)result).plus(new DecimalValue(date.calendar.getFractionalSecond()));}
} else if (isCalledAs("timezone-from-dateTime") || isCalledAs("timezone-from-date") || isCalledAs("timezone-from-time")) {
result = date.getTimezone();
} else {
logger.error("can't handle function " + mySignature.getName().getLocalName());
throw new Error("can't handle function " + mySignature.getName().getLocalName());
}
}