/** * Static factory: create a year-month duration value from a supplied string, in * ISO 8601 format [+|-]PnYnM * * @param s a string in the lexical space of xs:yearMonthDuration. * @return either a YearMonthDurationValue, or a ValidationFailure if the string was * not in the lexical space of xs:yearMonthDuration. */ public static ConversionResult makeYearMonthDurationValue(CharSequence s) { ConversionResult d = DurationValue.makeDuration(s, true, false); if (d instanceof ValidationFailure) { return d; } DurationValue dv = (DurationValue) d; return YearMonthDurationValue.fromMonths((dv.getYears() * 12 + dv.getMonths()) * dv.signum()); }
/** * Static factory: create a year-month duration value from a supplied string, in * ISO 8601 format [+|-]PnYnM * * @param s a string in the lexical space of xs:yearMonthDuration. * @return either a YearMonthDurationValue, or a ValidationFailure if the string was * not in the lexical space of xs:yearMonthDuration. */ public static ConversionResult makeYearMonthDurationValue(CharSequence s) { ConversionResult d = DurationValue.makeDuration(s, true, false); if (d instanceof ValidationFailure) { return d; } DurationValue dv = (DurationValue) d; return YearMonthDurationValue.fromMonths((dv.getYears() * 12 + dv.getMonths()) * dv.signum()); }
int months = getMonths(); int days = getDays(); int hours = getHours();
int months = getMonths(); int days = getDays(); int hours = getHours();
/** * Get a component of the normalized value */ public AtomicValue getComponent(int component) throws XPathException { switch (component) { case Component.YEAR: return Int64Value.makeIntegerValue((negative ? -getYears() : getYears())); case Component.MONTH: return Int64Value.makeIntegerValue((negative ? -getMonths() : getMonths())); case Component.DAY: return Int64Value.makeIntegerValue((negative ? -getDays() : getDays())); case Component.HOURS: return Int64Value.makeIntegerValue((negative ? -getHours() : getHours())); case Component.MINUTES: return Int64Value.makeIntegerValue((negative ? -getMinutes() : getMinutes())); case Component.SECONDS: FastStringBuffer sb = new FastStringBuffer(16); String ms = ("000000" + microseconds); ms = ms.substring(ms.length() - 6); sb.append((negative ? "-" : "") + getSeconds() + '.' + ms); return (AtomicValue)DecimalValue.makeDecimalValue(sb, false); case Component.WHOLE_SECONDS: return Int64Value.makeIntegerValue((negative ? -seconds : seconds)); case Component.MICROSECONDS: return new Int64Value((negative ? -microseconds : microseconds)); default: throw new IllegalArgumentException("Unknown component for duration: " + component); } }
/** * Get a component of the normalized value */ public AtomicValue getComponent(int component) throws XPathException { switch (component) { case Component.YEAR: return Int64Value.makeIntegerValue((negative ? -getYears() : getYears())); case Component.MONTH: return Int64Value.makeIntegerValue((negative ? -getMonths() : getMonths())); case Component.DAY: return Int64Value.makeIntegerValue((negative ? -getDays() : getDays())); case Component.HOURS: return Int64Value.makeIntegerValue((negative ? -getHours() : getHours())); case Component.MINUTES: return Int64Value.makeIntegerValue((negative ? -getMinutes() : getMinutes())); case Component.SECONDS: FastStringBuffer sb = new FastStringBuffer(16); String ms = ("000000" + microseconds); ms = ms.substring(ms.length() - 6); sb.append((negative ? "-" : "") + getSeconds() + '.' + ms); return (AtomicValue)DecimalValue.makeDecimalValue(sb, false); case Component.WHOLE_SECONDS: return Int64Value.makeIntegerValue((negative ? -seconds : seconds)); case Component.MICROSECONDS: return new Int64Value((negative ? -microseconds : microseconds)); default: throw new IllegalArgumentException("Unknown component for duration: " + component); } }