Exemplo n.º 1
0
        private int CalcYears()
        {
            if (TimeCompare.IsSameMonth(Date1, Date2))
            {
                return(0);
            }

            int compareDay          = Date2.Day;
            int compareDaysPerMonth = Calendar.GetDaysInMonth(Year1, Month2);

            if (compareDay > compareDaysPerMonth)
            {
                compareDay = compareDaysPerMonth;
            }
            DateTime compareDate = new DateTime(Year1, Month2, compareDay,
                                                Date2.Hour, Date2.Minute, Date2.Second, Date2.Millisecond);

            if (Date2 > Date1)
            {
                if (compareDate < Date1)
                {
                    compareDate = compareDate.AddYears(1);
                }
            }
            else
            {
                if (compareDate > Date1)
                {
                    compareDate = compareDate.AddYears(-1);
                }
            }
            return(Year2 - Calendar.GetYear(compareDate));
        }
Exemplo n.º 2
0
        private int CalcQuarters()
        {
            if (TimeCompare.IsSameMonth(Date1, Date2))
            {
                return(0);
            }

            int         year1    = TimeTool.GetYearOf(YearBaseMonth, Year1, Month1);
            YearQuarter quarter1 = TimeTool.GetQuarterOfMonth(YearBaseMonth, (YearMonth)Month1);

            int         year2    = TimeTool.GetYearOf(YearBaseMonth, Year2, Month2);
            YearQuarter quarter2 = TimeTool.GetQuarterOfMonth(YearBaseMonth, (YearMonth)Month2);

            return
                (((year2 * TimeSpec.QuartersPerYear) + quarter2) -
                 ((year1 * TimeSpec.QuartersPerYear) + quarter1));
        }