Esempio n. 1
0
        public void TestPeriod()
        {
            // second of day
            LocalTime t = new LocalTime(0, 0, 0);

            Assert.IsTrue(TimePeriod.SecondOfDay(t) == 0);

            t = LocalTime.Midnight;
            Assert.IsTrue(TimePeriod.SecondOfDay(t) == 0);

            t = LocalTime.Noon;
            Assert.IsTrue(TimePeriod.SecondOfDay(t) == 43200);

            t = new LocalTime(23, 59, 59);
            Assert.IsTrue(TimePeriod.SecondOfDay(t) == 86399);

            t = LocalTime.MaxValue;
            Assert.IsTrue(TimePeriod.SecondOfDay(t) == 86399);

            // delta days
            LocalDate start = new LocalDate(2107, 1, 1);
            LocalDate end   = new LocalDate(2107, 1, 1);

            Assert.IsTrue(TimePeriod.DeltaDays(start, end) == 0);

            for (int i = 0; i < 10; i++)
            {
                LocalDate next = end.PlusDays(i);
                long      n    = TimePeriod.DeltaDays(start, next);
                Assert.IsTrue(n == i);
            }
        }
Esempio n. 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);
            }
        }