コード例 #1
0
        private ResultSequence minusXSTimeDuration(Item at)
        {
            XSTime   val        = (XSTime)at;
            Duration dtduration = null;
            Calendar thisCal    = normalizeCalendar(calendar(), tz());
            Calendar thatCal    = normalizeCalendar(val.calendar(), val.tz());
            long     duration   = thisCal.getTimeInMillis() - thatCal.getTimeInMillis();

            dtduration = _datatypeFactory.newDuration(duration);
            return(ResultSequenceFactory.create_new(XSDayTimeDuration.parseDTDuration(dtduration.ToString())));
        }
コード例 #2
0
ファイル: XSDate.cs プロジェクト: kaby76/AntlrTreeEditing
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private org.eclipse.wst.xml.xpath2.api.ResultSequence minusXSDate(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        private ResultSequence minusXSDate(ResultSequence arg)
        {
            XSDate   val        = (XSDate)NumericType.get_single_type(arg, typeof(XSDate));
            Duration dtduration = null;
            Calendar thisCal    = normalizeCalendar(calendar(), tz());
            Calendar thatCal    = normalizeCalendar(val.calendar(), val.tz());
            long     duration   = thisCal.getTimeInMillis()
                                  - thatCal.getTimeInMillis();

            dtduration = _datatypeFactory.newDuration(duration);
            return(ResultSequenceFactory.create_new(XSDayTimeDuration.parseDTDuration(dtduration.ToString())));
        }
コード例 #3
0
ファイル: XSDate.cs プロジェクト: kaby76/AntlrTreeEditing
        /// <summary>
        /// Mathematical addition operator between this XSDate 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 XSDate 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>
//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)
        {
            if (arg.size() != 1)
            {
                DynamicError.throw_type_error();
            }

            Item at = arg.first();

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

                    XSDate res = (XSDate)clone();

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

                    XSDate res = (XSDate)clone();

                    // We only need to add the Number of days dropping the rest.
                    int days = val.days();
                    if (val.negative())
                    {
                        days *= -1;
                    }
                    res.calendar().add(Calendar.DAY_OF_MONTH, days);

                    res.calendar().add(Calendar.MILLISECOND,
                                       (int)(val.time_value() * 1000.0));
                    return(ResultSequenceFactory.create_new(res));
                }
                else
                {
                    DynamicError.throw_type_error();
                    return(null);                    // unreach
                }
            }
            catch
            {
                Debug.Assert(false);
                return(null);
            }
        }
コード例 #4
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));
        }
コード例 #5
0
ファイル: XSDateTime.cs プロジェクト: kaby76/AntlrTreeEditing
        /// <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));
        }