Beispiel #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence constructor(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override ResultSequence constructor(ResultSequence arg)
        {
            if (arg.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            AnyAtomicType aat = (AnyAtomicType)arg.first();

            if (aat is NumericType || aat is CalendarType || aat is XSBoolean || aat is XSBase64Binary || aat is XSHexBinary || aat is XSAnyURI)
            {
                throw DynamicError.invalidType();
            }

            if (!isCastable(aat))
            {
                throw DynamicError.cant_cast(null);
            }

            XSDuration dtd = castDayTimeDuration(aat);

            if (dtd == null)
            {
                throw DynamicError.cant_cast(null);
            }

            return(dtd);
        }
Beispiel #2
0
        /// <summary>
        /// Mathematical subtraction between this duration stored and the supplied
        /// duration of time (of type XSDayTimeDuration)
        /// </summary>
        /// <param name="arg">
        ///            The duration of time to subtract </param>
        /// <returns> New XSDayTimeDuration representing the resulting duration after
        ///         the subtraction </returns>
        /// <exception cref="DynamicError"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence minus(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public virtual ResultSequence minus(ResultSequence arg)
        {
            XSDuration val = (XSDuration)NumericType.get_single_type(arg, typeof(XSDayTimeDuration));

            double res = value() - val.value();

            return(ResultSequenceFactory.create_new(new XSDayTimeDuration(res)));
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a representation of the supplied day
 /// </summary>
 /// <param name="cal">
 ///            Calendar representation of the day to be stored </param>
 /// <param name="tz">
 ///            Timezone associated with this day </param>
 public XSGDay(Calendar cal, XSDuration tz)
 {
     _calendar = cal;
     if (tz != null)
     {
         _timezoned = true;
         _tz        = tz;
     }
 }
Beispiel #4
0
        private XSDuration castYearMonthDuration(AnyAtomicType aat)
        {
            if (aat is XSDuration)
            {
                XSDuration duration = (XSDuration)aat;
                return(new XSYearMonthDuration(duration.year(), duration.month(), duration.negative()));
            }

            return(parseYMDuration(aat.StringValue));
        }
Beispiel #5
0
        private XSDuration castDayTimeDuration(AnyAtomicType aat)
        {
            if (aat is XSDuration)
            {
                XSDuration duration = (XSDuration)aat;
                return(new XSDayTimeDuration(duration.days(), duration.hours(), duration.minutes(), duration.seconds(), duration.negative()));
            }

            return(parseDTDuration(aat.StringValue));
        }
Beispiel #6
0
        /// <summary>
        /// Creates a new copy of the time (and timezone) stored
        /// </summary>
        /// <returns> New XSTime representing the copy of the time and timezone </returns>
        /// <exception cref="CloneNotSupportedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Object clone() throws CloneNotSupportedException
        public virtual object clone()
        {
            Calendar   c = (Calendar)calendar().clone();
            XSDuration t = tz();

            if (t != null)
            {
                t = (XSDuration)t.clone();
            }

            return(new XSTime(c, t));
        }
Beispiel #7
0
        /// <summary>
        /// Initialises to the supplied time and timezone
        /// </summary>
        /// <param name="cal">
        ///            Calendar representation of the time to be stored </param>
        /// <param name="tz">
        ///            The timezone (possibly null) associated with this time </param>
        public XSTime(Calendar cal, XSDuration tz)
        {
            _calendar = cal;

            _tz = tz;
            if (tz == null)
            {
                _timezoned = false;
            }
            else
            {
                _timezoned = true;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Equality comparison between this and the supplied duration of time.
        /// </summary>
        /// <param name="arg">
        ///            The duration of time to compare with </param>
        /// <returns> True if they both represent the duration of time. False otherwise </returns>
        /// <exception cref="DynamicError"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean eq(AnyType arg, org.eclipse.wst.xml.xpath2.api.DynamicContext dynamicContext) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override bool eq(AnyType arg, DynamicContext dynamicContext)
        {
            if (arg is XSDayTimeDuration)
            {
                XSDayTimeDuration dayTimeDuration = (XSDayTimeDuration)arg;
                return(monthValue() == 0 && dayTimeDuration.value() == 0.0);
            }
            else if (arg is XSYearMonthDuration)
            {
                XSYearMonthDuration yearMonthDuration = (XSYearMonthDuration)arg;
                return(monthValue() == yearMonthDuration.monthValue());
            }
            XSDuration val = (XSDuration)NumericType.get_single_type(arg, typeof(XSDuration));

            return(base.eq(val, dynamicContext));
        }
Beispiel #9
0
        /// <summary>
        /// Mathematical addition operator between this XSDateTime and a supplied
        /// result sequence (XDTYearMonthDuration and XDTDayTimeDuration are only
        /// valid ones).
        /// </summary>
        /// <param name="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. </param>
        /// <returns> New ResultSequence consisting of the result of the mathematical
        ///         minus operation. </returns>
        public virtual ResultSequence plus(ResultSequence arg)
        {
            if (arg.size() != 1)
            {
                DynamicError.throw_type_error();
            }

            Item at = arg.first();

            try
            {
                if (at is XSYearMonthDuration)
                {
                    XSYearMonthDuration val = (XSYearMonthDuration)at;

                    XSDateTime res = (XSDateTime)clone();

                    res.calendar().add(Calendar.MONTH, val.monthValue());
                    return(ResultSequenceFactory.create_new(res));
                }
                else if (at is XSDayTimeDuration)
                {
                    XSDuration val = (XSDuration)at;

                    XSDateTime res = (XSDateTime)clone();

                    XMLGregorianCalendar xmlCal     = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar)calendar());
                    Duration             dtduration = _datatypeFactory.newDuration(val.StringValue);
                    xmlCal.add(dtduration);
                    res = new XSDateTime(xmlCal.toGregorianCalendar(), res.tz());
                    return(ResultSequenceFactory.create_new(res));
                }
                else
                {
                    DynamicError.throw_type_error();
                    return(null);                    // unreach
                }
            }
            catch
            {
                Debug.Assert(false);
                return(null);
            }
        }
Beispiel #10
0
        public virtual Calendar normalizeCalendar(Calendar cal, XSDuration timezone)
        {
            Calendar adjusted = (Calendar)cal.clone();

            if (timezone != null)
            {
                int hours   = timezone.hours();
                int minutes = timezone.minutes();
                if (!timezone.negative())
                {
                    hours   *= -1;
                    minutes *= -1;
                }
                adjusted.AddHours(hours);
                adjusted.AddMinutes(minutes);
            }

            return(adjusted);
        }
Beispiel #11
0
        private ResultSequence minusXSDayTimeDuration(AnyType at)
        {
            XSDuration val = (XSDuration)at;

            try
            {
                XSDate res = (XSDate)clone();
                XMLGregorianCalendar xmlCal = _datatypeFactory
                                              .newXMLGregorianCalendar(
                    (GregorianCalendar)calendar());
                Duration dtduration = _datatypeFactory.newDuration(val.StringValue);
                xmlCal.add(dtduration.negate());
                res = new XSDate(xmlCal.toGregorianCalendar(), res.tz());
                return(ResultSequenceFactory.create_new(res));
            }
            catch
            {
            }
            return(null);
        }
Beispiel #12
0
        /// <summary>
        /// Mathematical addition between this time stored and the supplied time
        /// duration.
        /// </summary>
        /// <param name="arg">
        ///            A XDTDayTimeDuration representation of the duration of time to
        ///            add </param>
        /// <returns> A XSTime representing the result of this addition. </returns>
        /// <exception cref="DynamicError"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence plus(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public virtual ResultSequence plus(ResultSequence arg)
        {
            XSDuration val = (XSDuration)NumericType.get_single_type(arg, typeof(XSDayTimeDuration));

            try
            {
                double ms = val.time_value() * 1000.0;

                XSTime res = (XSTime)clone();

                res.calendar().add(Calendar.MILLISECOND, (int)ms);

                return(ResultSequenceFactory.create_new(res));
            }
            catch
            {
                Debug.Assert(false);
                return(null);
            }
        }
Beispiel #13
0
        private ResultSequence minusXSDayTimeDuration(Item at)
        {
            XSDuration val = (XSDuration)at;

            try
            {
                XSDateTime           res        = (XSDateTime)clone();
                XMLGregorianCalendar xmlCal     = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar)calendar());
                Duration             dtduration = _datatypeFactory.newDuration(val.StringValue);
                xmlCal.add(dtduration.negate());
                res = new XSDateTime(xmlCal.toGregorianCalendar(), res.tz());

                return(ResultSequenceFactory.create_new(res));
            }
            catch
            {
                throw;
            }
            //catch (CloneNotSupportedException)
            //{

            //}
            //return null;
        }
Beispiel #14
0
        /// <summary>
        /// Mathematical division between this duration stored and the supplied
        /// duration of time (of type XSDayTimeDuration)
        /// </summary>
        /// <param name="arg">
        ///            The duration of time to divide by </param>
        /// <returns> New XSDayTimeDuration representing the resulting duration after
        ///         the division </returns>
        /// <exception cref="DynamicError"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence div(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public virtual ResultSequence div(ResultSequence arg)
        {
            if (arg.size() != 1)
            {
                DynamicError.throw_type_error();
            }

            Item at = arg.first();

            if (at is XSDouble)
            {
                XSDouble dt     = (XSDouble)at;
                double   retval = 0;

                if (dt.nan())
                {
                    throw DynamicError.nan();
                }

                if (!dt.zero())
                {
                    decimal ret = new decimal(0);

                    if (dt.infinite())
                    {
                        retval = value() / dt.double_value();
                    }
                    else
                    {
                        ret = new decimal(value());
                        ret = decimal.Divide(ret, new decimal(dt.double_value()));
                        var x = ret.ToString();
                        double.TryParse(x, out double r);
                        retval = r;
                    }
                }
                else
                {
                    throw DynamicError.overflowUnderflow();
                }

                return(ResultSequenceFactory.create_new(new XSDayTimeDuration(retval)));
            }
            else if (at is XSDecimal)
            {
                XSDecimal dt = (XSDecimal)at;

                decimal ret = new decimal(0);

                if (!dt.zero())
                {
                    ret = new decimal(value());
                    ret = decimal.Divide(ret, dt.Value);
                }
                else
                {
                    throw DynamicError.overflowUnderflow();
                }

                var x = ret.ToString();
                double.TryParse(x, out double r);
                var i = (int)r;
                return(ResultSequenceFactory.create_new(new XSDayTimeDuration(i)));
            }
            else if (at is XSDayTimeDuration)
            {
                XSDuration md = (XSDuration)at;

                decimal res = default;
                res = new decimal(this.value());
                decimal l = new decimal(md.value());
                res = decimal.Divide(res, l);

                return(ResultSequenceFactory.create_new(new XSDecimal(res)));
            }
            else
            {
                DynamicError.throw_type_error();
                return(null);                // unreach
            }
        }
Beispiel #15
0
        /// <summary>
        /// Equality comparison between this and the supplied duration of time.
        /// </summary>
        /// <param name="arg">
        ///            The duration of time to compare with </param>
        /// <returns> True if they both represent the duration of time. False otherwise </returns>
        /// <exception cref="DynamicError"> </exception>
        public virtual bool eq(AnyType arg, DynamicContext dynamicContext)
        {
            XSDuration val = (XSDuration)NumericType.get_single_type(arg, typeof(XSDuration));

            return(value() == val.value());
        }
Beispiel #16
0
        /// <summary>
        /// Parses a String representation of a date and time and constructs a new
        /// XSDateTime object using that information
        /// </summary>
        /// <param name="str">
        ///            The String representation of the date (and optional timezone) </param>
        /// <returns> The XSDateTime representation of the date and time (and optional
        ///         timezone) </returns>
        public static XSDateTime parseDateTime(string str)
        {
            // oh no... not again

            // ok its three things:
            // date T time timezone

            int index = str.IndexOf('T');

            if (index == -1)
            {
                return(null);
            }

            // split date and rest...
            string date     = str.Substring(0, index);
            string time     = str.Substring(index + 1, str.Length - (index + 1));
            string timezone = null;

            // check for timezone
            index = time.IndexOf('+');
            if (index == -1)
            {
                index = time.IndexOf('-');
            }
            if (index == -1)
            {
                index = time.IndexOf('Z');
            }
            if (index != -1)
            {
                timezone = time.Substring(index, time.Length - index);
                time     = time.Substring(0, index);
            }

            // get date
            int[] d = parse_date(date);
            if (d == null)
            {
                return(null);
            }

            // SANITY CHEX
            var UTC = TimeZone.getTimeZone("UTC");
            GregorianCalendar cal = new GregorianCalendar(UTC);

            // year
            int year = d[0];

            if (year < 0)
            {
                year *= -1;
                cal.set(Calendar.ERA, GregorianCalendar.BC);
            }
            else
            {
                cal.set(Calendar.ERA, GregorianCalendar.AD);
            }

            // this is a nice bug....
            // if say the current day is 29...
            // then if we set the month to feb for example, and 29 doesn't
            // exist in that year, then the date screws up.
            cal.set(Calendar.DAY_OF_MONTH, 2);
            cal.set(Calendar.MONTH, 2);

            if (!set_item(cal, Calendar.YEAR, year))
            {
                return(null);
            }

            if (!set_item(cal, Calendar.MONTH, d[1] - 1))
            {
                return(null);
            }

            if (!set_item(cal, Calendar.DAY_OF_MONTH, d[2]))
            {
                return(null);
            }

            // get time
            double[] t = parse_time(time);
            if (t == null)
            {
                return(null);
            }

            if (!set_item(cal, Calendar.HOUR_OF_DAY, (int)t[0]))
            {
                return(null);
            }

            if (!set_item(cal, Calendar.MINUTE, (int)t[1]))
            {
                return(null);
            }

            if (!set_item(cal, Calendar.SECOND, (int)t[2]))
            {
                return(null);
            }

            double ms = t[2] - ((int)t[2]);

            ms *= 1000;
            if (!set_item(cal, Calendar.MILLISECOND, (int)ms))
            {
                return(null);
            }

            // get timezone
            int[]      tz  = null;
            XSDuration tzd = null;

            if (!string.ReferenceEquals(timezone, null))
            {
                tz = parse_timezone(timezone);

                if (tz == null)
                {
                    return(null);
                }

                tzd = new XSDayTimeDuration(0, tz[1], tz[2], 0.0, tz[0] < 0);
            }

            return(new XSDateTime(cal, tzd));
        }
Beispiel #17
0
        /// <summary>
        /// Comparison between this and the supplied duration of time.
        /// </summary>
        /// <param name="arg">
        ///            The duration of time to compare with </param>
        /// <returns> True if the supplied time represents a smaller duration than that
        ///         stored. False otherwise </returns>
        /// <exception cref="DynamicError"> </exception>
        public virtual bool gt(AnyType arg, DynamicContext context)
        {
            XSDuration val = (XSDuration)NumericType.get_single_type(arg, typeof(XSDayTimeDuration));

            return(value() > val.value());
        }