Search in sources :

Example 1 with XSDateTime

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

the class FnDateTime method dateTime.

/**
 * 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 dateTime(Collection args, StaticContext sc) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    ResultSequence arg2 = (ResultSequence) argiter.next();
    // is an empty sequence
    if (arg1.empty() || arg2.empty()) {
        return ResultBuffer.EMPTY;
    }
    XSDate param1 = (XSDate) arg1.first();
    XSTime param2 = (XSTime) arg2.first();
    Calendar cal = Calendar.getInstance();
    cal.set(param1.year(), param1.month() - 1, param1.day());
    cal.set(Calendar.HOUR_OF_DAY, param2.hour());
    cal.set(Calendar.MINUTE, param2.minute());
    cal.set(Calendar.SECOND, (new Double(Math.floor(param2.second())).intValue()));
    cal.set(Calendar.MILLISECOND, 0);
    XSDuration dateTimeZone = param1.tz();
    XSDuration timeTimeZone = param2.tz();
    if ((dateTimeZone != null && timeTimeZone != null) && !dateTimeZone.getStringValue().equals(timeTimeZone.getStringValue())) {
        // it's an error, if the arguments have different timezones
        throw DynamicError.inconsistentTimeZone();
    } else if (dateTimeZone == null && timeTimeZone != null) {
        return new XSDateTime(cal, timeTimeZone);
    } else if (dateTimeZone != null && timeTimeZone == null) {
        return new XSDateTime(cal, dateTimeZone);
    } else if ((dateTimeZone != null && timeTimeZone != null) && dateTimeZone.getStringValue().equals(timeTimeZone.getStringValue())) {
        return new XSDateTime(cal, dateTimeZone);
    } else {
        return new XSDateTime(cal, null);
    }
}
Also used : XSDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration) XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) XSDate(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDate) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Calendar(java.util.Calendar) Iterator(java.util.Iterator) Collection(java.util.Collection) XSTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime)

Example 2 with XSDateTime

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

the class FnDayFromDateTime 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 3 with XSDateTime

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

the class FnDayFromDateTime method day_from_date_time.

/**
 * Day-From-DateTime operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:day-from-datetime operation.
 */
public static ResultSequence day_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.day();
    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 4 with XSDateTime

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

the class FnMinutesFromDateTime method minutes_from_date_time.

/**
 * Minutes-from-DateTime operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:minutes-from-dateTime operation.
 */
public static ResultSequence minutes_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.minute();
    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 5 with XSDateTime

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

the class FnMinutesFromDateTime 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)

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