Example #1
0
        private IEnumerable <Range <DateTime> > GetWeeklyDatebands(Dtos.NewTimesheetsRequest request)
        {
            var start      = request.PlacementStartDate;
            var end        = request.PlacementEndDate;
            var datebands  = new List <Range <DateTime> >();
            var startReset = false;

            while (start <= end)
            {
                var      datebandStart = start;
                DateTime datebandEnd   = DateTime.Today;

                if (!startReset)
                {
                    var startOfWeek = _dateHelper.GetFirstDayOfWeek(start);
                    start = startOfWeek.AddDays(7);

                    datebandEnd = start.AddDays(-1);
                }
                else
                {
                    start       = start.AddDays(7);
                    datebandEnd = datebandStart.AddDays(6);
                }

                if (datebandEnd > end)
                {
                    datebandEnd = end;
                }

                var universalStart = new DateTime(datebandStart.Year, datebandStart.Month, datebandStart.Day, 0, 0, 0, DateTimeKind.Utc);
                var universalEnd   = new DateTime(datebandEnd.Year, datebandEnd.Month, datebandEnd.Day, 0, 0, 0, DateTimeKind.Utc);
                datebands.Add(new Range <DateTime>()
                {
                    Start = universalStart,
                    End   = universalEnd
                });
            }

            return(datebands);
        }