Exemplo n.º 1
0
        private static void Process(Job job, Queue <Day> days)
        {
            while (job.DurationLeft > TimeSpan.Zero)
            {
                var day = days.Peek();
                if (day.WorkTimeLeft == TimeSpan.Zero)
                {
                    days.Dequeue();
                    continue;
                }

                if (day.WorkTimeLeft <= job.DurationLeft)
                {
                    var durationToSave = day.WorkTimeLeft;

                    job.DurationLeft -= day.WorkTimeLeft;
                    job.AddDay(day, durationToSave);
                    days.Dequeue();
                }
                else
                {
                    var durationToSave = job.DurationLeft;

                    var diff = day.WorkTimeLeft - job.DurationLeft;
                    job.DurationLeft = TimeSpan.Zero;
                    day.WorkTimeLeft = diff;
                    job.AddDay(day, durationToSave);
                }
            }
        }