public void ShouldNotBeEqual()
        {
            var time1 = new LocalTime(12, 49, 55, 123000001);
            var time2 = new LocalTime(new DateTime(2017, 1, 1, 12, 49, 55, 123));
            var time3 = new LocalTime(new TimeSpan(0, 12, 49, 55, 125));

            time1.Equals(time2).Should().BeFalse();
            time1.Equals(time3).Should().BeFalse();
        }
        public void ShouldNotBeEqualToNull()
        {
            var time  = new LocalTime(12, 49, 55, 123000001);
            var other = (object)null;

            time.Equals(other).Should().BeFalse();
        }
        public void ShouldNotBeEqualToAnotherType()
        {
            var time  = new LocalTime(12, 49, 55, 123000001);
            var other = "some string";

            time.Equals(other).Should().BeFalse();
        }
Exemple #4
0
        public void Test_Equals_False()
        {
            LocalTime localTime1 = new LocalTime(2, 4);
            LocalTime localTime2 = new LocalTime(2, 4, 0, 1);

            Assert.False(localTime1 == localTime2);
            Assert.False(localTime1.Equals(localTime2));
        }
Exemple #5
0
        public void Test_Equals_True()
        {
            LocalTime localTime1 = new LocalTime(2, 4);
            LocalTime localTime2 = new LocalTime(2, 4, 0, 0);

            Assert.True(localTime1 == localTime2);
            Assert.True(localTime1.Equals(localTime2));
        }
Exemple #6
0
 /// <summary>
 /// Obtains an instance defining the yearly rule to create transitions between two offsets.
 /// <para>
 /// Applications should normally obtain an instance from <seealso cref="ZoneRules"/>.
 /// This factory is only intended for use when creating <seealso cref="ZoneRules"/>.
 ///
 /// </para>
 /// </summary>
 /// <param name="month">  the month of the month-day of the first day of the cutover week, not null </param>
 /// <param name="dayOfMonthIndicator">  the day of the month-day of the cutover week, positive if the week is that
 ///  day or later, negative if the week is that day or earlier, counting from the last day of the month,
 ///  from -28 to 31 excluding 0 </param>
 /// <param name="dayOfWeek">  the required day-of-week, null if the month-day should not be changed </param>
 /// <param name="time">  the cutover time in the 'before' offset, not null </param>
 /// <param name="timeEndOfDay">  whether the time is midnight at the end of day </param>
 /// <param name="timeDefnition">  how to interpret the cutover </param>
 /// <param name="standardOffset">  the standard offset in force at the cutover, not null </param>
 /// <param name="offsetBefore">  the offset before the cutover, not null </param>
 /// <param name="offsetAfter">  the offset after the cutover, not null </param>
 /// <returns> the rule, not null </returns>
 /// <exception cref="IllegalArgumentException"> if the day of month indicator is invalid </exception>
 /// <exception cref="IllegalArgumentException"> if the end of day flag is true when the time is not midnight </exception>
 public static ZoneOffsetTransitionRule Of(Month month, int dayOfMonthIndicator, DayOfWeek dayOfWeek, LocalTime time, bool timeEndOfDay, TimeDefinition timeDefnition, ZoneOffset standardOffset, ZoneOffset offsetBefore, ZoneOffset offsetAfter)
 {
     Objects.RequireNonNull(month, "month");
     Objects.RequireNonNull(time, "time");
     Objects.RequireNonNull(timeDefnition, "timeDefnition");
     Objects.RequireNonNull(standardOffset, "standardOffset");
     Objects.RequireNonNull(offsetBefore, "offsetBefore");
     Objects.RequireNonNull(offsetAfter, "offsetAfter");
     if (dayOfMonthIndicator < -28 || dayOfMonthIndicator > 31 || dayOfMonthIndicator == 0)
     {
         throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero");
     }
     if (timeEndOfDay && time.Equals(LocalTime.MIDNIGHT) == false)
     {
         throw new IllegalArgumentException("Time must be midnight when end of day flag is true");
     }
     return(new ZoneOffsetTransitionRule(month, dayOfMonthIndicator, dayOfWeek, time, timeEndOfDay, timeDefnition, standardOffset, offsetBefore, offsetAfter));
 }
        /**
         * <p>Find line for two neighbour nodes</p>
         * @param firstNode is int representation of firts node
         * @param secondNode is int representation of second node
         * @param time is LocalTime representation of time
         * @return int as index of line
         */
        private int findLine(int firstNode, int secondNode, LocalTime time)
        {
            if (data[firstNode, secondNode].isTransfer)
            {
                return(-1);
            }

            int index = 0;

            //loop for timetables at concrete edge
            for (int j = 0; j < data[firstNode, secondNode].times.Length; j++)
            {
                if (time.Equals(data[firstNode, secondNode].times[j]))
                {
                    index = j;
                }
            }

            return(index);
        }
        /**
         * <p>find nearest next time</p>
         * @param startTime is LocalTime representation of start time
         * @param actualNode is int representation of actual node
         * @param i  is int representation of cycle from parent calling method
         * @param timeDepartures is array of time departures between all two nodes in graph
         * @return next nearest LocalTime to start time
         */
        private LocalTime findImmediateTime(LocalTime startTime, int actualNode, int i, LocalTime[,] timeDepartures)
        {
            int       k        = 0;
            LocalTime nextTime = data[actualNode, i].times[k];

            //find in list of departures in day in actualNode nearest actualTIme
            while (startTime.CompareTo(nextTime) > 0 && !(startTime.Equals(nextTime)))
            {
                k++;
                //if occured new day, start at begin in list and time departure will set to 00:00
                if (k >= data[actualNode, i].times.Length)
                {
                    k = 0;
                    //timeDepartures[actualNode][i] = LocalTime.parse("00:00");
                    startTime = parseTime("00:00");
                    newDay    = true;
                }
                nextTime = data[actualNode, i].times[k];
            }

            return(nextTime);
        }
Exemple #9
0
 private void UpdateCheckConflict(LocalTime timeToSet, Period periodToSet)
 {
     if (Time != java.time.temporal.TemporalAccessor_Fields.Null)
     {
         if (Time.Equals(timeToSet) == false)
         {
             throw new DateTimeException("Conflict found: Fields resolved to different times: " + Time + " " + timeToSet);
         }
         if (ExcessDays.Zero == false && periodToSet.Zero == false && ExcessDays.Equals(periodToSet) == false)
         {
             throw new DateTimeException("Conflict found: Fields resolved to different excess periods: " + ExcessDays + " " + periodToSet);
         }
         else
         {
             ExcessDays = periodToSet;
         }
     }
     else
     {
         Time       = timeToSet;
         ExcessDays = periodToSet;
     }
 }
Exemple #10
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);
        }
Exemple #11
0
        public virtual void test_swapIndicies()
        {
            ImmutableMap <string, SwapIndex> mapAll   = SwapIndices.ENUM_LOOKUP.lookupAll();
            ImmutableList <SwapIndex>        indexAll = mapAll.values().asList();
            ImmutableList <string>           nameAll  = mapAll.Keys.asList();
            int size = indexAll.size();

            for (int i = 0; i < size; ++i)
            {
                // check no duplication
                for (int j = i + 1; j < size; ++j)
                {
                    assertFalse(nameAll.get(i).Equals(nameAll.get(j)));
                    assertFalse(indexAll.get(i).Equals(indexAll.get(j)));
                }
            }
            foreach (string name in nameAll)
            {
                SwapIndex index = mapAll.get(name);
                assertEquals(SwapIndex.of(name), index);
                assertEquals(index.Active, true);
                FixedIborSwapTemplate   temp = index.Template;
                FixedIborSwapConvention conv = temp.Convention;
                Tenor     tenor = temp.Tenor;
                LocalTime time  = index.FixingTime;
                ZoneId    zone  = index.FixingZone;
                // test consistency between name and template
                assertTrue(name.Contains(tenor.ToString()));
                if (name.StartsWith("USD", StringComparison.Ordinal))
                {
                    assertTrue(name.Contains("1100") || name.Contains("1500"));
                    assertTrue(conv.Equals(FixedIborSwapConventions.USD_FIXED_6M_LIBOR_3M));
                    assertTrue(zone.Equals(NEY_YORK));
                }
                if (name.StartsWith("GBP", StringComparison.Ordinal))
                {
                    assertTrue(name.Contains("1100"));
                    if (tenor.Equals(Tenor.TENOR_1Y))
                    {
                        assertTrue(conv.Equals(FixedIborSwapConventions.GBP_FIXED_1Y_LIBOR_3M));
                    }
                    else
                    {
                        assertTrue(conv.Equals(FixedIborSwapConventions.GBP_FIXED_6M_LIBOR_6M));
                    }
                    assertTrue(zone.Equals(LONDON));
                }
                if (name.StartsWith("EUR", StringComparison.Ordinal))
                {
                    assertTrue(name.Contains("1100") || name.Contains("1200"));
                    if (tenor.Equals(Tenor.TENOR_1Y))
                    {
                        assertTrue(conv.Equals(FixedIborSwapConventions.EUR_FIXED_1Y_EURIBOR_3M));
                    }
                    else
                    {
                        assertTrue(conv.Equals(FixedIborSwapConventions.EUR_FIXED_1Y_EURIBOR_6M));
                    }
                    assertTrue(zone.Equals(FRANKFURT));
                }
                if (name.Contains("1100"))
                {
                    assertTrue(time.Equals(LocalTime.of(11, 0)));
                }
                if (name.Contains("1200"))
                {
                    assertTrue(time.Equals(LocalTime.of(12, 0)));
                }
                if (name.Contains("1500"))
                {
                    assertTrue(time.Equals(LocalTime.of(15, 0)));
                }
                assertEquals(index.calculateFixingDateTime(date(2015, 6, 30)), date(2015, 6, 30).atTime(time).atZone(zone));
            }
        }