Subtract() public method

public Subtract ( System.DateTime start, System.TimeSpan offset, SeekBoundaryMode seekBoundaryMode = SeekBoundaryMode.Next ) : DateTime?
start System.DateTime
offset System.TimeSpan
seekBoundaryMode SeekBoundaryMode
return DateTime?
コード例 #1
0
        public void PeriodLimitsSubtractTest()
        {
            DateTime test = new DateTime( 2011, 4, 30 );

            TimeRange timeRange1 = new TimeRange( new DateTime( 2011, 4, 20 ), new DateTime( 2011, 4, 25 ) );
            TimeRange timeRange2 = new TimeRange( DateTime.MinValue, new DateTime( 2011, 4, 10 ) );
            CalendarDateAdd calendarDateAdd = new CalendarDateAdd();
            calendarDateAdd.ExcludePeriods.Add( timeRange1 );
            calendarDateAdd.ExcludePeriods.Add( timeRange2 );

            Assert.AreEqual( calendarDateAdd.Subtract( test, new TimeSpan( 5, 0, 0, 0 ) ), timeRange1.Start );
            Assert.IsNull( calendarDateAdd.Subtract( test, new TimeSpan( 20, 0, 0, 0 ) ) );
        }
コード例 #2
0
        public void NoPeriodsTest()
        {
            DateTime test = new DateTime( 2011, 4, 12 );

            CalendarDateAdd calendarDateAdd = new CalendarDateAdd();
            Assert.AreEqual( calendarDateAdd.Add( test, TimeSpan.Zero ), test );
            Assert.AreEqual( calendarDateAdd.Add( test, new TimeSpan( 1, 0, 0, 0 ) ), test.Add( new TimeSpan( 1, 0, 0, 0 ) ) );
            Assert.AreEqual( calendarDateAdd.Add( test, new TimeSpan( -1, 0, 0, 0 ) ), test.Add( new TimeSpan( -1, 0, 0, 0 ) ) );
            Assert.AreEqual( calendarDateAdd.Subtract( test, new TimeSpan( 1, 0, 0, 0 ) ), test.Subtract( new TimeSpan( 1, 0, 0, 0 ) ) );
            Assert.AreEqual( calendarDateAdd.Subtract( test, new TimeSpan( -1, 0, 0, 0 ) ), test.Subtract( new TimeSpan( -1, 0, 0, 0 ) ) );
        }