Example #1
0
        /// <summary>
        /// Evaluate the function using the arguments passed.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <param name="sc">
        ///            Result of static context operation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of the fn:dateTime operation. </returns>
        public static ResultSequence dateTime(ICollection args, StaticContext sc)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            // get args
            IEnumerator argiter = cargs.GetEnumerator();

            argiter.MoveNext();
            ResultSequence arg1 = (ResultSequence)argiter.Current;

            argiter.MoveNext();
            ResultSequence arg2 = (ResultSequence)argiter.Current;

            // if either of the parameter is an empty sequence, the result
            // is an empty sequence
            if (arg1 == null || arg2 == null || 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, (int)Math.Floor(param2.second()));
            cal.set(Calendar.MILLISECOND, 0);

            XSDuration dateTimeZone = param1.tz();
            XSDuration timeTimeZone = param2.tz();

            if ((dateTimeZone != null && timeTimeZone != null) && !dateTimeZone.StringValue.Equals(timeTimeZone.StringValue))
            {
                // 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.StringValue.Equals(timeTimeZone.StringValue))
            {
                return(new XSDateTime(cal, dateTimeZone));
            }
            else
            {
                return(new XSDateTime(cal, null));
            }
        }
Example #2
0
        /// <summary>
        /// Evaluate the function using the arguments passed.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <param name="sc">
        ///            Result of static context operation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of the fn:dateTime operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence adjustDate(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext dc) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence adjustDate(ICollection args, DynamicContext dc)
        {
            ICollection cargs = Function.convert_arguments(args, expectedArgs());

            // get args
            IEnumerator argiter = cargs.GetEnumerator();

            argiter.MoveNext();
            ResultSequence arg1 = (ResultSequence)argiter.Current;

            if (arg1 == null || arg1.empty())
            {
                return(ResultBuffer.EMPTY);
            }
            ResultSequence arg2 = ResultBuffer.EMPTY;

            if (argiter.MoveNext())
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                arg2 = (ResultSequence)argiter.Current;
            }

            XSDate            date     = (XSDate)arg1.item(0);
            XSDayTimeDuration timezone = null;

            if (arg2.empty())
            {
                if (date.timezoned())
                {
                    XSDate localized = new XSDate(date.calendar(), null);
                    return(localized);
                }
                return(arg1);
            }

            timezone = (XSDayTimeDuration)arg2.item(0);
            if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc))
            {
                throw DynamicError.invalidTimezone();
            }

            if (date.tz() == null)
            {
                return(new XSDate(date.calendar(), timezone));
            }

            XMLGregorianCalendar xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar)date.normalizeCalendar(date.calendar(), date.tz()));

            Duration duration = _datatypeFactory.newDuration(timezone.StringValue);

            xmlCalendar.add(duration);

            return(new XSDate(xmlCalendar.toGregorianCalendar(), timezone));
        }
Example #3
0
        /// <summary>
        /// Timezone-from-Date operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:timezone-from-date operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence timezone_from_date(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence timezone_from_date(ICollection args)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());
            var         i     = cargs.GetEnumerator();

            i.MoveNext();
            ResultSequence arg1 = (ResultSequence)i.Current;

            if (arg1 == null || arg1.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            XSDate dt = (XSDate)arg1.first();

            if (dt.timezoned())
            {
                return(dt.tz());
            }
            return(ResultBuffer.EMPTY);
        }