Example #1
0
        private void TestShiftInstances(WorkSchedule ws, LocalDate instanceReference)
        {
            Rotation rotation = ws.Teams[0].Rotation;

            // shift instances
            LocalDate startDate = instanceReference;
            LocalDate endDate   = instanceReference.PlusDays(rotation.GetDuration().Days);

            long      days = TimePeriod.DeltaDays(instanceReference, endDate) + 1;
            LocalDate day  = startDate;

            for (long i = 0; i < days; i++)
            {
                List <ShiftInstance> instances = ws.GetShiftInstancesForDay(day);

                foreach (ShiftInstance instance in instances)
                {
                    int isBefore = instance.StartDateTime.CompareTo(instance.GetEndTime());
                    Assert.IsTrue(isBefore < 0);
                    Assert.IsTrue(instance.Shift != null);
                    Assert.IsTrue(instance.Team != null);

                    Shift     shift     = instance.Shift;
                    LocalTime startTime = shift.StartTime;
                    LocalTime endTime   = shift.GetEnd();

                    Assert.IsTrue(shift.IsInShift(startTime));
                    Assert.IsTrue(shift.IsInShift(startTime.PlusSeconds(1)));

                    Duration shiftDuration = instance.Shift.Duration;

                    // midnight is special case
                    if (!shiftDuration.Equals(Duration.FromHours(24)))
                    {
                        Assert.IsFalse(shift.IsInShift(startTime.PlusSeconds(-1)));
                    }

                    Assert.IsTrue(shift.IsInShift(endTime));
                    Assert.IsTrue(shift.IsInShift(endTime.PlusSeconds(-1)));

                    if (!shiftDuration.Equals(Duration.FromHours(24)))
                    {
                        Assert.IsFalse(shift.IsInShift(endTime.PlusSeconds(1)));
                    }

                    LocalDateTime ldt = day.At(startTime);
                    Assert.IsTrue(ws.GetShiftInstancesForTime(ldt).Count > 0);

                    ldt = day.At(startTime.PlusSeconds(1));
                    Assert.IsTrue(ws.GetShiftInstancesForTime(ldt).Count > 0);

                    ldt = day.At(startTime.PlusSeconds(-1));

                    foreach (ShiftInstance si in ws.GetShiftInstancesForTime(ldt))
                    {
                        if (!shiftDuration.Equals(Duration.FromHours(24)))
                        {
                            Assert.IsFalse(shift.Name.Equals(si.Shift.Name));
                        }
                    }

                    ldt = day.At(endTime);
                    Assert.IsTrue(ws.GetShiftInstancesForTime(ldt).Count > 0);

                    ldt = day.At(endTime.PlusSeconds(-1));
                    Assert.IsTrue(ws.GetShiftInstancesForTime(ldt).Count > 0);

                    ldt = day.At(endTime.PlusSeconds(1));

                    foreach (ShiftInstance si in ws.GetShiftInstancesForTime(ldt))
                    {
                        if (!shiftDuration.Equals(Duration.FromHours(24)))
                        {
                            Assert.IsFalse(shift.Name.Equals(si.Shift.Name));
                        }
                    }
                }

                day = day.PlusDays(1);
            }
        }