private GetWeekOfYear ( System.DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek ) : int | ||
time | System.DateTime | |
rule | CalendarWeekRule | |
firstDayOfWeek | DayOfWeek | |
Результат | int |
public void PosTest1() { System.Globalization.Calendar tbc = new ThaiBuddhistCalendar(); Random rand = new Random(-55); int year = rand.Next(tbc.MinSupportedDateTime.Year, tbc.MaxSupportedDateTime.Year); int month = rand.Next(1, 12); int day; if (IsLeapYear(year)) { day = rand.Next(1, _DAYS_PER_MONTHS_IN_LEAP_YEAR[month] + 1); } else { day = rand.Next(1, _DAYS_PER_MONTHS_IN_NO_LEAP_YEAR[month] + 1); } DateTime dt = new DateTime(year, month, day); for (int i = 0; i < 7; i++) { for (int j = 0; j < 3; j++) { int actualWeek = getWeekOfYear(dt, (CalendarWeekRule)j, (DayOfWeek)i); int resultWeek = tbc.GetWeekOfYear(dt, (CalendarWeekRule)j, (DayOfWeek)i); Assert.Equal(actualWeek, resultWeek); } } }
public void PosTest2() { System.Globalization.Calendar tbc = new ThaiBuddhistCalendar(); DateTime dt = tbc.MaxSupportedDateTime; for (int i = 0; i < 7; i++) { for (int j = 0; j < 3; j++) { int actualWeek = getWeekOfYear(dt, (CalendarWeekRule)j, (DayOfWeek)i); int resultWeek = tbc.GetWeekOfYear(dt, (CalendarWeekRule)j, (DayOfWeek)i); Assert.Equal(actualWeek, resultWeek); } } }
public void PosTest4() { System.Globalization.Calendar tbc = new ThaiBuddhistCalendar(); System.Globalization.Calendar gc = new GregorianCalendar(); Random rand = new Random(-55); int year = rand.Next(tbc.MinSupportedDateTime.Year, tbc.MaxSupportedDateTime.Year); int month = 12; int day = 31; int actualWeek = 53; DateTime dt = new DateTime(year, month, day); CultureInfo myCI = new CultureInfo("th-TH"); int resultWeek = tbc.GetWeekOfYear(dt, myCI.DateTimeFormat.CalendarWeekRule, myCI.DateTimeFormat.FirstDayOfWeek); Assert.Equal(actualWeek, resultWeek); }
public void NegTest2() { System.Globalization.Calendar tbc = new ThaiBuddhistCalendar(); Random rand = new Random(-55); int year = rand.Next(tbc.MinSupportedDateTime.Year, tbc.MaxSupportedDateTime.Year); int month = rand.Next(1, 12); int day; if (IsLeapYear(year)) { day = rand.Next(1, _DAYS_PER_MONTHS_IN_LEAP_YEAR[month] + 1); } else { day = rand.Next(1, _DAYS_PER_MONTHS_IN_NO_LEAP_YEAR[month] + 1); } DateTime dt = new DateTime(year, month, day); CultureInfo myCI = new CultureInfo("th-TH"); Assert.Throws<ArgumentOutOfRangeException>(() => { tbc.GetWeekOfYear(dt, (CalendarWeekRule)3, myCI.DateTimeFormat.FirstDayOfWeek); }); Assert.Throws<ArgumentOutOfRangeException>(() => { tbc.GetWeekOfYear(dt, (CalendarWeekRule)(-1), myCI.DateTimeFormat.FirstDayOfWeek); }); }