コード例 #1
0
        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);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
 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
 }
コード例 #4
0
 public static Boolean IsDateInYearAndQuarter(DateTime dateTime, Int32 year, Int32 quarter)
 {
     CheckQuarter(quarter);
       return ((dateTime.Year == year) && (dateTime.Quarter() == quarter));
 }
コード例 #5
0
 public void QuarterShouldReturnExpectedResult()
 {
     var date = new DateTime( 2013, 4, 1 );
     var actual = date.Quarter();
     Assert.Equal( 2, actual );
 }
コード例 #6
0
ファイル: TEQuarter.cs プロジェクト: barake/TemporalToolkit
        /// <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;
        }
コード例 #7
0
        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 ) );
        }
コード例 #8
0
        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 );
        }
コード例 #9
0
        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 );
        }