コード例 #1
0
ファイル: XSDate.cs プロジェクト: kaby76/AntlrTreeEditing
        /// <summary>
        /// Comparison on this and the supplied dates (taking timezones into account)
        /// </summary>
        /// <param name="arg">
        ///            XSDate representation of the date to compare to </param>
        /// <exception cref="DynamicError"> </exception>
        /// <returns> True if in time, this date lies after the date supplied. False
        ///         otherwise. </returns>
        public virtual bool gt(AnyType arg, DynamicContext context)
        {
            XSDate   val     = (XSDate)NumericType.get_single_type((Item)arg, typeof(XSDate));
            Calendar thiscal = normalizeCalendar(calendar(), tz());
            Calendar thatcal = normalizeCalendar(val.calendar(), val.tz());

            return(thiscal.CompareTo(thatcal) > 0);
        }
コード例 #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
ファイル: XSDate.cs プロジェクト: kaby76/AntlrTreeEditing
        private ResultSequence minusXSYearMonthDuration(AnyType at)
        {
            XSYearMonthDuration val = (XSYearMonthDuration)at;

            try
            {
                XSDate res = (XSDate)clone();

                res.calendar().add(Calendar.MONTH, val.monthValue() * -1);
                return(ResultSequenceFactory.create_new(res));
            }
            catch
            {
            }
            return(null);
        }
コード例 #5
0
ファイル: XSDate.cs プロジェクト: kaby76/AntlrTreeEditing
        private XSDate castDate(Item aat)
        {
            if (aat is XSDate)
            {
                XSDate date = (XSDate)aat;
                return(new XSDate(date.calendar(), date.tz()));
            }

            if (aat is XSDateTime)
            {
                XSDateTime dateTime = (XSDateTime)aat;
                return(new XSDate(dateTime.calendar(), dateTime.tz()));
            }

            return(parse_date(aat.StringValue));
        }
コード例 #6
0
ファイル: XSDateTime.cs プロジェクト: kaby76/AntlrTreeEditing
        private CalendarType castDateTime(AnyAtomicType aat)
        {
            if (aat is XSDate)
            {
                XSDate date = (XSDate)aat;
                return(new XSDateTime(date.calendar(), date.tz()));
            }

            if (aat is XSDateTime)
            {
                XSDateTime dateTime = (XSDateTime)aat;
                return(new XSDateTime(dateTime.calendar(), dateTime.tz()));
            }

            return(parseDateTime(aat.StringValue));
        }
コード例 #7
0
ファイル: XSDate.cs プロジェクト: kaby76/AntlrTreeEditing
        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);
        }
コード例 #8
0
        private XSGDay castGDay(AnyAtomicType aat)
        {
            if (aat is XSGDay)
            {
                XSGDay gday = (XSGDay)aat;
                return(new XSGDay(gday.calendar(), gday.tz()));
            }

            if (aat is XSDate)
            {
                XSDate date = (XSDate)aat;
                return(new XSGDay(date.calendar(), date.tz()));
            }

            if (aat is XSDateTime)
            {
                XSDateTime dateTime = (XSDateTime)aat;
                return(new XSGDay(dateTime.calendar(), dateTime.tz()));
            }
            return(parse_gDay(aat.StringValue));
        }
コード例 #9
0
        private XSGYear castGYear(AnyAtomicType aat)
        {
            if (aat is XSGYear)
            {
                XSGYear gy = (XSGYear)aat;
                return(new XSGYear(gy.calendar(), gy.tz()));
            }

            if (aat is XSDate)
            {
                XSDate date = (XSDate)aat;
                return(new XSGYear(date.calendar(), date.tz()));
            }

            if (aat is XSDateTime)
            {
                XSDateTime dateTime = (XSDateTime)aat;
                return(new XSGYear(dateTime.calendar(), dateTime.tz()));
            }

            return(parse_gYear(aat.StringValue));
        }
コード例 #10
0
        private XSGYearMonth castGYearMonth(AnyAtomicType aat)
        {
            if (aat is XSGYearMonth)
            {
                XSGYearMonth gym = (XSGYearMonth)aat;
                return(new XSGYearMonth(gym.calendar(), gym.tz()));
            }

            if (aat is XSDate)
            {
                XSDate date = (XSDate)aat;
                return(new XSGYearMonth(date.calendar(), date.tz()));
            }

            if (aat is XSDateTime)
            {
                XSDateTime dateTime = (XSDateTime)aat;
                return(new XSGYearMonth(dateTime.calendar(), dateTime.tz()));
            }

            return(parse_gYearMonth(aat.StringValue));
        }
コード例 #11
0
        private XSGMonthDay castGMonthDay(AnyAtomicType aat)
        {
            if (aat is XSGMonthDay)
            {
                XSGMonthDay gmd = (XSGMonthDay)aat;
                return(new XSGMonthDay(gmd.calendar(), gmd.tz()));
            }

            if (aat is XSDate)
            {
                XSDate date = (XSDate)aat;
                return(new XSGMonthDay(date.calendar(), date.tz()));
            }

            if (aat is XSDateTime)
            {
                XSDateTime dateTime = (XSDateTime)aat;
                return(new XSGMonthDay(dateTime.calendar(), dateTime.tz()));
            }

            return(parse_gMonthDay(aat.StringValue));
        }
コード例 #12
0
ファイル: XSDate.cs プロジェクト: kaby76/AntlrTreeEditing
        /// <summary>
        /// Creates a new result sequence consisting of the retrievable date value in
        /// the supplied result sequence
        /// </summary>
        /// <param name="arg">
        ///            The result sequence from which to extract the date value. </param>
        /// <exception cref="DynamicError"> </exception>
        /// <returns> A new result sequence consisting of the date value supplied. </returns>
//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);
            }

            Item aat = arg.first();

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

            XSDate dt = castDate(aat);

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

            return(dt);
        }