Пример #1
0
        }         // SetWorkingPeriod

        // ----------------------------------------------------------------------
        private void UpdateWorkingPeriodMode()
        {
            if (isWorkingPeriodUpdating)
            {
                return;
            }

            TimePeriodMode workingTimePeriod = TimePeriodMode.Custom;
            TimeRange      workingTimeRange  = WorkingTimeRange;

            if (workingTimeRange != null)
            {
                if (workingTimeRange.IsSamePeriod(new Year()))
                {
                    workingTimePeriod = TimePeriodMode.Year;
                }
                else if (workingTimeRange.IsSamePeriod(new Halfyear()))
                {
                    workingTimePeriod = TimePeriodMode.Halfyear;
                }
                else if (workingTimeRange.IsSamePeriod(new Quarter()))
                {
                    workingTimePeriod = TimePeriodMode.Quarter;
                }
                else if (workingTimeRange.IsSamePeriod(new Month()))
                {
                    workingTimePeriod = TimePeriodMode.Month;
                }
                else if (workingTimeRange.IsSamePeriod(new Week()))
                {
                    workingTimePeriod = TimePeriodMode.Week;
                }
                else if (workingTimeRange.IsSamePeriod(new Day()))
                {
                    workingTimePeriod = TimePeriodMode.Day;
                }
            }

            isWorkingPeriodUpdating = true;
            WorkingTimePeriod       = workingTimePeriod;
            isWorkingPeriodUpdating = false;
        }         // UpdateWorkingPeriodMode
Пример #2
0
        public static List<String> GetDatesForPeriod(string workDate, TimePeriodMode timePeriodMode
       , out string dateFrom, out string dateTo)
        {
            string dateFormat = "yyyy-MM-dd";
              var result = new List<String>();
              if(timePeriodMode == TimePeriodMode.Day)
              {
            dateFrom = dateTo = workDate;
            result.Add(dateFrom);
              }
              else
              {
            var baseDate = DateTime.ParseExact(workDate, dateFormat, CultureInfo.InvariantCulture);

            if(timePeriodMode == TimePeriodMode.Week)
            {
              int daysSpan = (baseDate.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)baseDate.DayOfWeek);
              dateFrom = baseDate.AddDays(-1 * daysSpan - 6).ToString(dateFormat);
              dateTo = baseDate.AddDays(-1 * daysSpan).ToString(dateFormat);
            }
            else
            {
              DateTime relativeDate = baseDate.AddDays(-1 * baseDate.Day);
              dateFrom = relativeDate.AddDays(-1 * (DateTime.DaysInMonth(relativeDate.Year, relativeDate.Month) - 1)).ToString(dateFormat);
              dateTo = relativeDate.ToString(dateFormat);
            }

            baseDate = DateTime.ParseExact(dateFrom, dateFormat, CultureInfo.InvariantCulture);
            int counter = 0;
            while (baseDate.AddDays(counter).ToString(dateFormat).CompareTo(dateTo) <= 0)
            {
              result.Add(baseDate.AddDays(counter).ToString(dateFormat));
              counter++;
            }
              }

              return result;
        }