当前位置: 首页>>代码示例>>C#>>正文


C# DateTime.Quarter方法代码示例

本文整理汇总了C#中System.DateTime.Quarter方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.Quarter方法的具体用法?C# DateTime.Quarter怎么用?C# DateTime.Quarter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.DateTime的用法示例。


在下文中一共展示了DateTime.Quarter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldReturnCorrectQuarter

        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);
        }
开发者ID:CedricDumont,项目名称:CExtensions-Net,代码行数:8,代码来源:DateTimeExtensionsTest.cs

示例2: TestQuarterCalc

        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);
            }
        }
开发者ID:vgribok,项目名称:Aspectacular,代码行数:18,代码来源:DateTImeExtTest.cs

示例3: QuarterWithCalendarShouldReturnExpectedResult

 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
 }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:7,代码来源:DateTimeExtensionsTest.cs

示例4: IsDateInYearAndQuarter

 public static Boolean IsDateInYearAndQuarter(DateTime dateTime, Int32 year, Int32 quarter)
 {
     CheckQuarter(quarter);
       return ((dateTime.Year == year) && (dateTime.Quarter() == quarter));
 }
开发者ID:ctimmons,项目名称:cs_utilities,代码行数:5,代码来源:DateTimeUtils.cs

示例5: QuarterShouldReturnExpectedResult

 public void QuarterShouldReturnExpectedResult()
 {
     var date = new DateTime( 2013, 4, 1 );
     var actual = date.Quarter();
     Assert.Equal( 2, actual );
 }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:6,代码来源:DateTimeExtensionsTest.cs

示例6: Includes

        /// <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;
        }
开发者ID:barake,项目名称:TemporalToolkit,代码行数:26,代码来源:TEQuarter.cs

示例7: FormatQuarterPart

        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 ) );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:18,代码来源:DateTimeFormatProvider.cs

示例8: Quarter

        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 );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:8,代码来源:CalendarExtensions.cs

示例9: EndOfQuarter

        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 );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:8,代码来源:CalendarExtensions.cs


注:本文中的System.DateTime.Quarter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。