Exemplo n.º 1
0
        public int Count(DateTimeUnitEnums unit)
        {
            var      nb       = 0;
            DateTime iterator = StartDate;

            while (iterator <= EndDate)
            {
                nb++;
                if (unit == DateTimeUnitEnums.Months)
                {
                    iterator = iterator.AddMonths(1);
                }
                else
                {
                    iterator = iterator.AddYears(1);
                }
            }
            return(nb);
        }
Exemplo n.º 2
0
        public Interval(DateTime baseDate, DateTimeUnitEnums unit, int nb)
        {
            DateTime baseStartDate;

            if (unit == DateTimeUnitEnums.Months)
            {
                baseStartDate = baseDate.AddMonths(-nb);
            }
            else
            {
                baseStartDate = baseDate.AddYears(-nb);
            }

            // First date of the month
            this.StartDate = new DateTime(baseStartDate.Year, baseStartDate.Month, 1);

            // Last date of the month
            this.EndDate = new DateTime(baseDate.Year, baseDate.Month, 1).AddDays(-1);
        }