Example #1
0
        public void TestFirefighterShifts1()
        {
            // Kern Co, CA
            schedule = new WorkSchedule("Kern Co.", "Three 24 hour alternating shifts");

            // shift, start 07:00 for 24 hours
            Shift shift = schedule.CreateShift("24 Hour", "24 hour shift", new LocalTime(7, 0, 0), Duration.FromHours(24));

            // 2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF
            Rotation rotation = new Rotation("24 Hour", "2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF");

            rotation.AddSegment(shift, 2, 2);
            rotation.AddSegment(shift, 2, 2);
            rotation.AddSegment(shift, 2, 8);

            Team platoon1 = schedule.CreateTeam("Red", "A Shift", rotation, new LocalDate(2017, 1, 8));
            Team platoon2 = schedule.CreateTeam("Black", "B Shift", rotation, new LocalDate(2017, 2, 1));
            Team platoon3 = schedule.CreateTeam("Green", "C Shift", rotation, new LocalDate(2017, 1, 2));

            List <ShiftInstance> instances = schedule.GetShiftInstancesForDay(new LocalDate(2017, 3, 1));

            Assert.IsTrue(instances.Count == 1);
            Assert.IsTrue(instances[0].Team.Equals(platoon3));

            instances = schedule.GetShiftInstancesForDay(new LocalDate(2017, 3, 3));
            Assert.IsTrue(instances.Count == 1);
            Assert.IsTrue(instances[0].Team.Equals(platoon1));

            instances = schedule.GetShiftInstancesForDay(new LocalDate(2017, 3, 9));
            Assert.IsTrue(instances.Count == 1);
            Assert.IsTrue(instances[0].Team.Equals(platoon2));

            runBaseTest(schedule, Duration.FromHours(144), Duration.FromDays(18), new LocalDate(2017, 2, 1));
        }
Example #2
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);
            }
        }