Search in sources :

Example 16 with XSDateTime

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime in project webtools.sourceediting by eclipse.

the class FnYearFromDateTime method year_from_date_time.

/**
 * Year-from-DateTime operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:year-from-dateTime operation.
 */
public static ResultSequence year_from_date_time(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    XSDateTime dt = (XSDateTime) arg1.first();
    int res = dt.year();
    return new XSInteger(BigInteger.valueOf(res));
}
Also used : XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Collection(java.util.Collection)

Example 17 with XSDateTime

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime in project webtools.sourceediting by eclipse.

the class FnSecondsFromDateTime method seconds_from_date_time.

/**
 * Seconds-from-dateTime operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:seconds-from-dateTime operation.
 */
public static ResultSequence seconds_from_date_time(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    XSDateTime dt = (XSDateTime) arg1.first();
    double res = dt.second();
    return new XSDecimal(new BigDecimal(res));
}
Also used : XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Collection(java.util.Collection) XSDecimal(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal) BigDecimal(java.math.BigDecimal)

Example 18 with XSDateTime

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime in project webtools.sourceediting by eclipse.

the class FnCurrentDateTime method current_dateTime.

/**
 * Current-Date-Time operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param dc
 *            Result of dynamic context operation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:current-dateTime operation.
 */
public static ResultSequence current_dateTime(Collection args, DynamicContext dc) throws DynamicError {
    assert args.size() == 0;
    Duration d = dc.getTimezoneOffset();
    XSDayTimeDuration tz = new XSDayTimeDuration(0, d.getHours(), d.getMinutes(), 0.0, d.getSign() == -1);
    AnyType res = new XSDateTime(dc.getCurrentDateTime(), tz);
    return ResultSequenceFactory.create_new(res);
}
Also used : XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) Duration(javax.xml.datatype.Duration) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 19 with XSDateTime

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime in project webtools.sourceediting by eclipse.

the class XSDateTime method plus.

/**
 * Mathematical addition operator between this XSDateTime and a supplied
 * result sequence (XDTYearMonthDuration and XDTDayTimeDuration are only
 * valid ones).
 *
 * @param arg
 *            The supplied ResultSequence that is on the right of the minus
 *            operator. If arg is an XDTYearMonthDuration or an
 *            XDTDayTimeDuration the result will be a XSDateTime of the
 *            result of the current date minus the duration of time
 *            supplied.
 * @return New ResultSequence consisting of the result of the mathematical
 *         minus operation.
 */
public ResultSequence plus(ResultSequence arg) throws DynamicError {
    if (arg.size() != 1)
        DynamicError.throw_type_error();
    Item at = arg.first();
    try {
        if (at instanceof XSYearMonthDuration) {
            XSYearMonthDuration val = (XSYearMonthDuration) at;
            XSDateTime res = (XSDateTime) clone();
            res.calendar().add(Calendar.MONTH, val.monthValue());
            return ResultSequenceFactory.create_new(res);
        } else if (at instanceof XSDayTimeDuration) {
            XSDuration val = (XSDuration) at;
            XSDateTime res = (XSDateTime) clone();
            XMLGregorianCalendar xmlCal = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) calendar());
            Duration dtduration = _datatypeFactory.newDuration(val.getStringValue());
            xmlCal.add(dtduration);
            res = new XSDateTime(xmlCal.toGregorianCalendar(), res.tz());
            return ResultSequenceFactory.create_new(res);
        } else {
            DynamicError.throw_type_error();
            // unreach
            return null;
        }
    } catch (CloneNotSupportedException err) {
        assert false;
        return null;
    }
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Duration(javax.xml.datatype.Duration)

Aggregations

XSDateTime (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime)18 Collection (java.util.Collection)9 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)9 ArrayList (java.util.ArrayList)8 SeqType (org.eclipse.wst.xml.xpath2.processor.internal.SeqType)8 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)5 Duration (javax.xml.datatype.Duration)3 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)3 Iterator (java.util.Iterator)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 BigDecimal (java.math.BigDecimal)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Item (org.eclipse.wst.xml.xpath2.api.Item)1 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)1 CalendarType (org.eclipse.wst.xml.xpath2.processor.internal.types.CalendarType)1 XSDate (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDate)1 XSDecimal (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal)1 XSDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration)1 XSTime (org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime)1