Example #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);
        }
Example #2
0
 protected WeekTimeRange(ITimePeriod period, ITimeCalendar timeCalendar)
     : base(period, timeCalendar)
 {
     Year      = period.Start.Year;
     StartWeek = WeekTool.GetYearAndWeek(period.Start, timeCalendar.Culture).Week ?? 1;
     WeekCount = 1;
 }
Example #3
0
        public void GetYearAndWeekByIso8601(int year, int month, int day, int weekYear, int week)
        {
            var moment      = new DateTime(year, month, day);
            var yearAndWeek = WeekTool.GetYearAndWeek(moment, null, WeekOfYearRuleKind.Iso8601);

            Assert.AreEqual(weekYear, yearAndWeek.Year);
            Assert.AreEqual(week, yearAndWeek.Week);
        }
Example #4
0
        protected WeekTimeRange(DateTime moment, int weekCount, ITimeCalendar timeTimeCalendar)
            : base(GetPeriodOf(moment, weekCount, timeTimeCalendar), timeTimeCalendar)
        {
            var yearAndWeek = WeekTool.GetYearAndWeek(moment, timeTimeCalendar);

            Year      = yearAndWeek.Year ?? 0;
            StartWeek = yearAndWeek.Week ?? 1;
            WeekCount = weekCount;
        }
Example #5
0
        public void GetYearAndWeekTest()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("ko-KR");
            var rule = WeekOfYearRuleKind.Calendar;
            CalendarWeekRule weekRule;
            DayOfWeek        firstDayOfWeek;

            foreach (var culture in CultureTestData.Default.Cultures)
            {
                var currentCulture = culture;
                WeekTool.GetCalendarWeekRuleAndFirstDayOfWeek(currentCulture, rule, out weekRule, out firstDayOfWeek);

                if (IsDebugEnabled)
                {
                    log.Debug("WeekOfYearRule=[{0}], CalendarWeekRule=[{1}], FirstDayOfWeek=[{2}]", rule, weekRule, firstDayOfWeek);
                }


                CalendarWeekRule weekRule1       = weekRule;
                DayOfWeek        firstDayOfWeek1 = firstDayOfWeek;

                Parallel.For(2000, 2100,
                             year => {
                    var startDay = TimeTool.StartTimeOfYear(year);
                    var endDay   = startDay.Add(TimeSpec.MinNegativeDuration);

                    var startDayYearAndWeek = WeekTool.GetYearAndWeek(startDay, currentCulture);
                    var endDayYearAndWeek   = WeekTool.GetYearAndWeek(endDay, currentCulture);

                    if (IsDebugEnabled)
                    {
                        log.Debug("{0},{1} ==> End:{2} Start:{3}", endDay, startDay, endDayYearAndWeek, startDayYearAndWeek);
                    }


                    // 새해 첫날은 무조건 첫 주가 된다.
                    if (weekRule1 == CalendarWeekRule.FirstDay)
                    {
                        Assert.AreNotEqual(endDayYearAndWeek, startDayYearAndWeek);
                    }
                    else if (weekRule1 == CalendarWeekRule.FirstFullWeek)
                    {
                        if (startDay.DayOfWeek == firstDayOfWeek1)
                        {
                            Assert.AreNotEqual(endDayYearAndWeek, startDayYearAndWeek);
                        }
                        else
                        {
                            Assert.AreEqual(endDayYearAndWeek, startDayYearAndWeek);
                        }
                    }
                    else if (weekRule1 == CalendarWeekRule.FirstFourDayWeek)
                    {
                        if (startDay.DayOfWeek == firstDayOfWeek1)
                        {
                            Assert.AreNotEqual(endDayYearAndWeek, startDayYearAndWeek);
                        }
                        //else
                        //    Assert.AreEqual(endDayYearAndWeek, startDayYearAndWeek,
                        //                    "endDay=[{0}], startDay=[{1}], culture=[{2}]",
                        //                    endDayYearAndWeek, startDayYearAndWeek, currentCulture);
                    }
                });
            }

            rule = WeekOfYearRuleKind.Iso8601;
            WeekTool.GetCalendarWeekRuleAndFirstDayOfWeek(CultureInfo.CurrentCulture, rule, out weekRule, out firstDayOfWeek);


            Parallel.For(2000, 2100,
                         year => {
                var startDay = TimeTool.StartTimeOfYear(year);
                var endDay   = startDay.Add(TimeSpec.MinNegativeDuration);

                var startDayYearAndWeek = WeekTool.GetYearAndWeek(startDay, null, rule);
                var endDayYearAndWeek   = WeekTool.GetYearAndWeek(endDay, null, rule);

                if (IsDebugEnabled)
                {
                    log.Debug("{0},{1} ==> End:{2} Start:{3}", endDay, startDay, endDayYearAndWeek, startDayYearAndWeek);
                }


                if (startDay.DayOfWeek == firstDayOfWeek)
                {
                    Assert.AreNotEqual(endDayYearAndWeek, startDayYearAndWeek);
                }
                else
                {
                    Assert.AreEqual(endDayYearAndWeek, startDayYearAndWeek);
                }
            });
        }
Example #6
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);
                }
            });
        }