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); }
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); }
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; }
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); }); }
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); }); }
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); }
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"); }