public void PeriodAddition_MethodEquivalents()
 {
     LocalTime start = new LocalTime(20, 30);
     Period period = Period.FromHours(3) + Period.FromMinutes(10);
     Assert.AreEqual(start + period, LocalTime.Add(start, period));
     Assert.AreEqual(start + period, start.Plus(period));
 }
Beispiel #2
0
        public ISettableClock LocalNow(LocalTime time)
        {
            _timeZone = time.TimeZone;
            _time = time.UtcTime;

            return this;
        }
 public void CombineWithTime()
 {
     LocalDate date = new LocalDate(2010, 6, 16);
     LocalTime time = new LocalTime(16, 20);
     LocalDateTime dateTime = date + time;
     Assert.AreEqual(new LocalDateTime(2010, 6, 16, 16, 20, 0), dateTime);
 }
Beispiel #4
0
        public void add()
        {
            var time = new LocalTime(DateTime.Today.AddHours(8), TimeZoneInfo.Local);
            var halfHourLater = time.Add("0800".ToTime());

            halfHourLater.Time.ShouldEqual(DateTime.Today.AddHours(16));
        }
 public void PlusHours_CrossingDayBoundary()
 {
     LocalTime start = new LocalTime(12, 15, 8);
     LocalTime expected = new LocalTime(8, 15, 8);
     Assert.AreEqual(expected, start.PlusHours(20));
     Assert.AreEqual(start, start.PlusHours(20).PlusHours(-20));
 }
 public void Subtraction_WithPeriod()
 {
     LocalTime start = new LocalTime(5, 30, 1);
     Period period = Period.FromHours(2) + Period.FromSeconds(1);
     LocalTime expected = new LocalTime(3, 30, 0);
     Assert.AreEqual(expected, start - period);
 }
Beispiel #7
0
 public void CombineWithTime()
 {
     LocalDate date = new LocalDate(2010, 6, 16);
     LocalTime time = new LocalTime(16, 20, 0);
     LocalDateTime dateTime = date + time;
     Assert.AreEqual("ISO: 2010-06-16T16:20:00 LOC", dateTime.ToString());
 }
 public void Subtraction_WrapsAtMidnight()
 {
     LocalTime start = new LocalTime(1, 0, 0);
     Period period = Period.FromHours(3);
     LocalTime expected = new LocalTime(22, 0, 0);
     Assert.AreEqual(expected, start - period);
 }
 public void Subtraction_PeriodWithTime()
 {
     LocalTime time = new LocalTime(20, 30);
     Period period = Period.FromDays(1);
     // Use method not operator here to form a valid statement
     Assert.Throws<ArgumentException>(() => LocalTime.Subtract(time, period));
 }
        public async Task Flights_One_Way()
        {
            var departureDate = Instant.FromDateTimeUtc(DateTime.UtcNow).InUtc().Date.PlusMonths(1);
            var outboundDepartureStartTime = new LocalTime(8, 0, 0);
            var outboundDepartureEndTime = new LocalTime(12, 0, 0);
            const int maxStops = 2;
            const int maxDuration = 14 * 60;

            var itineraries = await Scanner.QueryFlight(new FlightQuerySettings(
                new FlightRequestSettings(
                    Location.FromString("GVA-sky"),
                    Location.FromString("JFK-sky"),
                    departureDate),
                new FlightResponseSettings(
                    sortOrder: SortOrder.Descending,
                    sortType: SortType.Price,
                    maxStops: maxStops,
                    maxDuration: maxDuration,
                    outboundDepartureStartTime: outboundDepartureStartTime,
                    outboundDepartureEndTime: outboundDepartureEndTime)));

            Assert.IsTrue(itineraries.Count > 0);

            foreach (var itinerary in itineraries)
            {
                Assert.IsNull(itinerary.InboundLeg);
            }
        }
 public void PlusMinutes_Simple()
 {
     LocalTime start = new LocalTime(12, 15, 8);
     LocalTime expectedForward = new LocalTime(12, 17, 8);
     LocalTime expectedBackward = new LocalTime(12, 13, 8);
     Assert.AreEqual(expectedForward, start.PlusMinutes(2));
     Assert.AreEqual(expectedBackward, start.PlusMinutes(-2));
 }
 public void PlusSeconds_Simple()
 {
     LocalTime start = new LocalTime(12, 15, 8);
     LocalTime expectedForward = new LocalTime(12, 15, 18);
     LocalTime expectedBackward = new LocalTime(12, 14, 58);
     Assert.AreEqual(expectedForward, start.PlusSeconds(10));
     Assert.AreEqual(expectedBackward, start.PlusSeconds(-10));
 }
 public void PlusMilliseconds_Simple()
 {
     LocalTime start = new LocalTime(12, 15, 8, 300);
     LocalTime expectedForward = new LocalTime(12, 15, 8, 700);
     LocalTime expectedBackward = new LocalTime(12, 15, 7, 900);
     Assert.AreEqual(expectedForward, start.PlusMilliseconds(400));
     Assert.AreEqual(expectedBackward, start.PlusMilliseconds(-400));
 }
 public void PlusTicks_Simple()
 {
     LocalTime start = new LocalTime(12, 15, 8, 300, 7500);
     LocalTime expectedForward = new LocalTime(12, 15, 8, 301, 1500);
     LocalTime expectedBackward = new LocalTime(12, 15, 8, 300, 3500);
     Assert.AreEqual(expectedForward, start.PlusTicks(4000));
     Assert.AreEqual(expectedBackward, start.PlusTicks(-4000));
 }
Beispiel #15
0
        public void greater_than_operator()
        {
            var time1 = new LocalTime(DateTime.Today.AddHours(8), TimeZoneInfo.Local);
            var time2 = new LocalTime(DateTime.Today.AddHours(10), TimeZoneInfo.Local);

            (time1 > time2).ShouldBeFalse();
            (time2 > time1).ShouldBeTrue();
        }
 public void PlusHours_CrossingSeveralDaysBoundary()
 {
     // Christmas day + 10 days and 1 hour
     LocalTime start = new LocalTime(12, 15, 8);
     LocalTime expected = new LocalTime(13, 15, 8);
     Assert.AreEqual(expected, start.PlusHours(241));
     Assert.AreEqual(start, start.PlusHours(241).PlusHours(-241));
 }
Beispiel #17
0
 public Complex(IStorage stroage)
 {
     _Time = new LocalTime();
     _Hall = new Hall();
     _World = new World(LocalTime.Instance);
     _Updater = new Utility.Updater<Utility.IUpdatable>();
     _Storage = stroage;
 }
 public void PlusHours_Simple()
 {
     LocalTime start = new LocalTime(12, 15, 8);
     LocalTime expectedForward = new LocalTime(14, 15, 8);
     LocalTime expectedBackward = new LocalTime(10, 15, 8);
     Assert.AreEqual(expectedForward, start.PlusHours(2));
     Assert.AreEqual(expectedBackward, start.PlusHours(-2));
 }
        public void TimeOfDay_After1970()
        {
            LocalDateTime dateTime = new LocalDateTime(1975, 11, 8, 12, 5, 23);
            LocalTime expected = new LocalTime(12, 5, 23);
            Assert.AreEqual(expected, dateTime.TimeOfDay);

            Assert.AreEqual(new LocalDateTime(1970, 1, 1, 12, 5, 23), dateTime.TimeOfDay.LocalDateTime);
        }
Beispiel #20
0
        public void create_local_time()
        {
            var time = new LocalTime(DateTime.Today.AddHours(8).ToUniversalTime(TimeZoneInfo.Local), TimeZoneInfo.Local);
            time.Time.ShouldEqual(DateTime.Today.AddHours(8));
            time.TimeOfDay.ShouldEqual("0800".ToTime());
            time.Date.ShouldEqual(DateTime.Today.ToDate());

            time.UtcTime.ShouldEqual(DateTime.Today.AddHours(8).ToUniversalTime(TimeZoneInfo.Local));
        }
Beispiel #21
0
 public Complex(IStorage stroage)
 {
     _Time = new LocalTime();
     _Hall = new Hall();
     _World = new World(LocalTime.Instance);
     _Updater = new Utility.Updater();
     _Storage = stroage;
     _TimeCounter = new Utility.TimeCounter();
 }
 public void PlusTicks_Long()
 {
     Assert.IsTrue(NodaConstants.TicksPerDay > int.MaxValue);
     LocalTime start = new LocalTime(12, 15, 8);
     LocalTime expectedForward = new LocalTime(12, 15, 9);
     LocalTime expectedBackward = new LocalTime(12, 15, 7);
     Assert.AreEqual(expectedForward, start.PlusTicks(NodaConstants.TicksPerDay + NodaConstants.TicksPerSecond));
     Assert.AreEqual(expectedBackward, start.PlusTicks(-NodaConstants.TicksPerDay - NodaConstants.TicksPerSecond));
 }
Beispiel #23
0
 public void CombinationWithTime()
 {
     // Test all three approaches in the same test - they're logically equivalent.
     var calendar = CalendarSystem.Julian;
     LocalDate date = new LocalDate(2014, 3, 28, calendar);
     LocalTime time = new LocalTime(20, 17, 30);
     LocalDateTime expected = new LocalDateTime(2014, 3, 28, 20, 17, 30, calendar);
     Assert.AreEqual(expected, date + time);
     Assert.AreEqual(expected, date.At(time));
     Assert.AreEqual(expected, time.On(date));
 }
 public void Should_Calculate_Hour_Minute_Second()
 {
     foreach (var v in Values)
     {
         var time = new LocalTime(v.Item5);
         Assert.AreEqual(v.Item1, time.Hour, "For time: " + v.Item6);
         Assert.AreEqual(v.Item2, time.Minute, "For time: " + v.Item6);
         Assert.AreEqual(v.Item3, time.Second, "For time: " + v.Item6);
         Assert.AreEqual(v.Item4, time.Nanoseconds, "For time: " + v.Item6);
     }
 }
Beispiel #25
0
        public void dehydrate_and_hydrate()
        {
            var time = LocalTime.AtMachineTime("0800");
            var text = time.Hydrate();
            var time2 = new LocalTime(text);

            time2.UtcTime.ShouldEqual(time.UtcTime);

            time2.ShouldNotBeTheSameAs(time);
            time2.ShouldEqual(time);
        }
Beispiel #26
0
 public DepartureTime(string time)
 {
     var regex = new Regex(TimeRegex);
     if (!regex.IsMatch(time))
     {
         throw new ArgumentException("Incorrect format - should be hh:mm");
     }
     
     var hour = int.Parse(time.Split(':')[0]);
     var min = int.Parse(time.Split(':')[1]);
     Time = new LocalTime(hour, min);
 }
 internal LocalTime Add(LocalTime localTime, long value, ref int extraDays)
 {
     unchecked
     {
         if (value == 0)
         {
             return localTime;
         }
         int days = 0;
         // It's possible that there are better ways to do this, but this at least feels simple.
         if (value >= 0)
         {
             if (value >= UnitsPerDay)
             {
                 long longDays = value / UnitsPerDay;
                 // If this overflows, that's fine. (An OverflowException is a reasonable outcome.)
                 days = checked ((int) longDays);
                 value = value % UnitsPerDay;
             }
             long nanosToAdd = value * unitNanoseconds;
             long newNanos = localTime.NanosecondOfDay + nanosToAdd;
             if (newNanos >= NanosecondsPerDay)
             {
                 newNanos -= NanosecondsPerDay;
                 days = checked(days + 1);
             }
             extraDays = checked(extraDays + days);
             return new LocalTime(newNanos);
         }
         else
         {
             if (value <= -UnitsPerDay)
             {
                 long longDays = value / UnitsPerDay;
                 // If this overflows, that's fine. (An OverflowException is a reasonable outcome.)
                 days = checked((int) longDays);
                 value = value % UnitsPerDay;
             }
             long nanosToAdd = value * unitNanoseconds;
             long newNanos = localTime.NanosecondOfDay + nanosToAdd;
             if (newNanos < 0)
             {
                 newNanos += NanosecondsPerDay;
                 days = checked(days - 1);
             }
             extraDays = checked(days + extraDays);
             return new LocalTime(newNanos);
         }
     }
 }
Beispiel #28
0
        public LocalTime SyncWith(TimeServer ts)
        {
            var localTime = new LocalTime();

              if (IsDirty) {
            TimeEntry te = ts.GetTime();
            te.Apply(_culture);
            localTime = te.ToLocalTime();
              } else {
            TimeEntry te = new TimeEntry(localTime);
            te.EnsureImplant(_culture, _implant);
            localTime = te.ToLocalTime();
              }

              return localTime;
        }
        /// <summary>
        /// Initializes a new instance of the FlightResponseSettings with the specified parameters
        /// </summary>
        /// <param name="sortType">The property to sort on</param>
        /// <param name="sortOrder">Sort direction</param>
        /// <param name="maxStops">Filter for maximum number of stops. Between 0 and 3</param>
        /// <param name="maxDuration">Filter for maximum duration in minutes</param>
        /// <param name="outboundDepartureTime">Filter for outbound departure time by time period of the day </param>
        /// <param name="outboundDepartureStartTime">Filter for start of range for outbound departure time</param>
        /// <param name="outboundDepartureEndTime">Filter for end of range for outbound departure time</param>
        /// <param name="inboundDepartureTime">Filter for inbound departure time by time period of the day </param>
        /// <param name="inboundDepartureStartTime">Filter for start of range for inbound departure time</param>
        /// <param name="inboundDepartureEndTime">Filter for end of range for inbound departure time</param>
        /// <param name="originAirports">Origin airports to filter on. List of airport codes</param>
        /// <param name="destinationAirports">Destination airports to filter on. List of airport codes</param>
        /// <param name="includeCarriers">Filter flights by the specified carriers. Must be Iata carrier codes</param>
        /// <param name="excludeCarriers">Filter flights by any but the specified carriers. Must be Iata carrier codes</param>
        /// <param name="carrierSchema">The code schema to use for carriers</param>
        /// <param name="locationSchema">The code schema used for locations</param>
        public FlightResponseSettings(
            SortType sortType = SortType.Price, SortOrder sortOrder = SortOrder.Ascending,
            int? maxStops = null, int? maxDuration = null,
            DayTimePeriod? outboundDepartureTime = null, LocalTime? outboundDepartureStartTime = null,
            LocalTime? outboundDepartureEndTime = null,
            DayTimePeriod? inboundDepartureTime = null, LocalTime? inboundDepartureStartTime = null,
            LocalTime? inboundDepartureEndTime = null,
            IEnumerable<string> originAirports = null, IEnumerable<string> destinationAirports = null,
            IEnumerable<string> includeCarriers = null, IEnumerable<string> excludeCarriers = null,
            CarrierSchema carrierSchema = CarrierSchema.Iata, LocationSchema locationSchema = LocationSchema.Iata)
        {
            if (maxStops.HasValue && (maxStops.Value < 0 || maxStops.Value > 3))
            {
                throw new ArgumentException("The filter for maximum number of stops must be between 0 and 3", nameof(maxStops));
            }

            if (maxDuration.HasValue && (maxDuration.Value < 0 || maxDuration.Value > 1800))
            {
                throw new ArgumentException("The filter for maximum duration must be between 0 and 1800", nameof(maxDuration));
            }

            MaxDuration = maxDuration;
            MaxStops = maxStops;

            SortOrder = sortOrder;
            SortType = sortType;

            CarrierSchema = carrierSchema;
            LocationSchema = locationSchema;

            OriginAirports = originAirports;
            DestinationAirports = destinationAirports;
            IncludeCarriers = includeCarriers;
            ExcludeCarriers = excludeCarriers;

            OutboundDepartureTime = outboundDepartureTime;
            OutboundDepartureStartTime = outboundDepartureStartTime;
            OutboundDepartureEndTime = outboundDepartureEndTime;

            InboundDepartureTime = inboundDepartureTime;
            InboundDepartureStartTime = inboundDepartureStartTime;
            InboundDepartureEndTime = inboundDepartureEndTime;
        }
 internal LocalTime Add(LocalTime localTime, long value)
 {
     unchecked
     {
         // Arithmetic with a LocalTime wraps round, and every unit divides exactly
         // into a day, so we can make sure we add a value which is less than a day.
         if (value >= 0)
         {
             if (value >= UnitsPerDay)
             {
                 value = value % UnitsPerDay;
             }
             long nanosToAdd = value * unitNanoseconds;
             long newNanos = localTime.NanosecondOfDay + nanosToAdd;
             if (newNanos >= NanosecondsPerDay)
             {
                 newNanos -= NanosecondsPerDay;
             }
             return new LocalTime(newNanos);
         }
         else
         {
             if (value <= -UnitsPerDay)
             {
                 value = value % UnitsPerDay;
             }
             long nanosToAdd = value * unitNanoseconds;
             long newNanos = localTime.NanosecondOfDay + nanosToAdd;
             if (newNanos < 0)
             {
                 newNanos += NanosecondsPerDay;
             }
             return new LocalTime(newNanos);
         }
     }
 }
Beispiel #31
0
 public static DateTime addDateAndTime(LocalDate date, LocalTime time)
 {
     return(new DateTime(date.Year, date.Month, date.Day, time.Hour, time.Minute, time.Second));
 }
Beispiel #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ZoneYearOffset"/> class.
 /// </summary>
 /// <param name="mode">The transition mode.</param>
 /// <param name="monthOfYear">The month year offset.</param>
 /// <param name="dayOfMonth">The day of month. Negatives count from end of month.</param>
 /// <param name="dayOfWeek">The day of week. 0 means not set.</param>
 /// <param name="advance">if set to <c>true</c> [advance].</param>
 /// <param name="timeOfDay">The tick within the day.</param>
 internal ZoneYearOffset(TransitionMode mode, int monthOfYear, int dayOfMonth, int dayOfWeek, bool advance, LocalTime timeOfDay)
     : this(mode, monthOfYear, dayOfMonth, dayOfWeek, advance, timeOfDay, false)
 {
 }
Beispiel #33
0
        public void TestExceptions()
        {
            schedule = new WorkSchedule("Exceptions", "Test exceptions");
            Duration  shiftDuration = Duration.FromHours(24);
            LocalTime shiftStart    = new LocalTime(7, 0, 0);

            NonWorkingPeriod period = schedule.CreateNonWorkingPeriod("Non-working", "Non-working period",
                                                                      new LocalDateTime(2017, 1, 1, 0, 0, 0), Duration.FromHours(24));

            try
            {
                period.Duration = Duration.FromSeconds(0);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                // same period
                schedule.CreateNonWorkingPeriod("Non-working", "Non-working period", new LocalDateTime(2017, 1, 1, 0, 0, 0),
                                                Duration.FromHours(24));
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            // shift
            Shift shift = schedule.CreateShift("Test", "Test shift", shiftStart, shiftDuration);

            try
            {
                // crosses midnight
                shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(1)), shift.GetEnd().PlusHours(1));
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                shift.Duration = Duration.FromSeconds(0);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                shift.Duration = Duration.FromSeconds(48 * 3600);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                // same shift
                shift = schedule.CreateShift("Test", "Test shift", shiftStart, shiftDuration);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            Rotation rotation = new Rotation("Rotation", "Rotation");

            rotation.AddSegment(shift, 5, 2);

            LocalDate startRotation = new LocalDate(2016, 12, 31);
            Team      team          = schedule.CreateTeam("Team", "Team", rotation, startRotation);

            // ok
            schedule.CalculateWorkingTime(new LocalDateTime(2017, 1, 1, 7, 0, 0), new LocalDateTime(2017, 2, 1, 0, 0, 0));

            try
            {
                // end before start
                schedule.CalculateWorkingTime(new LocalDateTime(2017, 1, 2, 0, 0, 0), new LocalDateTime(2017, 1, 1, 0, 0, 0));
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                // same team
                team = schedule.CreateTeam("Team", "Team", rotation, startRotation);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                // date before start
                team.GetDayInRotation(new LocalDate(2016, 1, 1));
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                // end before start
                schedule.PrintShiftInstances(new LocalDate(2017, 1, 2), new LocalDate(2017, 1, 1));
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                // delete in-use shift
                schedule.DeleteShift(shift);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            // breaks
            Break lunch = shift.CreateBreak("Lunch", "Lunch", new LocalTime(12, 0, 0), Duration.FromMinutes(60));

            lunch.Duration  = Duration.FromMinutes(30);
            lunch.StartTime = new LocalTime(11, 30, 0);
            shift.RemoveBreak(lunch);
            shift.RemoveBreak(lunch);

            Shift shift2 = schedule.CreateShift("Test2", "Test shift2", shiftStart, shiftDuration);

            Assert.IsFalse(shift.Equals(shift2));

            Break lunch2 = shift2.CreateBreak("Lunch2", "Lunch", new LocalTime(12, 0, 0), Duration.FromMinutes(60));

            shift.RemoveBreak(lunch2);

            // ok to delete
            WorkSchedule schedule2 = new WorkSchedule("Exceptions2", "Test exceptions2");

            schedule2.Name        = "Schedule 2";
            schedule2.Description = "a description";

            schedule2.DeleteShift(shift);
            schedule2.DeleteTeam(team);
            schedule2.DeleteNonWorkingPeriod(period);

            // nulls
            try
            {
                schedule.CreateShift(null, "1", shiftStart, Duration.FromMinutes(60));
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            Assert.IsFalse(shift.Equals(rotation));

            // hashcode()
            team.GetHashCode();
            String name = team.Name;
            Dictionary <String, Team> teams = new Dictionary <String, Team>();

            teams[name] = team;
            Team t = teams[name];
        }
Beispiel #34
0
 public Occurance(LocalDate date, LocalTime time)
 {
     this.SetLocalTime(time);
     this.SetLocalDate(date);
 }
 internal LocalDateTimePatternParser(LocalDateTime templateValue)
 {
     templateValueDate = templateValue.Date;
     templateValueTime = templateValue.TimeOfDay;
 }
Beispiel #36
0
 /// <summary>
 /// A date time adjuster to move to the next specified time, but return the original date time if the time is already correct.
 /// </summary>
 /// <param name="time">The time to adjust date times to.</param>
 /// <returns>An adjuster which advances a date time to the next occurrence of the
 /// specified time, or the original date time if the time is already correct.</returns>
 public static Func <LocalDateTime, LocalDateTime> NextOrSame(LocalTime time) => dateTime => dateTime.TimeOfDay == time ? dateTime : NextTime(dateTime, time);
Beispiel #37
0
 public static TimeRange Create(LocalTime startTime, LocalTime endTime)
 {
     return(new TimeRange(startTime, endTime));
 }
Beispiel #38
0
        /// <summary>Parse string using the specified value type and return the resulting variant.</summary>
        public static Variant Parse <T>(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                // Empty value
                return(new Variant());
            }
            else
            {
                // Switch on type of default value
                switch (default(T))
                {
                case string stringValue:
                    return(new Variant(value));

                case double doubleValue:
                    double doubleResult = double.Parse(value);
                    return(new Variant(doubleResult));

                case bool boolValue:
                    bool boolResult = bool.Parse(value);
                    return(new Variant(boolResult));

                case int intValue:
                    int intResult = int.Parse(value);
                    return(new Variant(intResult));

                case long longValue:
                    long longResult = long.Parse(value);
                    return(new Variant(longResult));

                case LocalDate dateValue:
                    LocalDate dateResult = LocalDateUtil.Parse(value);
                    return(new Variant(dateResult));

                case LocalTime timeValue:
                    LocalTime timeResult = LocalTimeUtil.Parse(value);
                    return(new Variant(timeResult));

                case LocalMinute minuteValue:
                    LocalMinute minuteResult = LocalMinuteUtil.Parse(value);
                    return(new Variant(minuteResult));

                case LocalDateTime dateTimeValue:
                    LocalDateTime dateTimeResult = LocalDateTimeUtil.Parse(value);
                    return(new Variant(dateTimeResult));

                case Instant instantValue:
                    Instant instantResult = InstantUtil.Parse(value);
                    return(new Variant(instantResult));

                case Enum enumValue:
                    object enumResult = Enum.Parse(typeof(T), value);
                    return(new Variant(enumResult));

                default:
                    // Error message if any other type
                    throw new Exception(GetWrongTypeErrorMessage(default(T)));
                }
            }
        }
Beispiel #39
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ZoneYearOffset"/> class.
        /// </summary>
        /// <param name="mode">The transition mode.</param>
        /// <param name="monthOfYear">The month year offset.</param>
        /// <param name="dayOfMonth">The day of month. Negatives count from end of month.</param>
        /// <param name="dayOfWeek">The day of week. 0 means not set.</param>
        /// <param name="advance">if set to <c>true</c> [advance].</param>
        /// <param name="timeOfDay">The time of day at which the transition occurs.</param>
        /// <param name="addDay">Whether to add an extra day (for 24:00 handling).</param>
        internal ZoneYearOffset(TransitionMode mode, int monthOfYear, int dayOfMonth, int dayOfWeek, bool advance, LocalTime timeOfDay, bool addDay)
        {
            VerifyFieldValue(1, 12, "monthOfYear", monthOfYear, false);
            VerifyFieldValue(1, 31, "dayOfMonth", dayOfMonth, true);
            if (dayOfWeek != 0)
            {
                VerifyFieldValue(1, 7, "dayOfWeek", dayOfWeek, false);
            }

            this.Mode             = mode;
            this.monthOfYear      = monthOfYear;
            this.dayOfMonth       = dayOfMonth;
            this.dayOfWeek        = dayOfWeek;
            this.AdvanceDayOfWeek = advance;
            this.TimeOfDay        = timeOfDay;
            this.addDay           = addDay;
        }
Beispiel #40
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void writeLocalTime(java.time.LocalTime localTime) throws RuntimeException
        public override void WriteLocalTime(LocalTime localTime)
        {
            Buffer.Add(LocalTimeValue.LocalTime(localTime));
        }
 public static void WriteLocalTime(this BinaryWriter writer, LocalTime localTime) =>
 writer.Write(localTime.NanosecondOfDay);
 public LocalTime Test(LocalTime arg)
 {
     return(arg + Period.FromMinutes(10));
 }
 private Swaption(LongShort longShort, SwaptionSettlement swaptionSettlement, AdjustableDate expiryDate, LocalTime expiryTime, ZoneId expiryZone, Swap underlying)
 {
     JodaBeanUtils.notNull(longShort, "longShort");
     JodaBeanUtils.notNull(swaptionSettlement, "swaptionSettlement");
     JodaBeanUtils.notNull(expiryDate, "expiryDate");
     JodaBeanUtils.notNull(expiryTime, "expiryTime");
     JodaBeanUtils.notNull(expiryZone, "expiryZone");
     JodaBeanUtils.notNull(underlying, "underlying");
     this.longShort          = longShort;
     this.swaptionSettlement = swaptionSettlement;
     this.expiryDate         = expiryDate;
     this.expiryTime         = expiryTime;
     this.expiryZone         = expiryZone;
     this.underlying         = underlying;
     validate();
 }
Beispiel #44
0
 /// <summary>
 /// A date time adjuster to move to the previous specified time, but return the original date time if the time is already correct.
 /// </summary>
 /// <param name="time">The time to adjust date times to.</param>
 /// <returns>An adjuster which advances a date time to the previous occurrence of the
 /// specified time, or the original date time if the time is already correct.</returns>
 public static Func <LocalDateTime, LocalDateTime> PreviousOrSame(LocalTime time) => dateTime => dateTime.TimeOfDay == time ? dateTime : PreviousTime(dateTime, time);
Beispiel #45
0
        public void DefaultConstructor()
        {
            var actual = new LocalTime();

            Assert.AreEqual(LocalTime.Midnight, actual);
        }
Beispiel #46
0
 // Adjust from 1 microsecond to 100ns. Time zone (in seconds) is inverted.
 public override OffsetTime Read(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription = null)
 => new OffsetTime(
     LocalTime.FromTicksSinceMidnight(buf.ReadInt64() * 10),
     Offset.FromSeconds(-buf.ReadInt32()));
Beispiel #47
0
 /// <summary>
 /// A date time adjuster to move to the next specified time, adding a day if the time is already correct.
 /// </summary>
 /// <param name="time">The time to adjust date times to.</param>
 /// <returns>An adjuster which advances a date time to the next occurrence of the specified time.</returns>
 public static Func <LocalDateTime, LocalDateTime> Next(LocalTime time) => dateTime => NextTime(dateTime, time);
 /// <summary>
 /// Sets the expiry time of the option.
 /// <para>
 /// The expiry time is related to the expiry date and time-zone.
 /// </para>
 /// </summary>
 /// <param name="expiryTime">  the new value, not null </param>
 /// <returns> this, for chaining, not null </returns>
 public Builder expiryTime(LocalTime expiryTime)
 {
     JodaBeanUtils.notNull(expiryTime, "expiryTime");
     this.expiryTime_Renamed = expiryTime;
     return(this);
 }
Beispiel #49
0
 public TimeRange(LocalTime startTime, LocalTime endTime)
 {
     StartTime = startTime;
     EndTime   = endTime;
 }
Beispiel #50
0
 public void BinarySerialization()
 {
     TestHelper.AssertBinaryRoundtrip(LocalTime.FromHourMinuteSecondNanosecond(12, 34, 56, 123456789));
 }
Beispiel #51
0
 public LocalTime ConstructionToTick() => LocalTime.FromHourMinuteSecondMillisecondTick(15, 10, 25, 500, 1234);
 internal LocalDateTimeParseBucket(LocalDate templateValueDate, LocalTime templateValueTime)
 {
     Date = new LocalDatePatternParser.LocalDateParseBucket(templateValueDate);
     Time = new LocalTimePatternParser.LocalTimeParseBucket(templateValueTime);
 }
 public PrimaryCareProfileHoursOfOperation(LocalTime workingDayInHoursStartTime,
                                           LocalTime workingDayInHoursShoulderEndTime,
                                           LocalTime workingDayInHoursEndTime)
     : base(workingDayInHoursStartTime, workingDayInHoursShoulderEndTime, workingDayInHoursEndTime)
 {
 }
Beispiel #54
0
        public void TestGenericShift()
        {
            // regular work week with holidays and breaks
            schedule = new WorkSchedule("Regular 40 hour work week", "9 to 5");

            // holidays
            NonWorkingPeriod memorialDay = schedule.CreateNonWorkingPeriod("MEMORIAL DAY", "Memorial day", new LocalDateTime(2016, 5, 30, 0, 0, 0),
                                                                           Duration.FromHours(24));

            schedule.CreateNonWorkingPeriod("INDEPENDENCE DAY", "Independence day", new LocalDateTime(2016, 7, 4, 0, 0, 0),
                                            Duration.FromHours(24));
            schedule.CreateNonWorkingPeriod("LABOR DAY", "Labor day", new LocalDateTime(2016, 9, 5, 0, 0, 0),
                                            Duration.FromHours(24));
            schedule.CreateNonWorkingPeriod("THANKSGIVING", "Thanksgiving day and day after",
                                            new LocalDateTime(2016, 11, 24, 0, 0, 0), Duration.FromHours(48));
            schedule.CreateNonWorkingPeriod("CHRISTMAS SHUTDOWN", "Christmas week scheduled maintenance",
                                            new LocalDateTime(2016, 12, 25, 0, 30, 0), Duration.FromHours(168));

            // each shift duration
            Duration  shiftDuration = Duration.FromHours(8);
            LocalTime shift1Start   = new LocalTime(7, 0, 0);
            LocalTime shift2Start   = new LocalTime(15, 0, 0);

            // shift 1
            Shift shift1 = schedule.CreateShift("Shift1", "Shift #1", shift1Start, shiftDuration);

            // breaks
            shift1.CreateBreak("10AM", "10 am break", new LocalTime(10, 0, 0), Duration.FromMinutes(15));
            shift1.CreateBreak("LUNCH", "lunch", new LocalTime(12, 0, 0), Duration.FromHours(1));
            shift1.CreateBreak("2PM", "2 pm break", new LocalTime(14, 0, 0), Duration.FromMinutes(15));

            // shift 2
            Shift shift2 = schedule.CreateShift("Shift2", "Shift #2", shift2Start, shiftDuration);

            // shift 1, 5 days ON, 2 OFF
            Rotation rotation1 = new Rotation("Shift1", "Shift1");

            rotation1.AddSegment(shift1, 5, 2);

            // shift 2, 5 days ON, 2 OFF
            Rotation rotation2 = new Rotation("Shift2", "Shift2");

            rotation2.AddSegment(shift2, 5, 2);

            LocalDate startRotation = new LocalDate(2016, 1, 1);
            Team      team1         = schedule.CreateTeam("Team1", "Team #1", rotation1, startRotation);
            Team      team2         = schedule.CreateTeam("Team2", "Team #2", rotation2, startRotation);

            // same day
            LocalDateTime from = startRotation.PlusDays(7).At(shift1Start);
            LocalDateTime to;

            Duration totalWorking = Duration.Zero;

            // 21 days, team1
            Duration d = Duration.Zero;

            for (int i = 0; i < 21; i++)
            {
                to           = from.PlusDays(i);
                totalWorking = team1.CalculateWorkingTime(from, to);
                int dir = team1.GetDayInRotation(to.Date);

                Assert.IsTrue(totalWorking.Equals(d));

                TimePeriod period = rotation1.GetPeriods()[dir - 1];
                if (period is Shift)
                {
                    d = d.Plus(shiftDuration);
                }
            }
            Duration totalSchedule = totalWorking;

            // 21 days, team2
            from = startRotation.PlusDays(7).At(shift2Start);
            d    = Duration.Zero;

            for (int i = 0; i < 21; i++)
            {
                to           = from.PlusDays(i);
                totalWorking = team2.CalculateWorkingTime(from, to);
                int dir = team2.GetDayInRotation(to.Date);

                Assert.IsTrue(totalWorking.Equals(d));

                if (rotation1.GetPeriods()[dir - 1] is Shift)
                {
                    d = d.Plus(shiftDuration);
                }
            }
            totalSchedule = totalSchedule.Plus(totalWorking);

            Duration scheduleDuration   = schedule.CalculateWorkingTime(from, from.PlusDays(21));
            Duration nonWorkingDuration = schedule.CalculateNonWorkingTime(from, from.PlusDays(21));

            Assert.IsTrue(scheduleDuration.Plus(nonWorkingDuration).Equals(totalSchedule));

            // breaks
            Duration allBreaks = Duration.FromMinutes(90);

            Assert.IsTrue(shift1.CalculateBreakTime().Equals(allBreaks));

            // misc
            WorkSchedule schedule2 = new WorkSchedule();

            Shift shift3 = new Shift();

            shift3.Name = "Shift3";
            Assert.IsTrue(shift3.WorkSchedule == null);
            Assert.IsTrue(shift3.CompareTo(shift3) == 0);

            Team team3 = new Team();

            Assert.IsTrue(team3.WorkSchedule == null);

            RotationSegment segment = new RotationSegment();

            segment.Sequence      = 1;
            segment.StartingShift = shift2;
            segment.DaysOn        = 5;
            segment.DaysOff       = 2;
            Assert.IsTrue(segment.Rotation == null);

            Rotation rotation3 = new Rotation();

            rotation3.Name = "Rotation3";
            Assert.IsTrue(rotation3.CompareTo(rotation3) == 0);
            Assert.IsTrue(rotation3.RotationSegments.Count == 0);

            NonWorkingPeriod nwp = new NonWorkingPeriod();

            Assert.IsTrue(nwp.WorkSchedule == null);


            Assert.IsTrue(team1.WorkSchedule.Equals(schedule));


            Assert.IsTrue(!team1.IsDayOff(startRotation));


            Assert.IsTrue(team1.CompareTo(team1) == 0);
            team3.Rotation = rotation1;


            Assert.IsTrue(!memorialDay.IsInPeriod(new LocalDate(2016, 1, 1)));

            runBaseTest(schedule, Duration.FromHours(40), Duration.FromDays(7), new LocalDate(2016, 1, 1));
        }
 private IborFutureOptionSecurity(SecurityInfo info, Currency currency, PutCall putCall, double strikePrice, LocalDate expiryDate, LocalTime expiryTime, ZoneId expiryZone, FutureOptionPremiumStyle premiumStyle, Rounding rounding, SecurityId underlyingFutureId)
 {
     JodaBeanUtils.notNull(info, "info");
     JodaBeanUtils.notNull(currency, "currency");
     JodaBeanUtils.notNull(expiryDate, "expiryDate");
     JodaBeanUtils.notNull(expiryTime, "expiryTime");
     JodaBeanUtils.notNull(expiryZone, "expiryZone");
     JodaBeanUtils.notNull(premiumStyle, "premiumStyle");
     JodaBeanUtils.notNull(rounding, "rounding");
     JodaBeanUtils.notNull(underlyingFutureId, "underlyingFutureId");
     this.info               = info;
     this.currency           = currency;
     this.putCall            = putCall;
     this.strikePrice        = strikePrice;
     this.expiryDate         = expiryDate;
     this.expiryTime         = expiryTime;
     this.expiryZone         = expiryZone;
     this.premiumStyle       = premiumStyle;
     this.rounding           = rounding;
     this.underlyingFutureId = underlyingFutureId;
     validate();
 }
Beispiel #56
0
        public void XmlSerialization()
        {
            var value = LocalTime.FromHourMinuteSecondNanosecond(17, 53, 23, 123456789);

            TestHelper.AssertXmlRoundtrip(value, "<value>17:53:23.123456789</value>");
        }
        /// <summary>
        ///   Parses the date time of year.
        /// </summary>
        /// <param name="tokens">The tokens to parse.</param>
        /// <param name="forRule">True if this is for a Rule line, in which case ON/AT are mandatory;
        /// false for a Zone line, in which case it's part of "until" and they're optional</param>
        /// <returns>The DateTimeOfYear object.</returns>
        /// <remarks>
        ///   IN ON AT
        /// </remarks>
        internal ZoneYearOffset ParseDateTimeOfYear(Tokens tokens, bool forRule)
        {
            var mode      = ZoneYearOffset.StartOfYear.Mode;
            var timeOfDay = ZoneYearOffset.StartOfYear.TimeOfDay;

            int monthOfYear = NextMonth(tokens, "MonthOfYear");

            int  dayOfMonth       = 1;
            int  dayOfWeek        = 0;
            bool advanceDayOfWeek = false;
            bool addDay           = false;

            if (tokens.HasNextToken || forRule)
            {
                var on = NextString(tokens, "On");
                if (on.StartsWith("last", StringComparison.Ordinal))
                {
                    dayOfMonth = -1;
                    dayOfWeek  = ParseDayOfWeek(on.Substring(4));
                }
                else
                {
                    int index = on.IndexOf(">=", StringComparison.Ordinal);
                    if (index > 0)
                    {
                        dayOfMonth       = Int32.Parse(on.Substring(index + 2), CultureInfo.InvariantCulture);
                        dayOfWeek        = ParseDayOfWeek(on.Substring(0, index));
                        advanceDayOfWeek = true;
                    }
                    else
                    {
                        index = on.IndexOf("<=", StringComparison.Ordinal);
                        if (index > 0)
                        {
                            dayOfMonth = Int32.Parse(on.Substring(index + 2), CultureInfo.InvariantCulture);
                            dayOfWeek  = ParseDayOfWeek(on.Substring(0, index));
                        }
                        else
                        {
                            try
                            {
                                dayOfMonth = Int32.Parse(on, CultureInfo.InvariantCulture);
                                dayOfWeek  = 0;
                            }
                            catch (FormatException e)
                            {
                                throw new ArgumentException("Unparsable ON token: " + on, e);
                            }
                        }
                    }
                }

                if (tokens.HasNextToken || forRule)
                {
                    var atTime = NextString(tokens, "AT");
                    if (!string.IsNullOrEmpty(atTime))
                    {
                        if (Char.IsLetter(atTime[atTime.Length - 1]))
                        {
                            char zoneCharacter = atTime[atTime.Length - 1];
                            mode   = ZoneYearOffset.NormalizeModeCharacter(zoneCharacter);
                            atTime = atTime.Substring(0, atTime.Length - 1);
                        }
                        if (atTime == "24:00")
                        {
                            timeOfDay = LocalTime.Midnight;
                            addDay    = true;
                        }
                        else
                        {
                            // We happen to parse the time as if it's an offset...
                            Offset tickOfDay = ParserHelper.ParseOffset(atTime);
                            timeOfDay = new LocalTime(tickOfDay.Ticks);
                        }
                    }
                }
            }
            return(new ZoneYearOffset(mode, monthOfYear, dayOfMonth, dayOfWeek, advanceDayOfWeek, timeOfDay, addDay));
        }
Beispiel #58
0
        public static bool DoTheyTimeCollide(LocalTime StartTime1, LocalTime FinishTime1, LocalTime StartTime2, LocalTime FinishTime2)
        {
            //if we can not consider their bounderies
            if ((CompareTime(FinishTime1, StartTime2) == 0 && CompareTime(StartTime1, FinishTime2) < 0)
                ||
                (CompareTime(FinishTime2, StartTime1) == 0 && CompareTime(StartTime2, FinishTime1) < 0)
                )
            {
                return(false);
            }

            if (CompareTime(FinishTime1, StartTime2) < 0 || CompareTime(StartTime1, FinishTime2) > 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #59
0
        public void ShouldCreateTimeWithTimeComponents()
        {
            var cypherTime = new LocalTime(13, 15, 59);

            cypherTime.ToTimeSpan().Should().Be(new TimeSpan(13, 15, 59));
        }
Beispiel #60
0
 /// <summary>
 /// A date time adjuster to move to the previous specified time, subtracting a day if the time is already correct.
 /// </summary>
 /// <param name="time">The time to adjust date times to.</param>
 /// <returns>An adjuster which advances a date time to the previous occurrence of the specified time.</returns>
 public static Func <LocalDateTime, LocalDateTime> Previous(LocalTime time) => dateTime => PreviousTime(dateTime, time);