GetWeekOfYear() private method

private GetWeekOfYear ( System.DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek ) : int
time System.DateTime
rule CalendarWeekRule
firstDayOfWeek DayOfWeek
return int
コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
 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);
         }
     }
 }
コード例 #3
0
 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);
 }
コード例 #4
0
        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);
            });
        }