HasInside() 공개 메소드

public HasInside ( System.DateTime test ) : bool
test System.DateTime
리턴 bool
예제 #1
0
        // ----------------------------------------------------------------------
        public bool IsValidReservation( DateTime start, DateTime end )
        {
            if ( !TimeCompare.IsSameDay( start, end ) )
            {
                return false;  // multiple day reservation
            }

            TimeRange workingHours = new TimeRange( TimeTrim.Hour( start, 8 ), TimeTrim.Hour( start, 18 ) );
            return workingHours.HasInside( new TimeRange( start, end ) );
        }
예제 #2
0
        public void HasInsideDateTimeTest()
        {
            TimeRange timeRange = new TimeRange( start, end );
            Assert.AreEqual( timeRange.End, end );

            // start
            Assert.IsFalse( timeRange.HasInside( start.AddMilliseconds( -1 ) ) );
            Assert.IsTrue( timeRange.HasInside( start ) );
            Assert.IsTrue( timeRange.HasInside( start.AddMilliseconds( 1 ) ) );

            // end
            Assert.IsTrue( timeRange.HasInside( end.AddMilliseconds( -1 ) ) );
            Assert.IsTrue( timeRange.HasInside( end ) );
            Assert.IsFalse( timeRange.HasInside( end.AddMilliseconds( 1 ) ) );
        }
예제 #3
0
        public void HasInsidePeriodTest()
        {
            TimeRange timeRange = new TimeRange( start, end );
            Assert.AreEqual( timeRange.End, end );

            // before
            TimeRange before1 = new TimeRange( start.AddHours( -2 ), start.AddHours( -1 ) );
            Assert.IsFalse( timeRange.HasInside( before1 ) );
            TimeRange before2 = new TimeRange( start.AddMilliseconds( -1 ), end );
            Assert.IsFalse( timeRange.HasInside( before2 ) );
            TimeRange before3 = new TimeRange( start.AddMilliseconds( -1 ), start );
            Assert.IsFalse( timeRange.HasInside( before3 ) );

            // after
            TimeRange after1 = new TimeRange( end.AddHours( 1 ), end.AddHours( 2 ) );
            Assert.IsFalse( timeRange.HasInside( after1 ) );
            TimeRange after2 = new TimeRange( start, end.AddMilliseconds( 1 ) );
            Assert.IsFalse( timeRange.HasInside( after2 ) );
            TimeRange after3 = new TimeRange( end, end.AddMilliseconds( 1 ) );
            Assert.IsFalse( timeRange.HasInside( after3 ) );

            // inside
            Assert.IsTrue( timeRange.HasInside( timeRange ) );
            TimeRange inside1 = new TimeRange( start.AddMilliseconds( 1 ), end );
            Assert.IsTrue( timeRange.HasInside( inside1 ) );
            TimeRange inside2 = new TimeRange( start.AddMilliseconds( 1 ), end.AddMilliseconds( -1 ) );
            Assert.IsTrue( timeRange.HasInside( inside2 ) );
            TimeRange inside3 = new TimeRange( start, end.AddMilliseconds( -1 ) );
            Assert.IsTrue( timeRange.HasInside( inside3 ) );
        }
예제 #4
0
        public void CheckDateBetweenDatesSample()
        {
            DateTime[] moments = new[]
                {
                    new DateTime( 2011, 11, 02 ),
                    new DateTime( 2011, 12, 25 ),
                    new DateTime( 2011, 12, 09 ),
                    new DateTime( 2011, 12, 13 )
                };

            TimeRange timeRange = new TimeRange( new DateTime( 2011, 11, 01 ), new DateTime( 2011, 12, 15 ) );

            Console.WriteLine( "time range: {0}", timeRange );
            foreach ( DateTime moment in moments )
            {
                Console.WriteLine( "{0:d} is inside: {1}", moment, timeRange.HasInside( moment ) ? "1" : "0" );
            }
        }