/// <summary> /// 在连续时间段内计算各时段交替收费的总费用 /// </summary> /// <param name="beginning"></param> /// <param name="ending"></param> /// <returns></returns> private decimal CalculateFeeAlteration(DateTime beginning, DateTime ending) { double minDay = 0; double minNight = 0; decimal fee = 0; //交替计算,直到所有时段都计算完 do { minDay = DayTimezone.SliceDuration(beginning, ending, SwitchWhenTimeZoneOverTime); if (minDay > 0) { fee += DayTimezone.CalculateFee(minDay); beginning = beginning.AddMinutes(minDay); } minNight = NightTimezone.SliceDuration(beginning, ending, SwitchWhenTimeZoneOverTime); if (minNight > 0) { fee += NightTimezone.CalculateFee(minNight); beginning = beginning.AddMinutes(minNight); } } while (minDay > 0 || minNight > 0); return fee; }
/// <summary> /// 计算两个时段内的收费费用,不考虑时段的最高收费 /// </summary> /// <param name="beginning"></param> /// <param name="ending"></param> /// <returns></returns> private TariffTwoZoneCharge CalculateTwoZoneChargeFee(DateTime beginning, DateTime ending) { TariffTwoZoneCharge chargeFee = new TariffTwoZoneCharge(beginning, ending); double minDay = 0; double minNight = 0; //交替计算,直到所有时段都计算完 do { minDay = DayTimezone.SliceDuration(beginning, ending, SwitchWhenTimeZoneOverTime); if (minDay > 0) { chargeFee.FirstCharge += DayTimezone.CalculateFeeWithOutLimiteFee(minDay); beginning = beginning.AddMinutes(minDay); } minNight = NightTimezone.SliceDuration(beginning, ending, SwitchWhenTimeZoneOverTime); if (minNight > 0) { chargeFee.SecondCharge += NightTimezone.CalculateFeeWithOutLimiteFee(minNight); beginning = beginning.AddMinutes(minNight); } } while (minDay > 0 || minNight > 0); return chargeFee; }