示例#1
0
        /// <summary>
        /// Get holidays in a given year. More can be added here...
        /// </summary>
        /// <param name="year">The year to fetch holidays dates in.</param>
        /// <returns>A list of holiday dates.</returns>
        public static Dictionary <DateTime, String> GetHolidaysInYear(Int32 year)
        {
            Dictionary <DateTime, String> holidays = new Dictionary <DateTime, String>();

            // New Years
            holidays.Add(new DateTime(year, 1, 1), "New Year's Day");
            // Dr. Martin Luther King Day
            holidays.Add(HDateTime.GetDayFromWeekOfMonth(new DateTime(year, 1, 1), WeekOfMonth.Third, DayOfWeek.Monday), "Dr. Martin Luther King Day");
            // President's Day
            holidays.Add(HDateTime.GetDayFromWeekOfMonth(new DateTime(year, 2, 1), WeekOfMonth.Third, DayOfWeek.Monday), "President's Day");
            // Memorial Day
            holidays.Add(HDateTime.GetDayFromWeekOfMonth(new DateTime(year, 5, 1), WeekOfMonth.Last, DayOfWeek.Monday), "Memorial Day");
            // Independence Day
            holidays.Add(new DateTime(year, 7, 4), "Independence Day");
            // Labor Day
            holidays.Add(HDateTime.GetDayFromWeekOfMonth(new DateTime(year, 9, 1), WeekOfMonth.First, DayOfWeek.Monday), "Labor Day");
            // Thanksgiving Day
            holidays.Add(HDateTime.GetDayFromWeekOfMonth(new DateTime(year, 11, 1), WeekOfMonth.Fourth, DayOfWeek.Thursday), "Thanksgiving Day");
            // Christmas Day
            holidays.Add(new DateTime(year, 12, 25), "Christmas Day");

            return(holidays);
        }
示例#2
0
 /// <summary>
 /// Get the end day in the given week.
 /// </summary>
 /// <param name="dt">The datetime to parse.</param>
 /// <param name="startOfWeek">The start day of the week.</param>
 /// <returns>The end of the week.</returns>
 public static DateTime LastOfWeek(DateTime dt, DayOfWeek startOfWeek)
 {
     return(HDateTime.FirstOfWeek(dt, startOfWeek).AddDays(6));
 }
示例#3
0
        /// <summary>
        /// Try to get the datetime from an object.
        /// </summary>
        /// <param name="value">Object to try to parse.</param>
        /// <returns>The parsed datetime or the current Utc datetime.</returns>
        public static DateTime GetDateTime(object value)
        {
            DateTime?newDateTime = HDateTime.GetDateTimeNullable(value);

            return(newDateTime != null ? newDateTime.Value : DateTime.UtcNow);
        }
示例#4
0
 /// <summary>
 /// Get holidays for a given month in a year.
 /// </summary>
 /// <param name="dt">The month date.</param>
 /// <returns>A list of holidays in a month.</returns>
 public static Dictionary <DateTime, String> GetHolidaysInMonth(DateTime dt)
 {
     return(HDateTime.GetHolidaysInYear(dt.Year).Where(kvp => kvp.Key.Month.Equals(dt.Month)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
 }
示例#5
0
 /// <summary>
 /// Get the total number of weeks in a month.
 /// </summary>
 /// <param name="dt">The datetime to evaluate.</param>
 /// <param name="startOfWeek">The start day of the week.</param>
 /// <returns>The total number of weeks in a month.</returns>
 public static Int32 GetNumberOfWeeks(DateTime dt, DayOfWeek startOfWeek)
 {
     return(HDateTime.GetWeekOfYear(HDateTime.LastOfMonth(dt), DayOfWeek.Sunday) - HDateTime.GetWeekOfYear(HDateTime.FirstOfMonth(dt), DayOfWeek.Sunday) + 1);
 }