Exemplo n.º 1
0
        public void ToTimeInterval_Null_ThrowsException()
        {
            // Arrange
            DateTimeInterval interval = null;

            // Act
            Action act = () => interval.ToTimeInterval();

            // Assert
            act.Should().Throw <ArgumentNullException>().And.Message.Should().Contain(nameof(interval));
        }
Exemplo n.º 2
0
        public void ToTimeInterval_LongerThanADay_ThrowsException()
        {
            // Arrange
            var startDateTime = Fixture.Create <LocalDateTime>();
            var period        = Period.FromDays(1) + Period.FromNanoseconds(1);
            var interval      = new DateTimeInterval(startDateTime, period);

            // Act
            Action act = () => interval.ToTimeInterval();

            // Assert
            act.Should().Throw <NotSupportedException>().And.Message.Should().Contain(nameof(interval));
        }
Exemplo n.º 3
0
        public void ToTimeInterval_OneDayLongInterval_OneDayTimeInterval()
        {
            // Arrange
            var startDateTime = Fixture.Create <LocalDateTime>();
            var period        = Period.FromDays(1);
            var interval      = new DateTimeInterval(startDateTime, period);
            var time          = startDateTime.TimeOfDay;

            // Act
            var timeInterval = interval.ToTimeInterval();

            // Assert
            timeInterval.Start.Should().Be(time);
            timeInterval.End.Should().Be(time);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Determines whether the time interval overlaps the date time interval.
        /// </summary>
        /// <param name="timeInterval">The time interval.</param>
        /// <param name="dateTimeInterval">The date time interval.</param>
        /// <returns><c>true</c> if the time interval overlaps the date time interval; <c>false</c>, otherwise.</returns>
        /// <remarks>
        /// This will always be <c>true</c> for date time intervals that are longer than a day.
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">If <paramref name="timeInterval"/> or <paramref name="dateTimeInterval"/> is <c>null</c>.</exception>
        public static bool Overlaps(this TimeInterval timeInterval, DateTimeInterval dateTimeInterval)
        {
            if (timeInterval == null)
            {
                throw new System.ArgumentNullException(nameof(timeInterval));
            }

            if (dateTimeInterval == null)
            {
                throw new System.ArgumentNullException(nameof(dateTimeInterval));
            }

            if (dateTimeInterval.IsSinglePointInterval())
            {
                return(timeInterval.Contains(dateTimeInterval.Start.TimeOfDay));
            }

            var maxEnd = dateTimeInterval.Start + Period.FromDays(1);

            return(maxEnd < dateTimeInterval.End || dateTimeInterval.ToTimeInterval().Overlaps(timeInterval));
        }