private double calcultePenaltyAmount(DateTime ActualReturnDate, DateTime ReturnDate) { // if ReturnDate is greater and equal today as per i understand no fine BusinessLogicDBOperations dbOperations = new BusinessLogicDBOperations(); List <GazetteHoliday> holidays = dbOperations.RetriveGazetteHoliday(); if (ReturnDate.Date >= DateTime.Now.Date) { return(0); } else { // how days exceed total days * planty amount which is 5 double lateDays = 0; lateDays = (DateTime.Now.Date - ReturnDate.Date).TotalDays; //while (ReturnDate != DateTime.Now.Date) //{ // if (!(ReturnDate.DayOfWeek == DayOfWeek.Saturday || ReturnDate.DayOfWeek == DayOfWeek.Sunday || Utilities.Utilities.CheckHoliday(ReturnDate, holidays))) // { // lateDays++; // } // ReturnDate = ReturnDate.AddDays(1); //} return(lateDays * 5); } }
/// <summary> /// This function calculates the date after specified number of work/business days /// Friday and Saturday are treated as off days. /// </summary> /// <param name="days">Business days</param> /// <returns>Target Date</returns> public static DateTime getDateAfterSpecifiedBusinessDays(int days) { BusinessLogicDBOperations dbOperations = new BusinessLogicDBOperations(); List <GazetteHoliday> holidays = dbOperations.RetriveGazetteHoliday(); DateTime TargetDate = DateTime.Now; for (int i = 0; i < 15;) { if (!(TargetDate.DayOfWeek == DayOfWeek.Saturday || TargetDate.DayOfWeek == DayOfWeek.Sunday || CheckHoliday(TargetDate, holidays))) { i++; } TargetDate = TargetDate.AddDays(1); } return(TargetDate); }