Ejemplo n.º 1
0
        /// <summary>
        /// Converts a relative date into an actual date.
        /// </summary>
        /// <param name="length">An amount of time.</param>
        /// <param name="timeUnit">The units in which the time is measured.</param>
        /// <returns>The current time plus the relative time.</returns>
        public static DateTime ToDateTime(Decimal length, TimeUnitCode timeUnit)
        {
            // Start with the current time.
            DateTime startDate = DateTime.Now;

            switch (timeUnit)
            {
            case TimeUnitCode.Days:

                // When the time is measured in days.
                startDate += TimeSpan.FromDays(Convert.ToInt32(length));
                break;

            case TimeUnitCode.Weeks:

                // When the time is measured in weeks.
                startDate += TimeSpan.FromDays(Convert.ToInt32(length) * 7);
                break;

            case TimeUnitCode.Months:

                // When the time is measured in months.
                startDate += TimeSpan.FromDays(Convert.ToInt32(length) * 30);
                break;
            }

            // This value represents and absolute date from today.
            return(startDate);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets an internal database identifier based on the Enumerated value.
 /// </summary>
 /// <param name="key">The strongly typed enumerated value.</param>
 /// <returns>The equivalent record identifier from the database.</returns>
 public static Guid FromCode(TimeUnitCode key)
 {
     return(TimeUnitMap.enumDictionary[key]);
 }