Click here to Skip to main content
15,892,298 members
Articles / Programming Languages / C#

Recurring Date Generator with Pattern Coding

Rate me:
Please Sign up or sign in to vote.
4.95/5 (51 votes)
4 Sep 2007CPOL4 min read 146.9K   6.9K   98  
Create recurring dates using a user-defined pattern. Create recurring dates from a coded value that defines what the pattern should be.
using System;
using System.Collections.Generic;

namespace RecurrenceGenerator
{
    public class RecurrenceValues
    {
        List<DateTime> values = new List<DateTime>() ;
        DateTime endDate;
        DateTime startDate;
        string seriesInfo;

        public RecurrenceValues() { }

        /// <summary>
        /// Get a Generic.List<DateTime> of Recurrence values.
        /// </summary>
        public List<DateTime> Values
        {
            get
            {
                return values;
            }
        }

        public DateTime LastDate
        {
          	get
            {
                if (values.Count > 0)
                    return values[values.Count - 1];
                else
                    return DateTime.MaxValue;
            }
        }

        /// <summary>
        /// Add a date to the List of Values. 
        /// </summary>
        /// <param name="recurrenceDate"></param>
        internal void AddDateValue(DateTime recurrenceDate)
        {
            values.Add(recurrenceDate);
        }

        /// <summary>
        /// Add a date to the List of Values adjusting it with the plus/minus x-days value
        /// </summary>
        /// <param name="recurrenceDate"></param>
        /// <param name="adjustedValue"></param>
        internal void AddDateValue(DateTime recurrenceDate, int adjustedValue)
        {
            values.Add(recurrenceDate.AddDays(adjustedValue));
        }

        /// <summary>
        ///     Set the Start Date. Only accessable from this assembly 
        ///     and usually set when trying to get the next date or 
        ///     an existing set of dates.
        /// </summary>
        /// <param name="startingDate" type="System.DateTime">
        ///     <para>
        ///         
        ///     </para>
        /// </param>
        internal void SetStartDate(DateTime startingDate)
        {
            startDate = startingDate;
        }

        /// <summary>
        ///     Set the SeriesInfo. Only accessable from this assembly 
        ///     and usually set when trying to get the next date or 
        ///     an existing set of dates.
        /// </summary>
        /// <param name="seriesInfo" type="string">
        ///     <para>
        ///         
        ///     </para>
        /// </param>
        internal void SetSeriesInfo(string seriesInfo)
        {
            this.seriesInfo = seriesInfo;
        }

        /// <summary>
        ///     Set the End Date. Only accessable from this assembly 
        ///     and usually set when trying to get the next date or 
        ///     an existing set of dates.
        /// </summary>
        /// <param name="endingDate" type="System.DateTime">
        ///     <para>
        ///         
        ///     </para>
        /// </param>
        internal void SetEndDate(DateTime endingDate)
        {
            endDate = endingDate;
        }

        /// <summary>
        ///     Readonly Start Date value. This is the first date of the recurring values.
        /// </summary>
        /// <value>
        ///     <para>
        ///         
        ///     </para>
        /// </value>
        /// <remarks>
        ///     
        /// </remarks>
        public DateTime StartDate
        {
            get
            {
                return startDate;
            }
        }

        /// <summary>
        ///     Readonly End Date value. This is the last date in the recurring values.
        /// </summary>
        /// <value>
        ///     <para>
        ///         
        ///     </para>
        /// </value>
        /// <remarks>
        ///     
        /// </remarks>
        public DateTime EndDate
        {
            get
            {
                return endDate;
            }
        }

        /// <summary>
        /// Series Information contained in a coded string.
        /// </summary>
        public string GetSeriesInfo()
        {
            return seriesInfo;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) BOCA Software Technologies, Inc.
United States United States
.NET Developer in Garner, North Carolina. Specializing in WinForms development in C#, VB.Net.

CEO/Founder BOCA Software Technologies, Inc.

Comments and Discussions