예제 #1
0
        public int CalculateStayInNumberOfDays_ShouldAdd1ExtraDay_ForEachWholeOrPartDay(string startDateValue, string endDateValue)
        {
            var startDateTime = DateTime.Parse(startDateValue);
            var endDateTime   = DateTime.Parse(endDateValue);

            return(ChargeableTimeCalculator.CalculateStayInNumberOfDays(startDateTime, endDateTime));
        }
        public string CalculatePrice(DateTime startDateTime, DateTime endDateTime)
        {
            // Seperated out method below into static utils method below
            // since it maybe in future that we need to reuse logic for seperate strategy.
            // Caution should be applied when using static class, however
            // I went for it in this small app since the util class is performing a calculation
            // and holds no state. The calculation logic is unlikely to change.
            var days = ChargeableTimeCalculator.CalculateStayInNumberOfDays(startDateTime, endDateTime);

            var timespan = TimeSpan.FromDays(days);

            var cost = (Math.Ceiling(timespan.TotalDays)) * AppConstants.LongStayCharge;

            return(cost.ToString("C", CultureInfo.CurrentCulture));
        }