Period defines a set of time units (day, week, month, etc.)
Exemplo n.º 1
0
 /// <summary>
 /// Constructs an <b>Interval</b> from the provided multiplier and time
 /// unit.
 /// </summary>
 /// <param name="multiplier">The time period multiplier.</param>
 /// <param name="period">The time period unit.</param>
 public Interval(int multiplier, Period period)
 {
     this.multiplier = multiplier;
     this.period     = period;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Determines if an <b>Interval</b> will divide the time period delimited
        /// by two dates exactly.
        /// </summary>
        /// <param name="first">The first date.</param>
        /// <param name="last">The last date.</param>
        /// <returns><b>true</b> if the <b>Interval</b> exactly divides the two
        /// dates an integer number of times.</returns>
        public bool DividesDates(Date first, Date last)
        {
            int				multiplier	= this.multiplier;
            Period			period		= this.period;

            if (period == Period.TERM)
                return (multiplier == 1);

            if (period == Period.WEEK) {
                period = Period.DAY;
                multiplier *= 7;
            }

            if (period == Period.YEAR) {
                if (first.Month		 != last.Month)			return (false);
                if (first.DayOfMonth != last.DayOfMonth)	return (false);

                return (((last.Year - first.Year) % multiplier) == 0);
            }

            if (period == Period.MONTH) {
                if (first.DayOfMonth != last.DayOfMonth)	return (false);

                return ((((last.Year - first.Year) * 12 + last.Month - first.Month) % multiplier) == 0);
            }

            return (((last.GetHashCode () - first.GetHashCode ()) % multiplier) == 0);
        }