本文整理汇总了C#中System.Globalization.GregorianCalendar.IsLeapYear方法的典型用法代码示例。如果您正苦于以下问题:C# GregorianCalendar.IsLeapYear方法的具体用法?C# GregorianCalendar.IsLeapYear怎么用?C# GregorianCalendar.IsLeapYear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.GregorianCalendar
的用法示例。
在下文中一共展示了GregorianCalendar.IsLeapYear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
{
ValidateArguments(arguments, 2);
var numDate1 = ArgToDecimal(arguments, 0);
var numDate2 = ArgToDecimal(arguments, 1);
var dt1 = System.DateTime.FromOADate(numDate1);
var dt2 = System.DateTime.FromOADate(numDate2);
var calcType = Days360Calctype.Us;
if (arguments.Count() > 2)
{
var european = ArgToBool(arguments, 2);
if(european) calcType = Days360Calctype.European;
}
var startYear = dt1.Year;
var startMonth = dt1.Month;
var startDay = dt1.Day;
var endYear = dt2.Year;
var endMonth = dt2.Month;
var endDay = dt2.Day;
if (calcType == Days360Calctype.European)
{
if (startDay == 31) startDay = 30;
if (endDay == 31) endDay = 30;
}
else
{
var calendar = new GregorianCalendar();
var nDaysInFeb = calendar.IsLeapYear(dt1.Year) ? 29 : 28;
// If the investment is EOM and (Date1 is the last day of February) and (Date2 is the last day of February), then change D2 to 30.
if (startMonth == 2 && startDay == nDaysInFeb && endMonth == 2 && endDay == nDaysInFeb)
{
endDay = 30;
}
// If the investment is EOM and (Date1 is the last day of February), then change D1 to 30.
if (startMonth == 2 && startDay == nDaysInFeb)
{
startDay = 30;
}
// If D2 is 31 and D1 is 30 or 31, then change D2 to 30.
if (endDay == 31 && (startDay == 30 || startDay == 31))
{
endDay = 30;
}
// If D1 is 31, then change D1 to 30.
if (startDay == 31)
{
startDay = 30;
}
}
var result = (endYear*12*30 + endMonth*30 + endDay) - (startYear*12*30 + startMonth*30 + startDay);
return CreateResult(result, DataType.Integer);
}
示例2: PosTest5
public void PosTest5()
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
int year;
bool expectedValue;
bool actualValue;
year = myCalendar.MinSupportedDateTime.Year;
expectedValue = this.IsLeapYear(year);
actualValue = myCalendar.IsLeapYear(year, 1);
Assert.Equal(expectedValue, actualValue);
}
示例3: PosTest2
public void PosTest2()
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
int year;
bool expectedValue;
bool actualValue;
year = GetACommonYear(myCalendar);
expectedValue = this.IsLeapYear(year);
actualValue = myCalendar.IsLeapYear(year, 1);
Assert.Equal(expectedValue, actualValue);
}
示例4: PosTest4
public void PosTest4()
{
System.Globalization.Calendar kC = new KoreanCalendar();
System.Globalization.Calendar gC = new GregorianCalendar();
DateTime dateTime = gC.ToDateTime(1200, 2, 29, 0, 0, 0, 0);
int year = dateTime.Year;
int era = gC.GetEra(dateTime);
bool expectedValue = gC.IsLeapYear(year, era);
bool actualValue;
actualValue = kC.IsLeapYear(year + 2333, kC.GetEra(dateTime));
Assert.Equal(expectedValue, actualValue);
}
示例5: Execute
public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
{
var functionArguments = arguments as FunctionArgument[] ?? arguments.ToArray();
ValidateArguments(functionArguments, 2);
var date1Num = ArgToDecimal(functionArguments, 0);
var date2Num = ArgToDecimal(functionArguments, 1);
if (date1Num > date2Num) //Switch to make date1 the lowest date
{
var t = date1Num;
date1Num = date2Num;
date2Num = t;
var fa = functionArguments[1];
functionArguments[1] = functionArguments[0];
functionArguments[0] = fa;
}
var date1 = System.DateTime.FromOADate(date1Num);
var date2 = System.DateTime.FromOADate(date2Num);
var basis = 0;
if (functionArguments.Count() > 2)
{
basis = ArgToInt(functionArguments, 2);
ThrowExcelErrorValueExceptionIf(() => basis < 0 || basis > 4, eErrorType.Num);
}
var func = context.Configuration.FunctionRepository.GetFunction("days360");
var calendar = new GregorianCalendar();
switch (basis)
{
case 0:
var d360Result = System.Math.Abs(func.Execute(functionArguments, context).ResultNumeric);
// reproducing excels behaviour
if (date1.Month == 2 && date2.Day==31)
{
var daysInFeb = calendar.IsLeapYear(date1.Year) ? 29 : 28;
if (date1.Day == daysInFeb) d360Result++;
}
return CreateResult(d360Result / 360d, DataType.Decimal);
case 1:
return CreateResult(System.Math.Abs((date2 - date1).TotalDays / CalculateAcutalYear(date1, date2)), DataType.Decimal);
case 2:
return CreateResult(System.Math.Abs((date2 - date1).TotalDays / 360d), DataType.Decimal);
case 3:
return CreateResult(System.Math.Abs((date2 - date1).TotalDays / 365d), DataType.Decimal);
case 4:
var args = functionArguments.ToList();
args.Add(new FunctionArgument(true));
double? result = System.Math.Abs(func.Execute(args, context).ResultNumeric / 360d);
return CreateResult(result.Value, DataType.Decimal);
default:
return null;
}
}
示例6: CalculateAcutalYear
private double CalculateAcutalYear(System.DateTime dt1, System.DateTime dt2)
{
var calendar = new GregorianCalendar();
var perYear = 0d;
var nYears = dt2.Year - dt1.Year + 1;
for (var y = dt1.Year; y <= dt2.Year; ++y)
{
perYear += calendar.IsLeapYear(y) ? 366 : 365;
}
if (new System.DateTime(dt1.Year + 1, dt1.Month, dt1.Day) >= dt2)
{
nYears = 1;
perYear = 365;
if (calendar.IsLeapYear(dt1.Year) && dt1.Month <= 2)
perYear = 366;
else if (calendar.IsLeapYear(dt2.Year) && dt2.Month > 2)
perYear = 366;
else if (dt2.Month == 2 && dt2.Day == 29)
perYear = 366;
}
return perYear/(double) nYears;
}
示例7: LeapYearCalendar
public string LeapYearCalendar(int anio)
{
string result = String.Empty; ;
GregorianCalendar calendar = new GregorianCalendar();
if (calendar.IsLeapYear((anio)))
{
result = "LeapYear";
}
else
{
result = "NoLeapYear";
}
return result;
}
示例8: ParseTrek
private bool ParseTrek(ClockToken[] dt, ref System.Int32 parsePos, TclDateTime calendar)
// calendar object to set
{
int pos = parsePos;
if (pos + 3 < dt.Length && dt[pos].is_Renamed(ClockToken.STARDATE) && dt[pos + 1].UNumber && dt[pos + 2].is_Renamed('.') && dt[pos + 3].UNumber)
{
GregorianCalendar gcal = new GregorianCalendar();
int trekYear = dt[pos + 1].Int / 1000 + 2323 - 377;
int trekDay = 1 + ((dt[pos + 1].Int % 1000) * (gcal.IsLeapYear(trekYear) ? 366 : 365)) / 1000;
int trekSeconds = dt[pos + 3].Int * 144 * 60;
calendar.year = trekYear;
calendar.dateTime = gcal.AddDays(calendar.dateTime, trekDay);
calendar.second = trekSeconds;
parsePos = pos + 4;
return true;
}
return false;
}
示例9: FormatClock
private void FormatClock(Interp interp, int clockVal, bool useGMT, string format)
{
DateTime date = new DateTime((long)clockVal * 10000 * 1000 + 621355968000000000);
DateTimeFormatInfo formatInfo = new DateTimeFormatInfo();
string fmt, locFmt;
GregorianCalendar calendar = new GregorianCalendar();
System.Int32[] temp_int_array;
temp_int_array = new System.Int32[3];
temp_int_array[0] = 0;
temp_int_array[1] = 0;
temp_int_array[2] = 0;
System.Int32[] fp = temp_int_array;
StringBuilder result = new StringBuilder();
if ((System.Object)format == null)
{
format = new StringBuilder("%a %b %d %H:%M:%S %Z %Y").ToString();
}
if (useGMT)
{
date = date.ToUniversalTime();
}
if (format.Equals("%Q"))
{
// Enterprise Stardate. (seems to be Star Track fan coding)
// ATK not tested
int trekYear = date.Year + 377 - 2323;
int trekDay = (date.DayOfYear * 1000) / (calendar.IsLeapYear(date.Year) ? 366 : 365);
int trekHour = (24 * 60 + date.Minute) / 144;
interp.SetResult("Stardate " + (trekYear < 10 ? "0" : "") + (trekYear * 1000 + trekDay) + '.' + trekHour);
return;
}
for (int ix = 0; ix < format.Length; ix++)
{
if (format[ix] == '%' && ix + 1 < format.Length)
{
switch (format[++ix])
{
case '%':
result.Append('%');
break;
case 'a':
result.Append(date.ToString("ddd", formatInfo));
break;
case 'A':
result.Append(date.ToString("dddd", formatInfo));
break;
case 'b':
case 'h':
result.Append(date.ToString("MMM", formatInfo));
break;
case 'B':
result.Append(date.ToString("MMMM", formatInfo));
break;
case 'c':
result.Append(date.ToString());
break;
case 'C':
int century = date.Year / 100;
result.Append((century < 10 ? "0" : "") + century);
break;
case 'd':
result.Append(date.ToString("dd", formatInfo));
break;
case 'D':
result.Append(date.ToString("MM/dd/yy", formatInfo));
break;
case 'e':
result.Append(date.ToString("%d", formatInfo));
break;
case 'H':
result.Append(date.ToString("HH", formatInfo));
break;
case 'I':
result.Append(date.ToString("hh", formatInfo));
break;
case 'j':
result.Append(date.Year.ToString("0###"));
break;
case 'k':
result.Append(date.ToString("H", formatInfo));
break;
case 'l':
result.Append(date.ToString("%h", formatInfo));
break;
case 'm':
// Month number (01 - 12).
result.Append(date.ToString("MM", formatInfo));
break;
case 'M':
// Minute (00 - 59).
//.........这里部分代码省略.........
示例10: FixedToGregorian
/// <summary>
/// Fixeds to gregorian.
/// </summary>
/// <param name="fixedDate">The fixed date.</param>
/// <param name="year">The year.</param>
/// <param name="month">The month.</param>
/// <param name="day">The day.</param>
private static void FixedToGregorian(int fixedDate, ref int year, ref int month, ref int day)
{
GregorianCalendar gregorianCalendar = new GregorianCalendar();
year = GregorianYearFromFixed(fixedDate);
int num2 = fixedDate - GregorianToFixed(year, 1, 1);
int num = (fixedDate < GregorianToFixed(year, 3, 1)) ? 0 : (gregorianCalendar.IsLeapYear(year) ? 1 : 2);
month = (int)Math.Floor((double)(((double)((12 * (num2 + num)) + 0x175)) / 367.0));
day = (fixedDate - GregorianToFixed(year, month, 1)) + 1;
}
示例11: NegTest1
public void NegTest1()
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
int year;
year = myCalendar.MaxSupportedDateTime.Year + 100;
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
myCalendar.IsLeapYear(year, 1);
});
}
示例12: NegTest3
public void NegTest3()
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
int year;
int era;
year = this.GetAYear(myCalendar);
era = 2 + _generator.GetInt32(-55) % (int.MaxValue - 1);
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
myCalendar.IsLeapYear(year, era);
});
}
示例13: SpecialDates
public void SpecialDates()
{
NpgsqlDate date;
DateTime dateTime;
System.Globalization.Calendar calendar = new System.Globalization.GregorianCalendar();
// a date after a leap year.
dateTime = new DateTime(2008, 5, 31);
date = new NpgsqlDate(dateTime);
Assert.AreEqual(dateTime.Day, date.Day);
Assert.AreEqual(dateTime.DayOfWeek, date.DayOfWeek);
Assert.AreEqual(dateTime.DayOfYear, date.DayOfYear);
Assert.AreEqual(calendar.IsLeapYear(2008), date.IsLeapYear);
Assert.AreEqual(dateTime.Month, date.Month);
Assert.AreEqual(dateTime.Year, date.Year);
// A date that is a leap year day.
dateTime = new DateTime(2000, 2, 29);
date = new NpgsqlDate(2000, 2, 29);
Assert.AreEqual(dateTime.Day, date.Day);
Assert.AreEqual(dateTime.DayOfWeek, date.DayOfWeek);
Assert.AreEqual(dateTime.DayOfYear, date.DayOfYear);
Assert.AreEqual(calendar.IsLeapYear(2000), date.IsLeapYear);
Assert.AreEqual(dateTime.Month, date.Month);
Assert.AreEqual(dateTime.Year, date.Year);
// A date that is not in a leap year.
dateTime = new DateTime(1900, 3, 1);
date = new NpgsqlDate(1900, 3, 1);
Assert.AreEqual(dateTime.Day, date.Day);
Assert.AreEqual(dateTime.DayOfWeek, date.DayOfWeek);
Assert.AreEqual(dateTime.DayOfYear, date.DayOfYear);
Assert.AreEqual(calendar.IsLeapYear(1900), date.IsLeapYear);
Assert.AreEqual(dateTime.Month, date.Month);
Assert.AreEqual(dateTime.Year, date.Year);
// a date after a leap year.
date = new NpgsqlDate(-1, 12, 31);
Assert.AreEqual(31, date.Day);
Assert.AreEqual(DayOfWeek.Sunday, date.DayOfWeek);
Assert.AreEqual(366, date.DayOfYear);
Assert.AreEqual(true, date.IsLeapYear);
Assert.AreEqual(12, date.Month);
Assert.AreEqual(-1, date.Year);
}
示例14: NpgsqlDateConstructors
public void NpgsqlDateConstructors()
{
NpgsqlDate date;
DateTime dateTime;
System.Globalization.Calendar calendar = new System.Globalization.GregorianCalendar();
date = new NpgsqlDate();
Assert.AreEqual(1, date.Day);
Assert.AreEqual(DayOfWeek.Monday, date.DayOfWeek);
Assert.AreEqual(1, date.DayOfYear);
Assert.AreEqual(false, date.IsLeapYear);
Assert.AreEqual(1, date.Month);
Assert.AreEqual(1, date.Year);
dateTime = new DateTime(2009, 5, 31);
date = new NpgsqlDate(dateTime);
Assert.AreEqual(dateTime.Day, date.Day);
Assert.AreEqual(dateTime.DayOfWeek, date.DayOfWeek);
Assert.AreEqual(dateTime.DayOfYear, date.DayOfYear);
Assert.AreEqual(calendar.IsLeapYear(2009), date.IsLeapYear);
Assert.AreEqual(dateTime.Month, date.Month);
Assert.AreEqual(dateTime.Year, date.Year);
//Console.WriteLine(new DateTime(2009, 5, 31).Ticks);
//Console.WriteLine((new DateTime(2009, 5, 31) - new DateTime(1, 1, 1)).TotalDays);
// 2009-5-31
dateTime = new DateTime(633793248000000000); // ticks since 1 Jan 1
date = new NpgsqlDate(733557); // days since 1 Jan 1
Assert.AreEqual(dateTime.Day, date.Day);
Assert.AreEqual(dateTime.DayOfWeek, date.DayOfWeek);
Assert.AreEqual(dateTime.DayOfYear, date.DayOfYear);
Assert.AreEqual(calendar.IsLeapYear(2009), date.IsLeapYear);
Assert.AreEqual(dateTime.Month, date.Month);
Assert.AreEqual(dateTime.Year, date.Year);
// copy previous value. should get same result
date = new NpgsqlDate(date);
Assert.AreEqual(dateTime.Day, date.Day);
Assert.AreEqual(dateTime.DayOfWeek, date.DayOfWeek);
Assert.AreEqual(dateTime.DayOfYear, date.DayOfYear);
Assert.AreEqual(calendar.IsLeapYear(2009), date.IsLeapYear);
Assert.AreEqual(dateTime.Month, date.Month);
Assert.AreEqual(dateTime.Year, date.Year);
}
示例15: IsLeapYearShouldReturnCorrectValueForFiscalYear
public void IsLeapYearShouldReturnCorrectValueForFiscalYear()
{
var target = new GregorianFiscalCalendar( 7 );
var calendar = new GregorianCalendar();
for ( var year = 2005; year <= 2015; year++ )
Assert.Equal( calendar.IsLeapYear( year - 1 ) | calendar.IsLeapYear( year ), target.IsLeapYear( year ) );
}