Search in sources :

Example 11 with XSDateTime

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

the class FnSecondsFromDateTime method expected_args.

/**
 * Obtain a list of expected arguments.
 *
 * @return Result of operation.
 */
public static synchronized Collection expected_args() {
    if (_expected_args == null) {
        _expected_args = new ArrayList();
        _expected_args.add(new SeqType(new XSDateTime(), SeqType.OCC_QMARK));
    }
    return _expected_args;
}
Also used : XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) ArrayList(java.util.ArrayList)

Example 12 with XSDateTime

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

the class FnTimezoneFromDateTime method timezone_from_date_time.

/**
 * Timezone-from-DateTime operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:timezone-from-dateTime operation.
 */
public static ResultSequence timezone_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();
    if (dt.timezoned()) {
        return dt.tz();
    }
    return ResultBuffer.EMPTY;
}
Also used : XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Collection(java.util.Collection)

Example 13 with XSDateTime

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

the class FnTimezoneFromDateTime method expected_args.

/**
 * Obtain a list of expected arguments.
 *
 * @return Result of operation.
 */
public static synchronized Collection expected_args() {
    if (_expected_args == null) {
        _expected_args = new ArrayList();
        _expected_args.add(new SeqType(new XSDateTime(), SeqType.OCC_QMARK));
    }
    return _expected_args;
}
Also used : XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) ArrayList(java.util.ArrayList)

Example 14 with XSDateTime

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

the class FnMonthFromDateTime method expected_args.

/**
 * Obtain a list of expected arguments.
 *
 * @return Result of operation.
 */
public static synchronized Collection expected_args() {
    if (_expected_args == null) {
        _expected_args = new ArrayList();
        _expected_args.add(new SeqType(new XSDateTime(), SeqType.OCC_QMARK));
    }
    return _expected_args;
}
Also used : XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) ArrayList(java.util.ArrayList)

Example 15 with XSDateTime

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

the class FnAdjustDateTimeToTimeZone method adjustdateTime.

/**
 * Evaluate the function using the arguments passed.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param sc
 *            Result of static context operation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of the fn:dateTime operation.
 */
public static ResultSequence adjustdateTime(Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext dynamicContext) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expectedArgs());
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    ResultSequence arg2 = null;
    if (argiter.hasNext()) {
        arg2 = (ResultSequence) argiter.next();
    }
    XSDateTime dateTime = (XSDateTime) arg1.item(0);
    XSDayTimeDuration timezone = null;
    if (arg2 != null && arg2.empty()) {
        if (dateTime.timezoned()) {
            CalendarType localized = new XSDateTime(dateTime.calendar(), null);
            return localized;
        } else {
            return arg1;
        }
    } else if (arg2 == null) {
        CalendarType localized = new XSDateTime(dateTime.normalizeCalendar(dateTime.calendar(), dateTime.tz()), null);
        return localized;
    }
    timezone = (XSDayTimeDuration) arg2.item(0);
    if (timezone.lt(minDuration, dynamicContext) || timezone.gt(maxDuration, dynamicContext)) {
        throw DynamicError.invalidTimezone();
    }
    if (dateTime.tz() == null) {
        return new XSDateTime(dateTime.calendar(), timezone);
    }
    XMLGregorianCalendar xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) dateTime.normalizeCalendar(dateTime.calendar(), dateTime.tz()));
    Duration duration = _datatypeFactory.newDuration(timezone.getStringValue());
    xmlCalendar.add(duration);
    return new XSDateTime(xmlCalendar.toGregorianCalendar(), timezone);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) Collection(java.util.Collection) Duration(javax.xml.datatype.Duration) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) CalendarType(org.eclipse.wst.xml.xpath2.processor.internal.types.CalendarType)

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