Exemple #1
0
        /// <summary>
        /// Timezone-from-Time operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:timezone-from-time 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_time(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence timezone_from_time(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);
            }

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

            if (dt.timezoned())
            {
                return(dt.tz());
            }
            return(ResultBuffer.EMPTY);
        }
        /// <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 adjustTime(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext dc) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence adjustTime(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())
            {
                arg2 = (ResultSequence)argiter.Current;
            }
            XSTime            time     = (XSTime)arg1.first();
            XSDayTimeDuration timezone = null;

            if (arg2.empty())
            {
                if (time.timezoned())
                {
                    XSTime localized = new XSTime(time.calendar(), null);
                    return(localized);
                }
                else
                {
                    return(arg1);
                }
            }


            XMLGregorianCalendar xmlCalendar = null;

            if (time.tz() != null)
            {
                xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar)time.normalizeCalendar(time.calendar(), time.tz()));
            }
            else
            {
                xmlCalendar = _datatypeFactory.newXMLGregorianCalendarTime(time.hour(), time.minute(), (int)time.second(), 0);
            }

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

            if (time.tz() == null)
            {
                return(new XSTime(time.calendar(), timezone));
            }

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

            xmlCalendar.add(duration);

            return(new XSTime(xmlCalendar.toGregorianCalendar(), timezone));
        }