diff --git a/Zetbox.App.Projekte.Common/Calendar/WorkScheduleActions.cs b/Zetbox.App.Projekte.Common/Calendar/WorkScheduleActions.cs index b30fb681ce..ac16706050 100644 --- a/Zetbox.App.Projekte.Common/Calendar/WorkScheduleActions.cs +++ b/Zetbox.App.Projekte.Common/Calendar/WorkScheduleActions.cs @@ -85,15 +85,35 @@ private static decimal Calc(WorkSchedule obj, DateTime from, DateTime until, Cal { WorkScheduleRule foundRule = null; // Find YearlyRule - foundRule = rules.OfType().FirstOrDefault(r => r.AppliesTo(from)); + var yearlyRule = rules.OfType().FirstOrDefault(r => r.AppliesTo(from)); // Find DayOfWeekRule - if (foundRule == null) + var dayOfWeekRule = rules.OfType().FirstOrDefault(r => r.AppliesTo(from)); + + if (yearlyRule == null) + { + foundRule = dayOfWeekRule; + } + else if(dayOfWeekRule != null) + { + // Use the most "free" rule + if (dayOfWeekRule.IsWorkingDay == false || dayOfWeekRule.WorkingHours < yearlyRule.WorkingHours) + { + foundRule = dayOfWeekRule; + } + else + { + // use the more specific rule + foundRule = yearlyRule; + } + } + else { - foundRule = rules.OfType().FirstOrDefault(r => r.AppliesTo(from)); + foundRule = yearlyRule; } - // Find CommonRule + if (foundRule == null) { + // Find CommonRule foundRule = rules.OfType().FirstOrDefault(r => r.AppliesTo(from)); }