示例#1
0
        public void GetStartOfWeekTest()
        {
            DateTime        now      = ClockProxy.Clock.Now;
            CultureTestData cultures = new CultureTestData();

            foreach (CultureInfo culture in cultures)
            {
                foreach (CalendarWeekRule weekRule in Enum.GetValues(typeof(CalendarWeekRule)))
                {
                    culture.DateTimeFormat.CalendarWeekRule = weekRule;

                    int year;
                    int weekOfYear;

                    // calendar week
                    TimeTool.GetWeekOfYear(now, culture, YearWeekType.Calendar, out year, out weekOfYear);
                    DateTime     weekStartCalendar = TimeTool.GetStartOfYearWeek(year, weekOfYear, culture, YearWeekType.Calendar);
                    TimeCalendar timeCalendar      = TimeCalendar.New(culture);
                    Assert.Equal <DateTime>(timeCalendar.GetStartOfYearWeek(year, weekOfYear), weekStartCalendar);

                    // iso 8601 calendar week
                    TimeTool.GetWeekOfYear(now, culture, YearWeekType.Iso8601, out year, out weekOfYear);
                    DateTime     weekStartCalendarIso8601 = TimeTool.GetStartOfYearWeek(year, weekOfYear, culture, YearWeekType.Iso8601);
                    TimeCalendar timeCalendarIso8601      = TimeCalendar.New(culture, YearMonth.January, YearWeekType.Iso8601);
                    Assert.Equal <DateTime>(timeCalendarIso8601.GetStartOfYearWeek(year, weekOfYear), weekStartCalendarIso8601);
                }
            }
        }         // GetStartOfWeekTest