예제 #1
0
        public override DvDuration Diff(DvTemporal <DvDate> b)
        {
            DesignByContract.Check.Require(b is DvDate, "Expected a DvDate instance in Diff function.");

            DvDate      bObj        = b as DvDate;
            Iso8601Date bObjIsoDate = bObj.isoDate;

            if (bObj == this)
            {
                return(new DvDuration("PT0S"));
            }

            double fractionalSecondsDiff = 0;
            int    secondsDiff           = 0;
            int    hoursDiff             = 0;
            int    minutesDiff           = 0;
            int    daysDiff   = 0;
            int    weeksDiff  = 0;
            int    monthsDiff = 0;
            int    yearsDiff  = 0;

            Iso8601Date leftOperand  = new Iso8601Date(this.Value);
            Iso8601Date rightOperand = new Iso8601Date(bObj.Value);

            if (leftOperand < rightOperand)
            {
                leftOperand  = new Iso8601Date(bObj.Value);;
                rightOperand = new Iso8601Date(this.Value);
            }

            if (!leftOperand.DayUnknown && !rightOperand.DayUnknown)
            {
                daysDiff = leftOperand.Day - rightOperand.Day;
            }

            int daysInMonth = 0;

            if (!leftOperand.MonthUnknown && !rightOperand.MonthUnknown)
            {
                monthsDiff = leftOperand.Month - rightOperand.Month;
                if (leftOperand.Month > 1)
                {
                    daysInMonth = System.DateTime.DaysInMonth(leftOperand.Year, leftOperand.Month - 1);
                }
                else
                {
                    daysInMonth = System.DateTime.DaysInMonth(leftOperand.Year - 1, leftOperand.Month - 1 + Iso8601DateTime.monthsInYear);
                }
            }
            yearsDiff = leftOperand.Year - rightOperand.Year;

            Iso8601Duration diff = Date.NormaliseDuration(yearsDiff, monthsDiff, weeksDiff, daysDiff, hoursDiff, minutesDiff, secondsDiff, fractionalSecondsDiff, daysInMonth);

            return(new DvDuration(diff.ToString()));
        }
예제 #2
0
        public override DvDuration Diff(DvTemporal <DvTime> b)
        {
            DesignByContract.Check.Require(b is DvTime, "Expected a DvTime instance in Diff function.");

            DvTime bObj = b as DvTime;

            if (bObj == this)
            {
                return(new DvDuration("PT0S"));
            }

            double fractionalSecondsDiff = 0;
            int    secondsDiff           = 0;
            int    hoursDiff             = 0;
            int    minutesDiff           = 0;
            int    daysDiff   = 0;
            int    weeksDiff  = 0;
            int    monthsDiff = 0;
            int    yearsDiff  = 0;

            Iso8601Time leftOperand  = new Iso8601Time(this.Value);
            Iso8601Time rightOperand = new Iso8601Time(bObj.Value);

            if (leftOperand < rightOperand)
            {
                leftOperand  = new Iso8601Time(bObj.Value);;
                rightOperand = new Iso8601Time(this.Value);
            }

            if (leftOperand.HasFractionalSecond && rightOperand.HasFractionalSecond)
            {
                fractionalSecondsDiff = leftOperand.FractionalSecond - rightOperand.FractionalSecond;
            }

            if (!leftOperand.SecondUnknown && !rightOperand.SecondUnknown)
            {
                secondsDiff = leftOperand.Second - rightOperand.Second;
            }

            if (!leftOperand.MinuteUnknown && !rightOperand.MinuteUnknown)
            {
                minutesDiff = leftOperand.Minute - rightOperand.Minute;
            }

            hoursDiff = leftOperand.Hour - rightOperand.Hour;

            int daysInMonth = 0;

            Iso8601Duration diff = Date.NormaliseDuration(yearsDiff, monthsDiff, weeksDiff, daysDiff, hoursDiff, minutesDiff, secondsDiff, fractionalSecondsDiff, daysInMonth);

            DesignByContract.Check.Assert(diff.Years == 0 && diff.Months == 0 && diff.Days == 0);

            return(new DvDuration(diff.ToString()));
        }
예제 #3
0
 public abstract DvDuration Diff(DvTemporal <T> b);