Exemplo n.º 1
0
        public void BclEquivalence(
            [ValueSource(typeof(BclCalendars), nameof(BclCalendars.MappedCalendars))] Calendar calendar,
            [ValueSource(nameof(CalendarWeekRules))] CalendarWeekRule bclRule,
            [ValueSource(nameof(BclDaysOfWeek))] DayOfWeek firstDayOfWeek)
        {
            var nodaCalendar = BclCalendars.CalendarSystemForCalendar(calendar);
            var nodaRule     = WeekYearRules.FromCalendarWeekRule(bclRule, firstDayOfWeek);
            var startYear    = new LocalDate(2016, 1, 1).WithCalendar(nodaCalendar).Year;

            for (int year = startYear; year < startYear + 30; year++)
            {
                var startDate = new LocalDate(year, 1, 1, nodaCalendar).PlusDays(-15);
                for (int day = 0; day < 30; day++)
                {
                    var date    = startDate.PlusDays(day);
                    var bclDate = date.ToDateTimeUnspecified();
                    var bclWeek = calendar.GetWeekOfYear(bclDate, bclRule, firstDayOfWeek);
                    // Weird... the BCL doesn't have a way of finding out which week-year we're in.
                    // We're starting at "start of year - 15 days", so a "small" week-of-year
                    // value means we're in "year", whereas a "large" week-of-year value means
                    // we're in the "year-1".
                    var bclWeekYear = bclWeek < 10 ? year : year - 1;

                    Assert.AreEqual(bclWeek, nodaRule.GetWeekOfWeekYear(date), "Date: {0}", date);
                    Assert.AreEqual(bclWeekYear, nodaRule.GetWeekYear(date), "Date: {0}", date);
                    Assert.AreEqual(date, nodaRule.GetLocalDate(bclWeekYear, bclWeek, date.IsoDayOfWeek, nodaCalendar),
                                    "Week-year:{0}; Week: {1}; Day: {2}", bclWeekYear, bclWeek, date.IsoDayOfWeek);
                }
            }
        }
Exemplo n.º 2
0
        public void BclThroughHistory()
        {
            Calendar       bcl  = BclCalendars.Persian;
            CalendarSystem noda = BclCalendars.CalendarSystemForCalendar(bcl);

            // Note: Noda Time stops in 9377, whereas the BCL goes into the start of 9378. This is because
            // Noda Time ensures that the whole year is valid.
            BclEquivalenceHelper.AssertEquivalent(bcl, noda);
        }
Exemplo n.º 3
0
        public void GetWeeksInWeekYear(
            [ValueSource(typeof(BclCalendars), nameof(BclCalendars.MappedCalendars))] Calendar calendar,
            [ValueSource(nameof(CalendarWeekRules))] CalendarWeekRule bclRule,
            [ValueSource(nameof(BclDaysOfWeek))] DayOfWeek firstDayOfWeek)
        {
            var nodaCalendar = BclCalendars.CalendarSystemForCalendar(calendar);
            var nodaRule     = WeekYearRules.FromCalendarWeekRule(bclRule, firstDayOfWeek);
            var startYear    = new LocalDate(2016, 1, 1).WithCalendar(nodaCalendar).Year;

            for (int year = startYear; year < startYear + 30; year++)
            {
                var bclDate = new LocalDate(year + 1, 1, 1, nodaCalendar).PlusDays(-1).ToDateTimeUnspecified();
                Assert.AreEqual(calendar.GetWeekOfYear(bclDate, bclRule, firstDayOfWeek),
                                nodaRule.GetWeeksInWeekYear(year, nodaCalendar), "Year {0}", year);
            }
        }