public CalculateResponse Calculate(CalculateRequest request)
        {
            Guard.NotNull(() => request, request);

            decimal price;
            var     totalHours = (request.EndDateTime - request.StartDateTime).TotalHours;

            if (totalHours < 1)
            {
                price = 5M;
            }
            else if (totalHours < 2)
            {
                price = 10M;
            }
            else if (totalHours < 3)
            {
                price = 15M;
            }
            else
            {
                price = 20M * ((request.EndDateTime.Date - request.StartDateTime.Date).Days + 1);
            }
            return(new CalculateResponse(RateName, price));
        }
Exemple #2
0
        public override CalculateResponse Calculate(CalculateRequest request)
        {
            Guard.NotNull(() => request, request);

            int startHour = request.StartDateTime.Hour,
                endHour   = request.EndDateTime.Hour;

            int inclMinStartHour = 18,
                exclMaxStartHour = 24,
                exclMaxEndHour   = 6;
            int maxEligibleHours = (24 - inclMinStartHour + exclMaxEndHour);
            var dayOfWeek        = request.StartDateTime.DayOfWeek;
            var isWeekend        = dayOfWeek == System.DayOfWeek.Saturday || dayOfWeek == System.DayOfWeek.Sunday;

            var isEligible =
                !isWeekend &&
                (request.EndDateTime - request.StartDateTime).TotalHours <= maxEligibleHours &&
                (inclMinStartHour <= startHour && startHour < exclMaxStartHour) &&
                (endHour < exclMaxEndHour);

            if (isEligible)
            {
                return(new CalculateResponse(RateName, 6.5M));
            }
            return(base.Calculate(request));
        }
        public override CalculateResponse Calculate(CalculateRequest request)
        {
            Guard.NotNull(() => request, request);

            double startHour = (double)request.StartDateTime.Hour + (request.StartDateTime.Minute / 60.0),
                   endHour   = (double)request.EndDateTime.Hour + (request.EndDateTime.Minute / 60.0);

            var isEligible = (6 <= startHour && startHour < 9) &&
                             (15.5 <= endHour && endHour < 23.5);

            if (isEligible)
            {
                return(new CalculateResponse(RateName, 13M));
            }
            return(base.Calculate(request));
        }
Exemple #4
0
        public override CalculateResponse Calculate(CalculateRequest request)
        {
            Guard.NotNull(() => request, request);

            var startDayOfWeek = request.StartDateTime.DayOfWeek;
            var endDayOfWeek   = request.EndDateTime.DayOfWeek;

            var isEligible = new HashSet <DayOfWeek> {
                request.StartDateTime.DayOfWeek, request.EndDateTime.DayOfWeek
            }.IsSubsetOf(new HashSet <DayOfWeek> {
                DayOfWeek.Saturday, DayOfWeek.Sunday
            });

            if (isEligible)
            {
                return(new CalculateResponse(RateName, 10M));
            }
            return(base.Calculate(request));
        }