コード例 #1
0
        public static IEnumerable <int> DateRange(this int beginDate, int endDate, int step = 1)
        {
            int fromDate = beginDate;
            int toDate   = endDate;

            while ((step >= 0 ? (fromDate <= toDate) : (fromDate >= toDate)))
            {
                yield return(fromDate);

                fromDate = fromDate.AddDays(step);
            }
        }
コード例 #2
0
        public static DateTime GetWorkingDay(DateTime month, int day)
        {
            month = month.AddDays(-(month.Day - 1));
            DateTime _month = month.Date;

            //MessageBox.Show(month.Day.ToString());

            for (int daysCount = 0; month.Day < DateTime.MaxValue.Month; month = month.AddDays(1))
            {
                if (month.DayOfWeek != DayOfWeek.Sunday &&
                    month.DayOfWeek != DayOfWeek.Saturday)
                {
                    daysCount++;
                }

                // If the working days reach [day], return the current count days
                if (daysCount >= day)
                {
                    return(month);
                }
            }

            return(_month);
        }
コード例 #3
0
 public static int AddWeeks(this int date, int weeks)
 {
     return(date.AddDays(7 * weeks));
 }