本文整理汇总了C#中System.Globalization.GregorianCalendar.ToFourDigitYear方法的典型用法代码示例。如果您正苦于以下问题:C# GregorianCalendar.ToFourDigitYear方法的具体用法?C# GregorianCalendar.ToFourDigitYear怎么用?C# GregorianCalendar.ToFourDigitYear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.GregorianCalendar
的用法示例。
在下文中一共展示了GregorianCalendar.ToFourDigitYear方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PosTest3
private void PosTest3(GregorianCalendarTypes calendarType)
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(calendarType);
int twoDigitYear;
int expectedFourDigitYear, actualFourDigitYear;
twoDigitYear = c_MIN_TWO_DIGIT_YEAR;
expectedFourDigitYear = GetExpectedFourDigitYear(myCalendar, twoDigitYear);
actualFourDigitYear = myCalendar.ToFourDigitYear(twoDigitYear);
Assert.Equal(expectedFourDigitYear, actualFourDigitYear);
}
示例2: PosTest1
private void PosTest1(GregorianCalendarTypes calendarType)
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(calendarType);
int twoDigitYear;
int expectedFourDigitYear, actualFourDigitYear;
twoDigitYear = TestLibrary.Generator.GetInt32(-55) % (c_MAX_TWO_DIGIT_YEAR + 1);
expectedFourDigitYear = GetExpectedFourDigitYear(myCalendar, twoDigitYear);
actualFourDigitYear = myCalendar.ToFourDigitYear(twoDigitYear);
Assert.Equal(expectedFourDigitYear, actualFourDigitYear);
}
示例3: CalculateAge
private static int CalculateAge(string socialSecurityNumber)
{
int age;
if (socialSecurityNumber == null)
{
return 0;
}
bool isShortNumber = socialSecurityNumber?.Length == 12;
if (isShortNumber)
{
//retrive birthdate
int yearOfBirth = Convert.ToInt32(socialSecurityNumber.Substring(0, 1)); //retrives y.o.b
int monthOfBirth = Convert.ToInt32(socialSecurityNumber.Substring(2, 3)); //retrives m.o.b
int dayOfBirth = Convert.ToInt32(socialSecurityNumber.Substring(4, 5)); //retrives d.o.b
Calendar testCalendar = new GregorianCalendar();
yearOfBirth = testCalendar.ToFourDigitYear(yearOfBirth);
testCalendar = null; //dispose of calendar
DateTime birthDate = new DateTime(yearOfBirth, monthOfBirth, dayOfBirth); //when the person was born
DateTime todayTime = DateTime.Now.Date; //todays date
DateTime birthDay = new DateTime(todayTime.Year, monthOfBirth, dayOfBirth);
//the persons birthday this year
int birthDateAdjustment = todayTime < birthDay ? -1 : 0;
//check if the persons birthday has already occured
age = todayTime.Year - birthDate.Year + birthDateAdjustment;
}
else
{
//retrive birthdate
int yearOfBirth = Convert.ToInt32(socialSecurityNumber.Substring(0, 3)); //retrives y.o.b
int monthOfBirth = Convert.ToInt32(socialSecurityNumber.Substring(4, 5)); //retrives m.o.b
int dayOfBirth = Convert.ToInt32(socialSecurityNumber.Substring(6, 7)); //retrives d.o.b
DateTime birthDate = new DateTime(yearOfBirth, monthOfBirth, dayOfBirth); //when the person was born
DateTime todayTime = DateTime.Now.Date; //todays date
DateTime birthDay = new DateTime(todayTime.Year, monthOfBirth, dayOfBirth);
//the persons birthday this year
int birthDateAdjustment = todayTime < birthDay ? -1 : 0;
//check if the persons birthday has already occured
age = todayTime.Year - birthDate.Year + birthDateAdjustment;
}
return age;
}
示例4: NegTest2
private void NegTest2(GregorianCalendarTypes calendarType)
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(calendarType);
int twoDigitYear;
twoDigitYear = c_MAX_TWO_DIGIT_YEAR + TestLibrary.Generator.GetInt32(-55) % (int.MaxValue - c_MAX_TWO_DIGIT_YEAR);
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
myCalendar.ToFourDigitYear(twoDigitYear);
});
}
示例5: NegTest1
private void NegTest1(GregorianCalendarTypes calendarType)
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(calendarType);
int twoDigitYear;
twoDigitYear = -1 * TestLibrary.Generator.GetInt32(-55);
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
myCalendar.ToFourDigitYear(twoDigitYear);
});
}
示例6: ToFourDigitYear
public static int ToFourDigitYear(int iYear)
{
GregorianCalendar gc;
gc = new GregorianCalendar(GregorianCalendarTypes.TransliteratedFrench);
//Debug.WriteLine(string.Format("TwoDigitYearMax = {0}", gc.TwoDigitYearMax));
return gc.ToFourDigitYear(iYear);
}
示例7: TestToFourDigitYear2
public void TestToFourDigitYear2 ()
{
GregorianCalendar gc = new GregorianCalendar ();
Assert.AreEqual (2029, gc.ToFourDigitYear (29), "#1-1");
Assert.AreEqual (1930, gc.ToFourDigitYear (30), "#1-2");
Assert.AreEqual (2029, gc.ToFourDigitYear (2029), "#1-3");
Assert.AreEqual (2030, gc.ToFourDigitYear (2030), "#1-4");
HebrewCalendar hbc = new HebrewCalendar ();
Assert.AreEqual (5790, hbc.ToFourDigitYear (90), "#2-1");
Assert.AreEqual (5691, hbc.ToFourDigitYear (91), "#2-2");
Assert.AreEqual (5790, hbc.ToFourDigitYear (5790), "#2-3");
Assert.AreEqual (5691, hbc.ToFourDigitYear (5691), "#2-4");
Assert.AreEqual (5999, hbc.ToFourDigitYear (5999), "#2-5");
// LAMESPEC: .NET fails to throw an exception unlike documented
/*
try {
hbc.ToFourDigitYear (6000);
Assert.Fail ("#2-6");
} catch (ArgumentOutOfRangeException) {
}
*/
ThaiBuddhistCalendar tc = new ThaiBuddhistCalendar ();
Assert.AreEqual (2572, tc.ToFourDigitYear (72), "#3-1");
Assert.AreEqual (2473, tc.ToFourDigitYear (73), "#3-2");
Assert.AreEqual (2572, tc.ToFourDigitYear (2572), "#3-3");
Assert.AreEqual (2573, tc.ToFourDigitYear (2573), "#3-4");
Assert.AreEqual (9999, tc.ToFourDigitYear (9999), "#3-5");
// LAMESPEC: .NET fails to throw an exception unlike documented
/*
try {
tc.ToFourDigitYear (10000);
Assert.Fail ("#3-6");
} catch (ArgumentOutOfRangeException) {
}
*/
KoreanCalendar kc = new KoreanCalendar ();
Assert.AreEqual (4362, kc.ToFourDigitYear (62), "#4-1");
Assert.AreEqual (4263, kc.ToFourDigitYear (63), "#4-2");
Assert.AreEqual (4362, kc.ToFourDigitYear (4362), "#4-3");
Assert.AreEqual (4363, kc.ToFourDigitYear (4363), "#4-4");
}