public override decimal TotalUnits()
        {
            var periods = new List <Tuple <DateTime, DateTime> >();

            var startTimeWithCharge = new DateTime(StartTimeWithCharge.Year, StartTimeWithCharge.Month, StartTimeWithCharge.Day, 8, 0, 0);

            if (StartTimeWithCharge > new DateTime(StartTimeWithCharge.Year, StartTimeWithCharge.Month, StartTimeWithCharge.Day, 18, 0, 0))
            {
                // If the start time is after the end of the charge period then we move for the next day at 8 am
                startTimeWithCharge = WeekHelper.MoveNextDay(startTimeWithCharge);
            }

            while (startTimeWithCharge < EndTimeWithCharge)
            {
                if (WeekHelper.IsWeekday(startTimeWithCharge))
                {
                    //add range to end of day
                    periods.Add(Tuple.Create(startTimeWithCharge,
                                             WeekHelper.MoveToEndOfDay(startTimeWithCharge)));
                }

                // move to next day at 8 am
                startTimeWithCharge = WeekHelper.MoveNextDay(startTimeWithCharge);
            }

            return((decimal)ChargeCalculator.CalculatePeriod(periods, StartTimeWithCharge, EndTimeWithCharge));
        }
Beispiel #2
0
        private static void Main()
        {
            //Using a generic calculator as it seems more clean for the hardcode but can also use the method within the class
            var calculator = new ChargeCalculator();

            Console.WriteLine("A stay entirely outside of a chargeable period will return " + calculator.CalculateTotalCost(new ShortStayCharge(DateTime.Parse("03/05/2019 18:01:00"),
                                                                                                                                                DateTime.Parse("03/05/2019 21:00:00"))));

            Console.WriteLine("A short stay from 07/09/2017 16:50:00 to 09/09/2017 19:15:00 would cost " + calculator.CalculateTotalCost(new ShortStayCharge(DateTime.Parse("07/09/2017 16:50:00"), DateTime.Parse("09/09/2017 19:15:00"))));

            Console.WriteLine("A long stay from 07/09/2017 07:50:00 to 09/09/2017 05:20:00 would cost " + calculator.CalculateTotalCost(new LongStayCharge(DateTime.Parse("07/09/2017 07:50:00"), DateTime.Parse("09/09/2017 05:20:00"))));

            Console.ReadLine();
        }
Beispiel #3
0
        public void CalculateTotal(IChargeBase charge)
        {
            var calculator = new ChargeCalculator();

            TotalCharge = calculator.CalculateTotalCost(charge);
        }