Sequence result;
if (args.length == 0 || args[0].isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
final Sequence arg = args[0];
final DurationValue duration = new DurationValue(((DurationValue) arg.itemAt(0)).getCanonicalDuration());
if (isCalledAs("days-from-duration")) {
result = new IntegerValue(duration.getPart(DurationValue.DAY));
} else if (isCalledAs("hours-from-duration")) {
result = new IntegerValue(duration.getPart(DurationValue.HOUR));
} else if (isCalledAs("minutes-from-duration")) {
result = new IntegerValue(duration.getPart(DurationValue.MINUTE));
} else if (isCalledAs("seconds-from-duration")) {
if (duration.getCanonicalDuration().getField(DatatypeConstants.SECONDS) == null)
{result = new DecimalValue(0);}
else
{result = new DecimalValue((BigDecimal)duration.getCanonicalDuration().getField(DatatypeConstants.SECONDS));}
if (duration.getCanonicalDuration().getSign() < 0)
{result = ((DecimalValue)result).negate();}
} else if (isCalledAs("months-from-duration")) {
result = new IntegerValue(duration.getPart(DurationValue.MONTH));
} else if (isCalledAs("years-from-duration")) {
result = new IntegerValue(duration.getPart(DurationValue.YEAR));
} else {
logger.error("can't handle function " + mySignature.getName().getLocalName());
throw new Error("can't handle function " + mySignature.getName().getLocalName());
}
}