Esempio n. 1
0
        public bool Satisfied(Meeting item)
        {
            if (item.Time.Start == null || item.Time.End == null)
            {
                return(false);
            }

            NodaTime.LocalTime startTime  = item.Time.Start ?? default(NodaTime.LocalTime);
            NodaTime.LocalTime endTime    = item.Time.End ?? default(NodaTime.LocalTime);
            NodaTime.LocalTime _startTime = _time.Start ?? default(NodaTime.LocalTime);
            NodaTime.LocalTime _endTime   = _time.End ?? default(NodaTime.LocalTime);

            NodaTime.Period start = NodaTime.Period.Between(startTime, _endTime);
            NodaTime.Period end   = NodaTime.Period.Between(_startTime, endTime);

            if (Math.Abs(start.Hours) <= _range.Hour)
            {
                if (Math.Abs(start.Minutes) <= _range.Minute)
                {
                    return(true);
                }
            }
            else if (Math.Abs(end.Hours) <= _range.Hour)
            {
                if (Math.Abs(end.Minutes) <= _range.Minute)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 2
0
 /// <summary>
 /// Returns the exact difference between two times.
 /// </summary>
 /// <remarks>
 /// If <paramref name="end"/> is before <paramref name="start" />, each property in the returned period
 /// will be negative.
 /// </remarks>
 /// <param name="start">Start time</param>
 /// <param name="end">End time</param>
 /// <returns>The period between the two times, using the time period units.</returns>
 public static Period Between(LocalTime start, LocalTime end)
 {
     return(Between(start.LocalDateTime, end.LocalDateTime, PeriodUnits.AllTimeUnits));
 }
Esempio n. 3
0
 /// <summary>
 /// Returns the period between a start and an end time, using only the given units.
 /// </summary>
 /// <remarks>
 /// If <paramref name="end"/> is before <paramref name="start" />, each property in the returned period
 /// will be negative. If the given set of units cannot exactly reach the end point (e.g. finding
 /// the difference between 3am and 4.30am in hours) the result will be such that adding it to <paramref name="start"/>
 /// will give a value between <paramref name="start"/> and <paramref name="end"/>. In other words,
 /// any rounding is "towards start"; this is true whether the resulting period is negative or positive.
 /// </remarks>
 /// <param name="start">Start time</param>
 /// <param name="end">End time</param>
 /// <param name="units">Units to use for calculations</param>
 /// <exception cref="ArgumentException"><paramref name="units"/> contains date units, is empty or contains unknown values.</exception>
 /// <exception cref="ArgumentException"><paramref name="start"/> and <paramref name="end"/> use different calendars.</exception>
 /// <returns>The period between the given times, using the given units.</returns>
 public static Period Between(LocalTime start, LocalTime end, PeriodUnits units)
 {
     Preconditions.CheckArgument((units & PeriodUnits.AllDateUnits) == 0, "units", "Units contains date units: {0}", units);
     return(Between(start.LocalDateTime, end.LocalDateTime, units));
 }
Esempio n. 4
0
 public static Period Between(LocalTime start, LocalTime end) => Between(start, end, PeriodUnits.AllTimeUnits);
Esempio n. 5
0
 internal OffsetDateTime([Trusted] YearMonthDayCalendar yearMonthDayCalendar, LocalTime time, Offset offset)
 {
     this.yearMonthDayCalendar = yearMonthDayCalendar;
     this.nanosecondsAndOffset = CombineNanoOfDayAndOffset(time.NanosecondOfDay, offset);
     Calendar.DebugValidateYearMonthDay(YearMonthDay);
 }
Esempio n. 6
0
        public OffsetDateTime With([NotNull] Func <LocalTime, LocalTime> adjuster)
        {
            LocalTime newTime = TimeOfDay.With(adjuster);

            return(new OffsetDateTime(yearMonthDayCalendar, (nanosecondsAndOffset & OffsetMask) | newTime.NanosecondOfDay));
        }
Esempio n. 7
0
 public OffsetDateTime At(LocalTime time) => new OffsetDateTime(Date.At(time), Offset);
Esempio n. 8
0
 /// <summary>
 /// Constructs an instance of the specified time and offset.
 /// </summary>
 /// <param name="time">The time part of the value.</param>
 /// <param name="offset">The offset part of the value.</param>
 public OffsetTime(LocalTime time, Offset offset)
 {
     this.time   = time;
     this.offset = offset;
 }
Esempio n. 9
0
 public void Deconstruct(out LocalTime localTime, out Offset offset)
 {
     localTime = TimeOfDay;
     offset    = Offset;
 }
Esempio n. 10
0
 public void Deconstruct(out LocalDate localDate, out LocalTime localTime, out Offset offset)
 {
     localDate = LocalDateTime.Date;
     localTime = LocalDateTime.TimeOfDay;
     offset    = Offset;
 }
Esempio n. 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocalDateTime"/> struct using the ISO
 /// calendar system.
 /// </summary>
 /// <param name="localInstant">The local instant.</param>
 /// <returns>The resulting date/time.</returns>
 internal LocalDateTime([Trusted] LocalInstant localInstant)
 {
     date = new LocalDate(localInstant.DaysSinceEpoch);
     time = new LocalTime(localInstant.NanosecondOfDay);
 }
Esempio n. 12
0
 internal LocalDateTime(LocalDate date, LocalTime time)
 {
     this.date = date;
     this.time = time;
 }
Esempio n. 13
0
 /// <summary>
 /// Set time
 /// </summary>
 /// <param name="ldt"></param>
 /// <param name="lt"></param>
 /// <returns></returns>
 public static LocalDateTime SetTime(this LocalDateTime ldt, LocalTime lt) =>
 ldt.SetTime(lt.Hour, lt.Minute, lt.Second, lt.Millisecond);
Esempio n. 14
0
        public OffsetDateTime With(Func <LocalTime, LocalTime> adjuster)
        {
            LocalTime newTime = TimeOfDay.With(adjuster);

            return(new OffsetDateTime(localDate, new OffsetTime(newTime.NanosecondOfDay, offsetTime.OffsetSeconds)));
        }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TimeInterval"/> struct.
 /// The TimeInterval includes the <paramref name="start"/> LocalTime and excludes the
 /// <paramref name="end"/> LocalTime. The end may equal the start (resulting in an empty TimeInterval).
 /// </summary>
 /// <param name="start">The start <see cref="LocalTime"/>.</param>
 /// <param name="end">The end <see cref="LocalTime"/>.</param>
 public TimeInterval(LocalTime start, LocalTime end)
 {
     this.start     = start;
     this.end       = end;
     IsEndInNextDay = start > end;
 }
Esempio n. 16
0
        public static int DaysOff(string date, string time, string rpfTimeZone, string ingestTimeZone)
        {
            int           tensPlace     = 0;
            DateTime      localDt       = DateTime.Parse(string.Format("{0} {1}", date, time));
            LocalTime     localTime     = new LocalTime(localDt.Hour, localDt.Minute, localDt.Second);
            int           hour          = localDt.Hour;
            LocalDateTime localDateTime = LocalDateTime.FromDateTime(localDt);

            DateTimeZoneProviders dtzp = new DateTimeZoneProviders();

            DateTimeZone rpfZone    = dtzp.Tzdb[rpfTimeZone];
            DateTimeZone ingestZone = dtzp.Tzdb[ingestTimeZone];

            ZonedDateTime zonedDateTime = localDateTime.InZoneLeniently(rpfZone);
            Offset        rpfOffset     = rpfZone.GetUtcOffset(zonedDateTime.ToInstant());
            Offset        ingestOffset  = ingestZone.GetUtcOffset(zonedDateTime.ToInstant());


            ZonedDateTime zeroTime   = new LocalDateTime(LocalDate.FromDateTime(localDt), new LocalTime(0, 15)).InZoneLeniently(ingestZone);
            ZonedDateTime elevenTime = new LocalDateTime(LocalDate.FromDateTime(localDt), new LocalTime(11, 15)).InZoneLeniently(ingestZone);

            ZonedDateTime zeroTimeRpf   = new LocalDateTime(LocalDate.FromDateTime(localDt), new LocalTime(0, 15)).InZoneLeniently(rpfZone);
            ZonedDateTime elevenTimeRpf = new LocalDateTime(LocalDate.FromDateTime(localDt), new LocalTime(11, 15)).InZoneLeniently(rpfZone);

            Offset zeroOffset   = zeroTimeRpf.Offset - zeroTime.Offset;
            Offset elevenOffset = elevenTimeRpf.Offset - elevenTime.Offset;

            if (Math.Abs(zeroOffset.Milliseconds) < Math.Abs(elevenOffset.Milliseconds))
            {
                var zeroClock = new LocalTime(0, 0);
                var lowTime   = zeroClock.PlusMilliseconds(-zeroOffset.Milliseconds);
                var highTime  = zeroClock.PlusMilliseconds(-elevenOffset.Milliseconds);

                if (localTime >= lowTime && localTime < highTime)
                {
                    tensPlace = 10;
                }
            }

            /*
             *
             * at0 get offsets and subtract rpfoffat0 - ingestOffsetat0  (-4)
             * at11 get offsets and subtract rpfoffat11 - ingestoffat11 (-5)
             *
             * if these are different
             *  range is (0 in time) - at0 or (0 - -4) = 4
             *   to (0 in time) -at11 or (0 - -5) = 5
             *
             *
             */

            var offsetDelta = rpfOffset - ingestOffset;
            var hrsToAdd    = offsetDelta.Milliseconds / NodaConstants.MillisecondsPerHour;

            var newHour = (hour + hrsToAdd);

            if (newHour < 0)
            {
                return(-1 - tensPlace);
            }
            else if (newHour > 24)
            {
                return(1 + tensPlace);
            }
            else
            {
                return(0 + tensPlace);
            }
        }