<commit_before>﻿// Copyright 2010 The Noda Time Authors. All rights reserved.
// Use of this source code is governed by the Apache License 2.0,
// as found in the LICENSE.txt file.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using JetBrains.Annotations;
using NodaTime.Annotations;
using NodaTime.Calendars;
using NodaTime.Utility;

namespace NodaTime
{
    /// <summary>
    /// A calendar system maps the non-calendar-specific "local time line" to human concepts
    /// such as years, months and days.
    /// </summary>
    /// <remarks>
    /// <para>
    /// Many developers will never need to touch this class, other than to potentially ask a calendar
    /// how many days are in a particular year/month and the like. Noda Time defaults to using the ISO-8601
    /// calendar anywhere that a calendar system is required but hasn't been explicitly specified.
    /// </para>
    /// <para>
    /// If you need to obtain a <see cref="CalendarSystem" /> instance, use one of the static properties or methods in this
    /// class, such as the <see cref="Iso" /> property or the <see cref="GetGregorianCalendar(int)" /> method.
    /// </para>
    /// <para>Although this class is currently sealed (as of Noda Time 1.2), in the future this decision may
    /// be reversed. In any case, there is no current intention for third-party developers to be able to implement
    /// their own calendar systems (for various reasons). If you require a calendar system which is not
    /// currently supported, please file a feature request and we'll see what we can do.
    /// </para>
    /// </remarks>
    /// <threadsafety>
    /// All calendar implementations are immutable and thread-safe. See the thread safety
    /// section of the user guide for more information.
    /// </threadsafety>
    [Immutable]
    public sealed class CalendarSystem
    {
        // TODO(2.0): Consider moving the static accessors into a separate class. As we get more calendars,
        // this approach will become unwieldy.

        #region Public factory members for calendars
        private const string GregorianName = "Gregorian";
        private const string IsoName = "ISO";
        private const string CopticName = "Coptic";
        private const string JulianName = "Julian";
        private const string IslamicName = "Hijri";
        private const string PersianName = "Persian";
        private const string HebrewName = "Hebrew";

        private static readonly CalendarSystem[] GregorianCalendarSystems;
        private static readonly CalendarSystem[] CopticCalendarSystems;
        private static readonly CalendarSystem[] JulianCalendarSystems;
        private static readonly CalendarSystem[,] IslamicCalendarSystems;
        private static readonly CalendarSystem IsoCalendarSystem;
        private static readonly CalendarSystem PersianCalendarSystem;
        private static readonly CalendarSystem[] HebrewCalendarSystems;

        static CalendarSystem()
        {
            IsoCalendarSystem = new CalendarSystem(IsoName, IsoName, new IsoYearMonthDayCalculator(), 4,
                new CalendarEra.BcCalendarEra(new YearMonthDay(-9998, 1, 1), true),
                new CalendarEra(Era.Common, new YearMonthDay(1, 1, 1), new YearMonthDay(9999, 12, 31), true));
            PersianCalendarSystem = new CalendarSystem(PersianName, PersianName, new PersianYearMonthDayCalculator(), Era.AnnoPersico);
            HebrewCalendarSystems = new[]
            {
                new CalendarSystem(HebrewName + "-Civil", HebrewName, new HebrewYearMonthDayCalculator(HebrewMonthNumbering.Civil), 4),
                new CalendarSystem(HebrewName + "-Scriptural", HebrewName, new HebrewYearMonthDayCalculator(HebrewMonthNumbering.Scriptural), 4)
            };

            // Variations for the calendar systems which have different objects for different "minimum first day of week"
            // values. These share eras and year/month/day calculators where appropriate.
            GregorianCalendarSystems = new CalendarSystem[7];
            CopticCalendarSystems = new CalendarSystem[7];
            JulianCalendarSystems = new CalendarSystem[7];
            var gregorianCalculator = new GregorianYearMonthDayCalculator();
            var copticCalculator = new CopticYearMonthDayCalculator();
            var julianCalculator = new JulianYearMonthDayCalculator();
            var copticEra = new CalendarEra(Era.AnnoMartyrum, GetStartOfCalendar(copticCalculator), GetEndOfCalendar(copticCalculator));
            var gregorianBeforeCommon = new CalendarEra.BcCalendarEra(GetStartOfCalendar(gregorianCalculator), false);
            var julianBeforeCommon = new CalendarEra.BcCalendarEra(GetStartOfCalendar(julianCalculator), false);
            var gregorianCommon = new CalendarEra(Era.Common, new YearMonthDay(1, 1, 1), GetEndOfCalendar(gregorianCalculator));
            var julianCommon = new CalendarEra(Era.Common, new YearMonthDay(1, 1, 1), GetEndOfCalendar(julianCalculator));
            for (int i = 1; i <= 7; i++)
            {
                GregorianCalendarSystems[i - 1] = new CalendarSystem(GregorianName, new GregorianYearMonthDayCalculator(), i, gregorianBeforeCommon, gregorianCommon);
                CopticCalendarSystems[i - 1] = new CalendarSystem(CopticName, new CopticYearMonthDayCalculator(), i, copticEra);
                JulianCalendarSystems[i - 1] = new CalendarSystem(JulianName, new JulianYearMonthDayCalculator(), i, julianBeforeCommon, julianCommon);
            }
            IslamicCalendarSystems = new CalendarSystem[4, 2];
            for (int i = 1; i <= 4; i++)
            {<commit_msg>Gah - looks like I put this fix in a different shelf...<commit_after>﻿// Copyright 2010 The Noda Time Authors. All rights reserved.
// Use of this source code is governed by the Apache License 2.0,
// as found in the LICENSE.txt file.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using JetBrains.Annotations;
using NodaTime.Annotations;
using NodaTime.Calendars;
using NodaTime.Utility;

namespace NodaTime
{
    /// <summary>
    /// A calendar system maps the non-calendar-specific "local time line" to human concepts
    /// such as years, months and days.
    /// </summary>
    /// <remarks>
    /// <para>
    /// Many developers will never need to touch this class, other than to potentially ask a calendar
    /// how many days are in a particular year/month and the like. Noda Time defaults to using the ISO-8601
    /// calendar anywhere that a calendar system is required but hasn't been explicitly specified.
    /// </para>
    /// <para>
    /// If you need to obtain a <see cref="CalendarSystem" /> instance, use one of the static properties or methods in this
    /// class, such as the <see cref="Iso" /> property or the <see cref="GetGregorianCalendar(int)" /> method.
    /// </para>
    /// <para>Although this class is currently sealed (as of Noda Time 1.2), in the future this decision may
    /// be reversed. In any case, there is no current intention for third-party developers to be able to implement
    /// their own calendar systems (for various reasons). If you require a calendar system which is not
    /// currently supported, please file a feature request and we'll see what we can do.
    /// </para>
    /// </remarks>
    /// <threadsafety>
    /// All calendar implementations are immutable and thread-safe. See the thread safety
    /// section of the user guide for more information.
    /// </threadsafety>
    [Immutable]
    public sealed class CalendarSystem
    {
        // TODO(2.0): Consider moving the static accessors into a separate class. As we get more calendars,
        // this approach will become unwieldy.

        #region Public factory members for calendars
        private const string GregorianName = "Gregorian";
        private const string IsoName = "ISO";
        private const string CopticName = "Coptic";
        private const string JulianName = "Julian";
        private const string IslamicName = "Hijri";
        private const string PersianName = "Persian";
        private const string HebrewName = "Hebrew";

        private static readonly CalendarSystem[] GregorianCalendarSystems;
        private static readonly CalendarSystem[] CopticCalendarSystems;
        private static readonly CalendarSystem[] JulianCalendarSystems;
        private static readonly CalendarSystem[,] IslamicCalendarSystems;
        private static readonly CalendarSystem IsoCalendarSystem;
        private static readonly CalendarSystem PersianCalendarSystem;
        private static readonly CalendarSystem[] HebrewCalendarSystems;

        static CalendarSystem()
        {
            IsoCalendarSystem = new CalendarSystem(IsoName, IsoName, new IsoYearMonthDayCalculator(), 4,
                new CalendarEra.BcCalendarEra(new YearMonthDay(-9998, 1, 1), true),
                new CalendarEra(Era.Common, new YearMonthDay(1, 1, 1), new YearMonthDay(9999, 12, 31), true));
            PersianCalendarSystem = new CalendarSystem(PersianName, PersianName, new PersianYearMonthDayCalculator(), Era.AnnoPersico);
            HebrewCalendarSystems = new[]
            {
                new CalendarSystem(HebrewName + "-Civil", HebrewName, new HebrewYearMonthDayCalculator(HebrewMonthNumbering.Civil), Era.AnnoMundi),
                new CalendarSystem(HebrewName + "-Scriptural", HebrewName, new HebrewYearMonthDayCalculator(HebrewMonthNumbering.Scriptural), Era.AnnoMundi)
            };

            // Variations for the calendar systems which have different objects for different "minimum first day of week"
            // values. These share eras and year/month/day calculators where appropriate.
            GregorianCalendarSystems = new CalendarSystem[7];
            CopticCalendarSystems = new CalendarSystem[7];
            JulianCalendarSystems = new CalendarSystem[7];
            var gregorianCalculator = new GregorianYearMonthDayCalculator();
            var copticCalculator = new CopticYearMonthDayCalculator();
            var julianCalculator = new JulianYearMonthDayCalculator();
            var copticEra = new CalendarEra(Era.AnnoMartyrum, GetStartOfCalendar(copticCalculator), GetEndOfCalendar(copticCalculator));
            var gregorianBeforeCommon = new CalendarEra.BcCalendarEra(GetStartOfCalendar(gregorianCalculator), false);
            var julianBeforeCommon = new CalendarEra.BcCalendarEra(GetStartOfCalendar(julianCalculator), false);
            var gregorianCommon = new CalendarEra(Era.Common, new YearMonthDay(1, 1, 1), GetEndOfCalendar(gregorianCalculator));
            var julianCommon = new CalendarEra(Era.Common, new YearMonthDay(1, 1, 1), GetEndOfCalendar(julianCalculator));
            for (int i = 1; i <= 7; i++)
            {
                GregorianCalendarSystems[i - 1] = new CalendarSystem(GregorianName, new GregorianYearMonthDayCalculator(), i, gregorianBeforeCommon, gregorianCommon);
                CopticCalendarSystems[i - 1] = new CalendarSystem(CopticName, new CopticYearMonthDayCalculator(), i, copticEra);
                JulianCalendarSystems[i - 1] = new CalendarSystem(JulianName, new JulianYearMonthDayCalculator(), i, julianBeforeCommon, julianCommon);
            }
            IslamicCalendarSystems = new CalendarSystem[4, 2];
            for (int i = 1; i <= 4; i++)
            {
{'fraction_non_alphanumeric': 0.08359240069084628, 'fraction_numerical': 0.008808290155440414, 'mean_word_length': 3.095120226308345, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4644770', 'n_tokens_mistral': 3216, 'n_tokens_neox': 2927, 'n_words': 1040}