public void CompareTo_SameCalendar()
        {
            LocalDate date1 = new LocalDate(2011, 1, 2);
            LocalDate date2 = new LocalDate(2011, 1, 2);
            LocalDate date3 = new LocalDate(2011, 1, 5);

            Assert.That(date1.CompareTo(date2), Is.EqualTo(0));
            Assert.That(date1.CompareTo(date3), Is.LessThan(0));
            Assert.That(date3.CompareTo(date2), Is.GreaterThan(0));
        }
        public void CompareTo_DifferentCalendars_OnlyLocalInstantMatters()
        {
            CalendarSystem islamic = CalendarSystem.GetIslamicCalendar(IslamicLeapYearPattern.Base15, IslamicEpoch.Astronomical);
            LocalDate      date1   = new LocalDate(2011, 1, 2);
            LocalDate      date2   = new LocalDate(1500, 1, 1, islamic);
            LocalDate      date3   = date1.WithCalendar(islamic);

            Assert.That(date1.CompareTo(date2), Is.LessThan(0));
            Assert.That(date2.CompareTo(date1), Is.GreaterThan(0));
            Assert.That(date1.CompareTo(date3), Is.EqualTo(0));
        }
Пример #3
0
        /// <summary>
        /// Check to see if this day is contained in the non-working period
        /// </summary>
        /// <param name="day">Date to check</param>
        /// <returns>True if in the non-working period</returns>
        public bool IsInPeriod(LocalDate day)
        {
            bool isInPeriod = false;

            LocalDate periodStart = StartDateTime.Date;
            LocalDate periodEnd   = GetEndDateTime().Date;

            if (day.CompareTo(periodStart) >= 0 && day.CompareTo(periodEnd) <= 0)
            {
                isInPeriod = true;
            }

            return(isInPeriod);
        }
Пример #4
0
        /// <summary>
        /// Print shift instances to the console
        /// </summary>
        /// <param name="start">Starting date</param>
        /// <param name="end">Ending date</param>
        public void PrintShiftInstances(LocalDate start, LocalDate end)
        {
            if (start.CompareTo(end) > 0)
            {
                string msg = String.Format(WorkSchedule.GetMessage("end.earlier.than.start"), start, end);
                throw new Exception(msg);
            }

            long days = TimePeriod.DeltaDays(start, end) + 1;

            LocalDate day = start;

            for (long i = 0; i < days; i++)
            {
                Console.WriteLine("[" + (i + 1) + "] " + GetMessage("Shifts.day") + ": " + day);

                List <ShiftInstance> instances = GetShiftInstancesForDay(day);

                if (instances.Count == 0)
                {
                    Console.WriteLine("   " + GetMessage("Shifts.non.working"));
                }
                else
                {
                    int count = 1;
                    foreach (ShiftInstance instance in instances)
                    {
                        Console.WriteLine("   (" + count + ")" + instance);
                        count++;
                    }
                }
                day = day.PlusDays(1);
            }
        }
Пример #5
0
        public void ShouldThrowOnCompareToOtherType()
        {
            var date1 = new LocalDate(1947, 12, 17);

            var ex = Record.Exception(() => date1.CompareTo(new DateTime(1947, 12, 17)));

            ex.Should().NotBeNull().And.BeOfType <ArgumentException>();
        }
Пример #6
0
        public void ShouldReportLargerOnCompareToNull()
        {
            var date1 = new LocalDate(1947, 12, 17);

            var comp = date1.CompareTo(null);

            comp.Should().BeGreaterThan(0);
        }
Пример #7
0
        public void CompareTo()
        {
            LocalDate date1  = new LocalDate(2010, 6, 16);
            LocalDate date2  = new LocalDate(2010, 6, 16);
            int       result = Snippet.For(date1.CompareTo(date2));

            Assert.AreEqual(0, result);
        }
        public void CompareTo_DifferentCalendars_Throws()
        {
            CalendarSystem islamic = CalendarSystem.GetIslamicCalendar(IslamicLeapYearPattern.Base15, IslamicEpoch.Astronomical);
            LocalDate      date1   = new LocalDate(2011, 1, 2);
            LocalDate      date2   = new LocalDate(1500, 1, 1, islamic);

            Assert.Throws <ArgumentException>(() => date1.CompareTo(date2));
            Assert.Throws <ArgumentException>(() => ((IComparable)date1).CompareTo(date2));
        }
Пример #9
0
        public void ShouldReportSmallerOnCompareTo()
        {
            var date1 = new LocalDate(1947, 12, 16);
            var date2 = new LocalDate(1947, 12, 17);

            var comp = date1.CompareTo(date2);

            comp.Should().BeLessThan(0);
        }
Пример #10
0
        public void ShouldReportEqualOnCompareTo()
        {
            var date1 = new LocalDate(1947, 12, 17);
            var date2 = new LocalDate(1947, 12, 17);

            var comp = date1.CompareTo(date2);

            comp.Should().Be(0);
        }
Пример #11
0
        public float ComputeEarningsGrowth(LocalDate today, int minQuarters)
        {
            if (EarningsQuarters.Count == 0)
            {
                return(float.NaN);
            }

            int currQuarter = -1;

            for (int i = 0; i < EarningsQuarters.Count; i++)
            {
                var quarterDate = EarningsQuarters[i];
                if (today.CompareTo(quarterDate) < 0)
                {
                    currQuarter = i;
                }
            }

            if (currQuarter < minQuarters)
            {
                return(float.NaN);
            }

            float prevEps = 0;

            for (int i = currQuarter - minQuarters; i <= currQuarter; i++)
            {
                prevEps += EarningsData[i];
            }
            prevEps = prevEps / (minQuarters - 1);

            float thisEps = EarningsData[currQuarter];

            float growth = (thisEps - prevEps) / prevEps;

            return(growth);
        }
Пример #12
0
        public bool isRecognizableBy(LocalDate asOf)
        {
            LocalDate recognizedOn = getRecognizedOn();

            return(asOf.CompareTo(recognizedOn) > 0 || asOf.Equals(recognizedOn));
        }
Пример #13
0
 public int CompareTo(DateInterval other)
 {
     Ensure.Bool.IsTrue(Period == other.Period);
     return(_start.CompareTo(other._start));
 }
Пример #14
0
        /// <summary>
        /// Calculate the schedule working time between the specified dates and times
        /// </summary>
        /// <param name="from">Starting date and time</param>
        /// <param name="to">Ending date and time</param>
        /// <returns>Duration</returns>
        public Duration CalculateWorkingTime(LocalDateTime from, LocalDateTime to)
        {
            if (from.CompareTo(to) > 0)
            {
                string msg = string.Format(WorkSchedule.GetMessage("end.earlier.than.start"), to, from);
                throw new Exception(msg);
            }

            Duration sum = Duration.Zero;

            LocalDate thisDate = from.Date;
            LocalTime thisTime = from.TimeOfDay;
            LocalDate toDate   = to.Date;
            LocalTime toTime   = to.TimeOfDay;
            int       dayCount = Rotation.GetDayCount();

            // get the working shift from yesterday
            Shift lastShift = null;

            LocalDate     yesterday         = thisDate.PlusDays(-1);
            ShiftInstance yesterdayInstance = GetShiftInstanceForDay(yesterday);

            if (yesterdayInstance != null)
            {
                lastShift = yesterdayInstance.Shift;
            }

            // step through each day until done
            while (thisDate.CompareTo(toDate) < 1)
            {
                if (lastShift != null && lastShift.SpansMidnight())
                {
                    // check for days in the middle of the time period
                    bool lastDay = thisDate.CompareTo(toDate) == 0 ? true : false;

                    if (!lastDay || (lastDay && !toTime.Equals(LocalTime.Midnight)))
                    {
                        // add time after midnight in this day
                        int afterMidnightSecond = TimePeriod.SecondOfDay(lastShift.GetEnd());
                        int fromSecond          = TimePeriod.SecondOfDay(thisTime);

                        if (afterMidnightSecond > fromSecond)
                        {
                            Duration seconds = Duration.FromSeconds(afterMidnightSecond - fromSecond);
                            sum = sum.Plus(seconds);
                        }
                    }
                }

                // today's shift
                ShiftInstance instance = GetShiftInstanceForDay(thisDate);

                Duration duration;

                if (instance != null)
                {
                    lastShift = instance.Shift;
                    // check for last date
                    if (thisDate.CompareTo(toDate) == 0)
                    {
                        duration = lastShift.CalculateWorkingTime(thisTime, toTime, true);
                    }
                    else
                    {
                        duration = lastShift.CalculateWorkingTime(thisTime, LocalTime.MaxValue, true);
                    }
                    sum = sum.Plus(duration);
                }
                else
                {
                    lastShift = null;
                }

                int n = 1;
                if (GetDayInRotation(thisDate) == dayCount)
                {
                    // move ahead by the rotation count if possible
                    LocalDate rotationEndDate = thisDate.PlusDays(dayCount);

                    if (rotationEndDate.CompareTo(toDate) < 0)
                    {
                        n   = dayCount;
                        sum = sum.Plus(Rotation.GetWorkingTime());
                    }
                }

                // move ahead n days starting at midnight
                thisDate = thisDate.PlusDays(n);
                thisTime = LocalTime.Midnight;
            }             // end day loop

            return(sum);
        }
Пример #15
0
 /// <summary>Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. </summary>
 /// <returns>A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes <paramref name="other" /> in the sort order.  Zero This instance occurs in the same position in the sort order as <paramref name="other" />. Greater than zero This instance follows <paramref name="other" /> in the sort order. </returns>
 /// <param name="other">An object to compare with this instance. </param>
 public int CompareTo(BadiDate other) => LocalDate.CompareTo(other.LocalDate);
        public void CompareTo_SameCalendar()
        {
            LocalDate date1 = new LocalDate(2011, 1, 2);
            LocalDate date2 = new LocalDate(2011, 1, 2);
            LocalDate date3 = new LocalDate(2011, 1, 5);

            Assert.That(date1.CompareTo(date2), Is.EqualTo(0));
            Assert.That(date1.CompareTo(date3), Is.LessThan(0));
            Assert.That(date3.CompareTo(date2), Is.GreaterThan(0));
        }
        public void CompareTo_DifferentCalendars_Throws()
        {
            CalendarSystem islamic = CalendarSystem.GetIslamicCalendar(IslamicLeapYearPattern.Base15, IslamicEpoch.Astronomical);
            LocalDate date1 = new LocalDate(2011, 1, 2);
            LocalDate date2 = new LocalDate(1500, 1, 1, islamic);

            Assert.Throws<ArgumentException>(() => date1.CompareTo(date2));
            Assert.Throws<ArgumentException>(() => ((IComparable) date1).CompareTo(date2));
        }
Пример #18
0
 public int CompareTo() => Sample.CompareTo(SampleBeforeEpoch);
Пример #19
0
 public static bool IsBefore(this LocalDate main, LocalDate other)
 {
     return(main.CompareTo(other) < 0);
 }
Пример #20
0
 public static bool IsAfter(this LocalDate main, LocalDate other)
 {
     return(main.CompareTo(other) > 0);
 }