Exemplo n.º 1
0
        /// <inheritdoc />
        public int GetWeeksInWeekYear(int weekYear, CalendarSystem calendar)
        {
            Preconditions.CheckNotNull(calendar, nameof(calendar));
            YearMonthDayCalculator yearMonthDayCalculator = calendar.YearMonthDayCalculator;

            ValidateWeekYear(weekYear, calendar);
            unchecked
            {
                int startOfWeekYear     = GetWeekYearDaysSinceEpoch(yearMonthDayCalculator, weekYear);
                int startOfCalendarYear = yearMonthDayCalculator.GetStartOfYearInDays(weekYear);
                // The number of days gained or lost in the week year compared with the calendar year.
                // So if the week year starts on December 31st of the previous calendar year, this will be +1.
                // If the week year starts on January 2nd of this calendar year, this will be -1.
                int extraDaysAtStart = startOfCalendarYear - startOfWeekYear;

                // At the end of the year, we may have some extra days too.
                // In a non-regular rule, we just round up, so assume we effectively have 6 extra days.
                // In a regular rule, there can be at most minDaysInFirstWeek - 1 days "borrowed"
                // from the following year - because if there were any more, those days would be in the
                // the following year instead.
                int extraDaysAtEnd = irregularWeeks ? 6 : minDaysInFirstWeek - 1;

                int daysInThisYear = yearMonthDayCalculator.GetDaysInYear(weekYear);

                // We can have up to "minDaysInFirstWeek - 1" days of the next year, too.
                return((daysInThisYear + extraDaysAtStart + extraDaysAtEnd) / 7);
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public int GetWeeksInWeekYear(int weekYear, [NotNull] CalendarSystem calendar)
        {
            Preconditions.CheckNotNull(calendar, nameof(calendar));
            YearMonthDayCalculator yearMonthDayCalculator = calendar.YearMonthDayCalculator;

            ValidateWeekYear(weekYear, calendar);
            unchecked
            {
                int startOfWeekYear     = GetWeekYearDaysSinceEpoch(yearMonthDayCalculator, weekYear);
                int startOfCalendarYear = yearMonthDayCalculator.GetStartOfYearInDays(weekYear);
                // The number of days gained or lost in the week year compared with the calendar year.
                // So if the week year starts on December 31st of the previous calendar year, this will be +1.
                // If the week year starts on January 2nd of this calendar year, this will be -1.
                int extraDaysAtStart = startOfCalendarYear - startOfWeekYear;

                // At the end of the year, we may have some extra days too.
                // In a non-regular rule, we just round up, so assume we effectively have 6 extra days.
                // TODO: Explain the reasoning for the regular rule part. I know it works, I just
                // don't know why.
                int extraDaysAtEnd = irregularWeeks ? 6: minDaysInFirstWeek - 1;

                int daysInThisYear = yearMonthDayCalculator.GetDaysInYear(weekYear);

                // We can have up to "minDaysInFirstWeek - 1" days of the next year, too.
                return((daysInThisYear + extraDaysAtStart + extraDaysAtEnd) / 7);
            }
        }
Exemplo n.º 3
0
        private int GetWeeksInWeekYear(int weekYear)
        {
            long startOfWeekYear     = GetWeekYearTicks(weekYear);
            long startOfCalendarYear = yearMonthDayCalculator.GetStartOfYearInTicks(weekYear);
            // The number of days gained or lost in the week year compared with the calendar year.
            // So if the week year starts on December 31st of the previous calendar year, this will be +1.
            // If the week year starts on January 2nd of this calendar year, this will be -1.

            int extraDays      = (int)((startOfCalendarYear - startOfWeekYear) / NodaConstants.TicksPerStandardDay);
            int daysInThisYear = yearMonthDayCalculator.GetDaysInYear(weekYear);

            // We can have up to "minDaysInFirstWeek - 1" days of the next year, too.
            return((daysInThisYear + extraDays + (minDaysInFirstWeek - 1)) / 7);
        }
Exemplo n.º 4
0
        private int GetWeeksInWeekYear([Trusted] int weekYear)
        {
            unchecked
            {
                int startOfWeekYear     = GetWeekYearDaysSinceEpoch(weekYear);
                int startOfCalendarYear = yearMonthDayCalculator.GetStartOfYearInDays(weekYear);
                // The number of days gained or lost in the week year compared with the calendar year.
                // So if the week year starts on December 31st of the previous calendar year, this will be +1.
                // If the week year starts on January 2nd of this calendar year, this will be -1.

                int extraDays      = startOfCalendarYear - startOfWeekYear;
                int daysInThisYear = yearMonthDayCalculator.GetDaysInYear(weekYear);

                // We can have up to "minDaysInFirstWeek - 1" days of the next year, too.
                return((daysInThisYear + extraDays + (minDaysInFirstWeek - 1)) / 7);
            }
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public int GetWeeksInWeekYear(int weekYear, [NotNull] CalendarSystem calendar)
        {
            Preconditions.CheckNotNull(calendar, nameof(calendar));
            YearMonthDayCalculator yearMonthDayCalculator = calendar.YearMonthDayCalculator;

            ValidateWeekYear(weekYear, calendar);
            unchecked
            {
                int startOfWeekYear     = GetWeekYearDaysSinceEpoch(yearMonthDayCalculator, weekYear);
                int startOfCalendarYear = yearMonthDayCalculator.GetStartOfYearInDays(weekYear);
                // The number of days gained or lost in the week year compared with the calendar year.
                // So if the week year starts on December 31st of the previous calendar year, this will be +1.
                // If the week year starts on January 2nd of this calendar year, this will be -1.

                int extraDays      = startOfCalendarYear - startOfWeekYear;
                int daysInThisYear = yearMonthDayCalculator.GetDaysInYear(weekYear);

                // We can have up to "minDaysInFirstWeek - 1" days of the next year, too.
                return((daysInThisYear + extraDays + (minDaysInFirstWeek - 1)) / 7);
            }
        }