public void ShouldReturnCorrectQuarter(int year, int month, int day, int expectedQuarter) { DateTime dt = new DateTime(year, month, day); int quarter = dt.Quarter(); quarter.ShouldBe(expectedQuarter); }
public void TestQuarterCalc() { for(int month = 1; month <= 12; month++) { DateTime qtrTest = new DateTime(2013, month, 5); int quarter = qtrTest.Quarter(); if(qtrTest.Month >= 1 && qtrTest.Month <= 3) Assert.AreEqual(1, quarter); else if(qtrTest.Month >= 4 && qtrTest.Month <= 6) Assert.AreEqual(2, quarter); else if(qtrTest.Month >= 7 && qtrTest.Month <= 9) Assert.AreEqual(3, quarter); else if(qtrTest.Month >= 10 && qtrTest.Month <= 12) Assert.AreEqual(4, quarter); } }
public void QuarterWithCalendarShouldReturnExpectedResult() { var date = new DateTime( 2013, 3, 1 ); var calendar = new GregorianFiscalCalendar( 7 ); var actual = date.Quarter( calendar ); Assert.Equal( 3, actual ); // because fiscal calendar starts in July }
public static Boolean IsDateInYearAndQuarter(DateTime dateTime, Int32 year, Int32 quarter) { CheckQuarter(quarter); return ((dateTime.Year == year) && (dateTime.Quarter() == quarter)); }
public void QuarterShouldReturnExpectedResult() { var date = new DateTime( 2013, 4, 1 ); var actual = date.Quarter(); Assert.Equal( 2, actual ); }
/// <summary> /// Returns true if date falls on specified quarter or range of quarters /// </summary> /// <param name="aDate"></param> /// <returns></returns> public override bool Includes(DateTime aDate) { //check for valid args if (this.Start == Quarter.Unset || (this.End.HasValue && this.End.Value == Quarter.Unset)) throw new ArgumentException(); bool result; if (this.End.HasValue) { //range if (this.End.Value >= this.Start) result = (aDate.Quarter(this.StartOfYear) <= this.End.Value && aDate.Quarter(this.StartOfYear) >= this.Start); else result = (aDate.Quarter(this.StartOfYear) <= this.End.Value || aDate.Quarter(this.StartOfYear)>= this.Start); } else result = (this.Start == aDate.Quarter(this.StartOfYear)); return result; }
protected virtual string FormatQuarterPart( DateTime value, string format, IFormatProvider formatProvider ) { Arg.NotNullOrEmpty( format, nameof( format ) ); Contract.Ensures( !string.IsNullOrEmpty( Contract.Result<string>() ) ); switch ( format.Length ) { case 1: // q return value.Quarter( Calendar ).ToString( formatProvider ); case 2: // qq return value.Quarter( Calendar ).ToString( "00", formatProvider ); case 3: // qqq return string.Format( formatProvider, SR.ShortQuarterFormat, value.Quarter( Calendar ) ); } // qqqq* return string.Format( formatProvider, SR.QuarterFormat, value.Quarter( Calendar ) ); }
public static int Quarter( this Calendar calendar, DateTime date ) { Arg.NotNull( calendar, nameof( calendar ) ); Contract.Ensures( Contract.Result<int>() > 0 ); Contract.Ensures( Contract.Result<int>() < 5 ); return date.Quarter( calendar ); }
public static DateTime EndOfQuarter( this Calendar calendar, DateTime date ) { Arg.NotNull( calendar, nameof( calendar ) ); Contract.Ensures( calendar.GetYear( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetYear( date ) ) ); Contract.Ensures( Contract.Result<DateTime>().Quarter( calendar ) == Contract.OldValue( date.Quarter( calendar ) ) ); return date.EndOfQuarter( calendar ); }