Ejemplo n.º 1
0
        private static List <BinsContainer> GetMonthBinsForRange(BinFactoryOptions timeOptions)
        {
            var binsContainers = new List <BinsContainer>();

            if (timeOptions.TimeOption == BinFactoryOptions.TimeOptions.StartToEnd)
            {
                var binsContainer = new BinsContainer(timeOptions.Start, timeOptions.End);
                for (var startTime = new DateTime(timeOptions.Start.Year, timeOptions.Start.Month, 1);
                     startTime.Date < timeOptions.End.Date;
                     startTime = startTime.AddMonths(1))
                {
                    binsContainer.Bins.Add(new Bin {
                        Start = startTime, End = startTime.AddMonths(1)
                    });
                }
                binsContainers.Add(binsContainer);
            }
            else
            {
                for (var startTime = new DateTime(timeOptions.Start.Year, timeOptions.Start.Month, 1);
                     startTime.Date < timeOptions.End.Date;
                     startTime = startTime.AddMonths(1))
                {
                    binsContainers.Add(new BinsContainer(startTime, startTime.AddMonths(1))
                    {
                        Bins = GetDayBinsForRange(startTime, startTime.AddMonths(1),
                                                  timeOptions.TimeOfDayStartHour.Value, timeOptions.TimeOfDayStartMinute.Value,
                                                  timeOptions.TimeOfDayEndHour.Value, timeOptions.TimeOfDayEndMinute.Value,
                                                  timeOptions.DaysOfWeek)
                    });
                }
            }
            return(binsContainers);
        }
Ejemplo n.º 2
0
        private static List <BinsContainer> GetDayBinsContainersForRange(BinFactoryOptions timeOptions)
        {
            var binsContainers = new List <BinsContainer>();
            var binsContainer  = new BinsContainer(timeOptions.Start, timeOptions.End);

            for (var startTime = new DateTime(timeOptions.Start.Year, timeOptions.Start.Month, timeOptions.Start.Day, 0,
                                              0, 0);
                 startTime.Date < timeOptions.End.Date;
                 startTime = startTime.AddDays(1))
            {
                if (timeOptions.TimeOption == BinFactoryOptions.TimeOptions.StartToEnd)
                {
                    binsContainer.Bins.Add(new Bin {
                        Start = startTime, End = startTime.AddDays(1)
                    });
                }
                else
                {
                    if (timeOptions.TimeOfDayStartHour != null && timeOptions.TimeOfDayStartMinute != null &&
                        timeOptions.TimeOfDayEndHour != null && timeOptions.TimeOfDayEndMinute != null)
                    {
                        binsContainer.Bins.Add(new Bin
                        {
                            Start = startTime.AddHours(timeOptions.TimeOfDayStartHour.Value)
                                    .AddMinutes(timeOptions.TimeOfDayStartMinute.Value),
                            End = startTime.AddHours(timeOptions.TimeOfDayEndHour.Value)
                                  .AddMinutes(timeOptions.TimeOfDayEndMinute.Value)
                        });
                    }
                }
            }
            binsContainers.Add(binsContainer);
            return(binsContainers);
        }
Ejemplo n.º 3
0
        private static List <BinsContainer> GetDayBinsContainersForRange(BinFactoryOptions timeOptions)
        {
            var binsContainers = new List <BinsContainer>();

            if (timeOptions.DaysOfWeek == null)
            {
                timeOptions.DaysOfWeek = new List <DayOfWeek>
                {
                    DayOfWeek.Sunday,
                    DayOfWeek.Monday,
                    DayOfWeek.Tuesday,
                    DayOfWeek.Wednesday,
                    DayOfWeek.Thursday,
                    DayOfWeek.Friday,
                    DayOfWeek.Saturday
                }
            }
            ;
            var binsContainer = new BinsContainer(timeOptions.Start, timeOptions.End);

            for (var startTime = new DateTime(timeOptions.Start.Year, timeOptions.Start.Month, timeOptions.Start.Day, 0,
                                              0, 0);
                 startTime.Date <= timeOptions.End.Date;
                 startTime = startTime.AddDays(1))
            {
                if (timeOptions.TimeOption == BinFactoryOptions.TimeOptions.StartToEnd && timeOptions.DaysOfWeek.Contains(startTime.DayOfWeek))
                {
                    binsContainer.Bins.Add(new Bin {
                        Start = startTime, End = startTime.AddDays(1)
                    });
                }
                else
                {
                    if (timeOptions.TimeOfDayStartHour != null && timeOptions.TimeOfDayStartMinute != null &&
                        timeOptions.TimeOfDayEndHour != null && timeOptions.TimeOfDayEndMinute != null)
                    {
                        if (timeOptions.DaysOfWeek.Contains(startTime.DayOfWeek))
                        {
                            binsContainer.Bins.Add(new Bin
                            {
                                Start = startTime.AddHours(timeOptions.TimeOfDayStartHour.Value)
                                        .AddMinutes(timeOptions.TimeOfDayStartMinute.Value),
                                End = startTime.AddHours(timeOptions.TimeOfDayEndHour.Value)
                                      .AddMinutes(timeOptions.TimeOfDayEndMinute.Value)
                            });
                        }
                    }
                }
            }
            binsContainers.Add(binsContainer);
            return(binsContainers);
        }
Ejemplo n.º 4
0
        private static List <BinsContainer> GetBinsForRange(BinFactoryOptions timeOptions, int minutes)
        {
            var binsContainers = new List <BinsContainer>();
            var startTimeSpan  = new TimeSpan();
            var endTimeSpan    = new TimeSpan();
            var tempStart      = timeOptions.Start;
            var tempEnd        = timeOptions.End;

            if (//timeOptions.TimeOption == BinFactoryOptions.TimeOptions.TimePeriod &&
                timeOptions.TimeOfDayStartHour != null &&
                timeOptions.TimeOfDayStartMinute != null &&
                timeOptions.TimeOfDayEndHour != null &&
                timeOptions.TimeOfDayEndMinute != null)
            {
                startTimeSpan = new TimeSpan(0, timeOptions.TimeOfDayStartHour.Value,
                                             timeOptions.TimeOfDayStartMinute.Value, 0);
                endTimeSpan = new TimeSpan(0, timeOptions.TimeOfDayEndHour.Value,
                                           timeOptions.TimeOfDayEndMinute.Value, 0);
            }
            var binsContainer = new BinsContainer(timeOptions.Start, timeOptions.End);

            for (var startTime = tempStart;
                 startTime < tempEnd;
                 startTime = startTime.AddMinutes(minutes))
            {
                switch (timeOptions.TimeOption)
                {
                case BinFactoryOptions.TimeOptions.StartToEnd:
                    binsContainer.Bins.Add(new Bin {
                        Start = startTime, End = startTime.AddMinutes(minutes)
                    });
                    break;

                case BinFactoryOptions.TimeOptions.TimePeriod:
                    var periodStartTimeSpan = new TimeSpan(0, startTime.Hour,
                                                           startTime.Minute, 0);
                    if (timeOptions.DaysOfWeek.Contains(startTime.DayOfWeek) &&
                        periodStartTimeSpan >= startTimeSpan &&
                        periodStartTimeSpan < endTimeSpan)
                    {
                        binsContainer.Bins.Add(new Bin {
                            Start = startTime, End = startTime.AddMinutes(minutes)
                        });
                    }
                    break;
                }
            }
            binsContainers.Add(binsContainer);
            return(binsContainers);
        }