예제 #1
0
        public void DefaultCalendarTest()
        {
            const int startWeek   = 1;
            var       currentTime = ClockProxy.Clock.Now;
            var       currentYear = ClockProxy.Clock.Now.Year;

            Action <CultureInfo> @weekRangeTestAction =
                (culture) => {
                foreach (WeekOfYearRuleKind yearWeekType in WeekOfYearRules)
                {
                    var yearWeek = WeekTool.GetYearAndWeek(currentTime, culture, yearWeekType);

                    for (int weekOfYear = startWeek; weekOfYear < yearWeek.Week; weekOfYear++)
                    {
                        var week = new WeekRange(currentYear, weekOfYear, TimeCalendar.New(culture, 1, yearWeekType));
                        week.Year.Should().Be(currentYear);

                        var weekStart = WeekTool.GetWeekRange(new YearAndWeek(currentYear, weekOfYear), culture, yearWeekType).Start;
                        var weekEnd   = weekStart.AddDays(TimeSpec.DaysPerWeek);

                        week.UnmappedStart.Should().Be(weekStart);
                        week.UnmappedEnd.Should().Be(weekEnd);
                    }
                }
            };

            Parallel.For(0, CultureTestData.Default.Count(), i => @weekRangeTestAction(CultureTestData.Default[i]));

            //!++ BUG:Silverlight 용 Paralell.ForEach 에 버그가 있습니다.
            // Parallel.ForEach(CultureTestData.Default.Cultures, @weekRangeTestAction);
        }
예제 #2
0
        private static TimeRange GetPeriodOf(int year, int weekOfYear, int weekCount, ITimeCalendar timeCalendar)
        {
            weekCount.ShouldBePositive("weekCount");

            var startWeek = WeekTool.GetWeekRange(new YearAndWeek(year, weekOfYear), timeCalendar.Culture, timeCalendar.WeekOfYearRule);

            var startDay = startWeek.Start;
            var endDay   = startDay.AddDays(weekCount * TimeSpec.DaysPerWeek);

            return(new TimeRange(startDay, endDay));
        }
예제 #3
0
        public void GetWeekRangeTest()
        {
            Parallel.For(0, CultureTestData.Default.Count(),
                         i => {
                var currentCulture = CultureTestData.Default[i];

                Enumerable
                .Range(2000, 20)
                .RunEach(year => {
                    var endDay   = (year - 1).GetEndOfYear();
                    var startDay = year.GetStartOfYear();

                    var endDayYearWeek = WeekTool.GetYearAndWeek(endDay, currentCulture);
                    Assert.IsTrue(endDayYearWeek.Year >= year - 1);

                    var startDayYearWeek = WeekTool.GetYearAndWeek(startDay, currentCulture);
                    Assert.IsTrue(startDayYearWeek.Year <= year);

                    // 해당일자가 속한 주차의 일자들을 구한다. 년말/년초 구간은 꼭 7일이 아닐 수 있다.
                    //
                    var endDayWeekRange   = WeekTool.GetWeekRange(endDayYearWeek, currentCulture);
                    var startDayWeekRange = WeekTool.GetWeekRange(startDayYearWeek, currentCulture);

                    Assert.IsTrue(endDayWeekRange.HasPeriod);
                    Assert.IsTrue(startDayWeekRange.HasPeriod);

                    if (IsDebugEnabled)
                    {
                        log.Debug("Start Day Weeks = " + startDayWeekRange);
                    }

                    if (endDayYearWeek == startDayYearWeek)
                    {
                        Assert.AreEqual(endDayWeekRange,
                                        startDayWeekRange,
                                        @"culture={0}, End={1}, Start={2}, EndOfWeek={3}, StartOfWeek={4}",
                                        currentCulture, endDayWeekRange, startDayWeekRange, endDayYearWeek,
                                        startDayYearWeek);
                    }
                    else
                    {
                        Assert.AreNotEqual(endDayWeekRange,
                                           startDayWeekRange,
                                           @"culture={0}, End={1}, Start={2}, EndOfWeek={3}, StartOfWeek={4}",
                                           currentCulture, endDayWeekRange, startDayWeekRange, endDayYearWeek,
                                           startDayYearWeek);
                    }
                });
            });

            var rule = WeekOfYearRuleKind.Iso8601;

            Parallel.For(2000, 2020,
                         year => {
                var endDay   = (year - 1).GetEndOfYear();
                var startDay = year.GetStartOfYear();

                var endDayYearWeek = WeekTool.GetYearAndWeek(endDay, null, rule);
                Assert.IsTrue(endDayYearWeek.Year >= year - 1);

                var startDayYearWeek = WeekTool.GetYearAndWeek(startDay, null, rule);
                Assert.IsTrue(startDayYearWeek.Year <= year);

                // 해당일자가 속한 주차의 일자들을 구한다. 년말/년초 구간은 꼭 7일이 아닐 수 있다.
                //
                var endDayWeekRange   = WeekTool.GetWeekRange(endDayYearWeek, null, rule);
                var startDayWeekRange = WeekTool.GetWeekRange(startDayYearWeek, null, rule);

                Assert.IsTrue(endDayWeekRange.HasPeriod);
                Assert.IsTrue(startDayWeekRange.HasPeriod);

                if (IsDebugEnabled)
                {
                    log.Debug("Start Day Weeks = " + startDayWeekRange);
                }

                if (endDayYearWeek == startDayYearWeek)
                {
                    Assert.AreEqual(endDayWeekRange,
                                    startDayWeekRange,
                                    @"rule={0}, End={1}, Start={2}, EndOfWeek={3}, StartOfWeek={4}",
                                    rule, endDayWeekRange, startDayWeekRange, endDayYearWeek, startDayYearWeek);
                }
                else
                {
                    Assert.AreNotEqual(endDayWeekRange,
                                       startDayWeekRange,
                                       @"rule={0}, End={1}, Start={2}, EndOfWeek={3}, StartOfWeek={4}",
                                       rule, endDayWeekRange, startDayWeekRange, endDayYearWeek, startDayYearWeek);
                }
            });
        }