本文整理汇总了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);
}
示例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);
}
}
示例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
}
示例4: IsDateInYearAndQuarter
public static Boolean IsDateInYearAndQuarter(DateTime dateTime, Int32 year, Int32 quarter)
{
CheckQuarter(quarter);
return ((dateTime.Year == year) && (dateTime.Quarter() == quarter));
}
示例5: QuarterShouldReturnExpectedResult
public void QuarterShouldReturnExpectedResult()
{
var date = new DateTime( 2013, 4, 1 );
var actual = date.Quarter();
Assert.Equal( 2, actual );
}
示例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;
}
示例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 ) );
}
示例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 );
}
示例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 );
}