< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 129
Coverable lines: 129
Total lines: 216
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%110%
GetYearInfo(...)0%440%
GetYear(...)100%110%
GetGregorianYear(...)100%110%
TrimEras(...)0%880%
.ctor()100%110%
GetEra(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseLunisolarCalendar.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4namespace System.Globalization
 5{
 6    /// <remarks>
 7    /// Calendar support range:
 8    ///     Calendar               Minimum             Maximum
 9    ///     ==========             ==========          ==========
 10    ///     Gregorian              1960/01/28          2050/01/22
 11    ///     JapaneseLunisolar      1960/01/01          2049/12/29
 12    /// </remarks>
 13    public class JapaneseLunisolarCalendar : EastAsianLunisolarCalendar
 14    {
 15        public const int JapaneseEra = 1;
 16
 17        private readonly GregorianCalendarHelper _helper;
 18
 19        private const int MinLunisolarYear = 1960;
 20        private const int MaxLunisolarYear = 2049;
 21
 022        private static readonly DateTime s_minDate = new DateTime(1960, 1, 28);
 023        private static readonly DateTime s_maxDate = new DateTime((new DateTime(2050, 1, 22, 23, 59, 59, 999)).Ticks + 9
 24
 025        public override DateTime MinSupportedDateTime => s_minDate;
 26
 027        public override DateTime MaxSupportedDateTime => s_maxDate;
 28
 29        protected override int DaysInYearBeforeMinSupportedYear =>
 30            // 1959 from ChineseLunisolarCalendar
 031            354;
 32
 33        // Data for years 1960-2049 matches output of Calendrical Calculations [1] and published calendar tables [2].
 34        // [1] Reingold, Edward M, and Nachum Dershowitz. Calendrical Calculations: The Ultimate Edition. Cambridge [etc
 35        // [2] Nishizawa, Yu\u0304so\u0304. Rekijitsu Taikan: Meiji Kaireki 1873-Nen-2100-Nen Shinkyu\u0304reki, Kanshi 
 036        private static readonly int[,] s_yinfo =
 037        {
 038/*Y           LM  Lmon  Lday    DaysPerMonth               D1   D2   D3   D4   D5   D6   D7   D8   D9   D10  D11  D12  D
 0391960     */ { 06,   01,   28,   0b1010110101010000 }, /*   30   29   30   29   30   30   29   30   29   30   29   30   2
 0401961     */ { 00,   02,   15,   0b1010101101010000 }, /*   30   29   30   29   30   29   30   30   29   30   29   30    
 0411962     */ { 00,   02,   05,   0b0100101101100000 }, /*   29   30   29   29   30   29   30   30   29   30   30   29    
 0421963     */ { 04,   01,   25,   0b1010010101110000 }, /*   30   29   30   29   29   30   29   30   29   30   30   30   2
 0431964     */ { 00,   02,   13,   0b1010010101110000 }, /*   30   29   30   29   29   30   29   30   29   30   30   30    
 0441965     */ { 00,   02,   02,   0b0101001001110000 }, /*   29   30   29   30   29   29   30   29   29   30   30   30    
 0451966     */ { 03,   01,   22,   0b0110100100110000 }, /*   29   30   30   29   30   29   29   30   29   29   30   30   2
 0461967     */ { 00,   02,   09,   0b1101100101010000 }, /*   30   30   29   30   30   29   29   30   29   30   29   30    
 0471968     */ { 07,   01,   30,   0b0110101010101000 }, /*   29   30   30   29   30   29   30   29   30   29   30   29   3
 0481969     */ { 00,   02,   17,   0b0101011010100000 }, /*   29   30   29   30   29   30   30   29   30   29   30   29    
 0491970     */ { 00,   02,   06,   0b1001101011010000 }, /*   30   29   29   30   30   29   30   29   30   30   29   30    
 0501971     */ { 05,   01,   27,   0b0100101011101000 }, /*   29   30   29   29   30   29   30   29   30   30   30   29   3
 0511972     */ { 00,   02,   15,   0b0100101011100000 }, /*   29   30   29   29   30   29   30   29   30   30   30   29    
 0521973     */ { 00,   02,   03,   0b1010010011100000 }, /*   30   29   30   29   29   30   29   29   30   30   30   29    
 0531974     */ { 04,   01,   23,   0b1101001001101000 }, /*   30   30   29   30   29   29   30   29   29   30   30   29   3
 0541975     */ { 00,   02,   11,   0b1101001001010000 }, /*   30   30   29   30   29   29   30   29   29   30   29   30    
 0551976     */ { 08,   01,   31,   0b1101010101001000 }, /*   30   30   29   30   29   30   29   30   29   30   29   29   3
 0561977     */ { 00,   02,   18,   0b1011010101000000 }, /*   30   29   30   30   29   30   29   30   29   30   29   29    
 0571978     */ { 00,   02,   07,   0b1101011010100000 }, /*   30   30   29   30   29   30   30   29   30   29   30   29    
 0581979     */ { 06,   01,   28,   0b1001011011010000 }, /*   30   29   29   30   29   30   30   29   30   30   29   30   2
 0591980     */ { 00,   02,   16,   0b1001010110110000 }, /*   30   29   29   30   29   30   29   30   30   29   30   30    
 0601981     */ { 00,   02,   05,   0b0100100110110000 }, /*   29   30   29   29   30   29   29   30   30   29   30   30    
 0611982     */ { 04,   01,   25,   0b1010010011011000 }, /*   30   29   30   29   29   30   29   29   30   30   29   30   3
 0621983     */ { 00,   02,   13,   0b1010010010110000 }, /*   30   29   30   29   29   30   29   29   30   29   30   30    
 0631984     */ { 10,   02,   02,   0b1011001001011000 }, /*   30   29   30   30   29   29   30   29   29   30   29   30   3
 0641985     */ { 00,   02,   20,   0b0110101001010000 }, /*   29   30   30   29   30   29   30   29   29   30   29   30    
 0651986     */ { 00,   02,   09,   0b0110110101000000 }, /*   29   30   30   29   30   30   29   30   29   30   29   29    
 0661987     */ { 06,   01,   29,   0b1011010110101000 }, /*   30   29   30   30   29   30   29   30   30   29   30   29   3
 0671988     */ { 00,   02,   18,   0b0010101101100000 }, /*   29   29   30   29   30   29   30   30   29   30   30   29    
 0681989     */ { 00,   02,   06,   0b1001010110110000 }, /*   30   29   29   30   29   30   29   30   30   29   30   30    
 0691990     */ { 05,   01,   27,   0b0100100110111000 }, /*   29   30   29   29   30   29   29   30   30   29   30   30   3
 0701991     */ { 00,   02,   15,   0b0100100101110000 }, /*   29   30   29   29   30   29   29   30   29   30   30   30    
 0711992     */ { 00,   02,   04,   0b0110010010110000 }, /*   29   30   30   29   29   30   29   29   30   29   30   30    
 0721993     */ { 03,   01,   23,   0b0110101001010000 }, /*   29   30   30   29   30   29   30   29   29   30   29   30   2
 0731994     */ { 00,   02,   10,   0b1110101001010000 }, /*   30   30   30   29   30   29   30   29   29   30   29   30    
 0741995     */ { 08,   01,   31,   0b0110110101001000 }, /*   29   30   30   29   30   30   29   30   29   30   29   29   3
 0751996     */ { 00,   02,   19,   0b0101101011010000 }, /*   29   30   29   30   30   29   30   29   30   30   29   30    
 0761997     */ { 00,   02,   08,   0b0010101101100000 }, /*   29   29   30   29   30   29   30   30   29   30   30   29    
 0771998     */ { 05,   01,   28,   0b1001001101110000 }, /*   30   29   29   30   29   29   30   30   29   30   30   30   2
 0781999     */ { 00,   02,   16,   0b1001001011100000 }, /*   30   29   29   30   29   29   30   29   30   30   30   29    
 0792000     */ { 00,   02,   05,   0b1100100101100000 }, /*   30   30   29   29   30   29   29   30   29   30   30   29    
 0802001     */ { 04,   01,   24,   0b1110010010101000 }, /*   30   30   30   29   29   30   29   29   30   29   30   29   3
 0812002     */ { 00,   02,   12,   0b1101010010100000 }, /*   30   30   29   30   29   30   29   29   30   29   30   29    
 0822003     */ { 00,   02,   01,   0b1101101001010000 }, /*   30   30   29   30   30   29   30   29   29   30   29   30    
 0832004     */ { 02,   01,   22,   0b0101101010101000 }, /*   29   30   29   30   30   29   30   29   30   29   30   29   3
 0842005     */ { 00,   02,   09,   0b0101011011000000 }, /*   29   30   29   30   29   30   30   29   30   30   29   29    
 0852006     */ { 07,   01,   29,   0b1010101011011000 }, /*   30   29   30   29   30   29   30   29   30   30   29   30   3
 0862007     */ { 00,   02,   18,   0b0010010111010000 }, /*   29   29   30   29   29   30   29   30   30   30   29   30    
 0872008     */ { 00,   02,   07,   0b1001001011010000 }, /*   30   29   29   30   29   29   30   29   30   30   29   30    
 0882009     */ { 05,   01,   26,   0b1100100101011000 }, /*   30   30   29   29   30   29   29   30   29   30   29   30   3
 0892010     */ { 00,   02,   14,   0b1010100101010000 }, /*   30   29   30   29   30   29   29   30   29   30   29   30    
 0902011     */ { 00,   02,   03,   0b1011010010100000 }, /*   30   29   30   30   29   30   29   29   30   29   30   29    
 0912012     */ { 03,   01,   23,   0b1011101001010000 }, /*   30   29   30   30   30   29   30   29   29   30   29   30   2
 0922013     */ { 00,   02,   10,   0b1011010101010000 }, /*   30   29   30   30   29   30   29   30   29   30   29   30    
 0932014     */ { 09,   01,   31,   0b0101010110101000 }, /*   29   30   29   30   29   30   29   30   30   29   30   29   3
 0942015     */ { 00,   02,   19,   0b0100101110100000 }, /*   29   30   29   29   30   29   30   30   30   29   30   29    
 0952016     */ { 00,   02,   08,   0b1010010110110000 }, /*   30   29   30   29   29   30   29   30   30   29   30   30    
 0962017     */ { 05,   01,   28,   0b0101001010111000 }, /*   29   30   29   30   29   29   30   29   30   29   30   30   3
 0972018     */ { 00,   02,   16,   0b0101001010110000 }, /*   29   30   29   30   29   29   30   29   30   29   30   30    
 0982019     */ { 00,   02,   05,   0b1010100101010000 }, /*   30   29   30   29   30   29   29   30   29   30   29   30    
 0992020     */ { 04,   01,   25,   0b1011010010101000 }, /*   30   29   30   30   29   30   29   29   30   29   30   29   3
 01002021     */ { 00,   02,   12,   0b0110101010100000 }, /*   29   30   30   29   30   29   30   29   30   29   30   29    
 01012022     */ { 00,   02,   01,   0b1010110101010000 }, /*   30   29   30   29   30   30   29   30   29   30   29   30    
 01022023     */ { 02,   01,   22,   0b0101010110101000 }, /*   29   30   29   30   29   30   29   30   30   29   30   29   3
 01032024     */ { 00,   02,   10,   0b0100101101100000 }, /*   29   30   29   29   30   29   30   30   29   30   30   29    
 01042025     */ { 06,   01,   29,   0b1010010101110000 }, /*   30   29   30   29   29   30   29   30   29   30   30   30   2
 01052026     */ { 00,   02,   17,   0b1010010101110000 }, /*   30   29   30   29   29   30   29   30   29   30   30   30    
 01062027     */ { 00,   02,   07,   0b0101001001110000 }, /*   29   30   29   30   29   29   30   29   29   30   30   30    
 01072028     */ { 05,   01,   27,   0b0110100100110000 }, /*   29   30   30   29   30   29   29   30   29   29   30   30   2
 01082029     */ { 00,   02,   13,   0b1101100100110000 }, /*   30   30   29   30   30   29   29   30   29   29   30   30    
 01092030     */ { 00,   02,   03,   0b0101101010100000 }, /*   29   30   29   30   30   29   30   29   30   29   30   29    
 01102031     */ { 03,   01,   23,   0b1010101101010000 }, /*   30   29   30   29   30   29   30   30   29   30   29   30   2
 01112032     */ { 00,   02,   11,   0b1001011011010000 }, /*   30   29   29   30   29   30   30   29   30   30   29   30    
 01122033     */ { 11,   01,   31,   0b0100101011101000 }, /*   29   30   29   29   30   29   30   29   30   30   30   29   3
 01132034     */ { 00,   02,   19,   0b0100101011100000 }, /*   29   30   29   29   30   29   30   29   30   30   30   29    
 01142035     */ { 00,   02,   08,   0b1010010011010000 }, /*   30   29   30   29   29   30   29   29   30   30   29   30    
 01152036     */ { 06,   01,   28,   0b1101001001101000 }, /*   30   30   29   30   29   29   30   29   29   30   30   29   3
 01162037     */ { 00,   02,   15,   0b1101001001010000 }, /*   30   30   29   30   29   29   30   29   29   30   29   30    
 01172038     */ { 00,   02,   04,   0b1101010100100000 }, /*   30   30   29   30   29   30   29   30   29   29   30   29    
 01182039     */ { 05,   01,   24,   0b1101101010100000 }, /*   30   30   29   30   30   29   30   29   30   29   30   29   2
 01192040     */ { 00,   02,   12,   0b1011011010100000 }, /*   30   29   30   30   29   30   30   29   30   29   30   29    
 01202041     */ { 00,   02,   01,   0b1001011011010000 }, /*   30   29   29   30   29   30   30   29   30   30   29   30    
 01212042     */ { 02,   01,   22,   0b0100101011011000 }, /*   29   30   29   29   30   29   30   29   30   30   29   30   3
 01222043     */ { 00,   02,   10,   0b0100100110110000 }, /*   29   30   29   29   30   29   29   30   30   29   30   30    
 01232044     */ { 07,   01,   30,   0b1010010010111000 }, /*   30   29   30   29   29   30   29   29   30   29   30   30   3
 01242045     */ { 00,   02,   17,   0b1010010010110000 }, /*   30   29   30   29   29   30   29   29   30   29   30   30    
 01252046     */ { 00,   02,   06,   0b1011001001010000 }, /*   30   29   30   30   29   29   30   29   29   30   29   30    
 01262047     */ { 05,   01,   26,   0b1011010100101000 }, /*   30   29   30   30   29   30   29   30   29   29   30   29   3
 01272048     */ { 00,   02,   14,   0b0110110101000000 }, /*   29   30   30   29   30   30   29   30   29   30   29   29    
 01282049     */ { 00,   02,   02,   0b1010110110100000 }, /*   30   29   30   29   30   30   29   30   30   29   30   29    
 0129         */ };
 130
 0131        internal override int MinCalendarYear => MinLunisolarYear;
 132
 0133        internal override int MaxCalendarYear => MaxLunisolarYear;
 134
 0135        internal override DateTime MinDate => s_minDate;
 136
 0137        internal override DateTime MaxDate => s_maxDate;
 138
 0139        internal override EraInfo[]? CalEraInfo => JapaneseCalendar.GetEraInfo();
 140
 141        internal override int GetYearInfo(int lunarYear, int index)
 142        {
 0143            if (lunarYear < MinLunisolarYear || lunarYear > MaxLunisolarYear)
 144            {
 0145                throw new ArgumentOutOfRangeException(
 0146                    "year",
 0147                    lunarYear,
 0148                    SR.Format(SR.ArgumentOutOfRange_Range, MinLunisolarYear, MaxLunisolarYear));
 149            }
 150
 0151            return s_yinfo[lunarYear - MinLunisolarYear, index];
 152        }
 153
 154        internal override int GetYear(int year, DateTime time)
 155        {
 0156            return _helper.GetYear(year, time);
 157        }
 158
 159        internal override int GetGregorianYear(int year, int era)
 160        {
 0161            return _helper.GetGregorianYear(year, era);
 162        }
 163
 164        /// <summary>
 165        /// Trim off the eras that are before our date range
 166        /// </summary>
 167        private static EraInfo[] TrimEras(EraInfo[] baseEras)
 168        {
 0169            EraInfo[] newEras = new EraInfo[baseEras.Length];
 0170            int newIndex = 0;
 171
 172            // Eras have most recent first, so start with that
 0173            for (int i = 0; i < baseEras.Length; i++)
 174            {
 175                // If this one's minimum year is bigger than our maximum year
 176                // then we can't use it.
 0177                if (baseEras[i].yearOffset + baseEras[i].minEraYear >= MaxLunisolarYear)
 178                {
 179                    // skip this one.
 180                    continue;
 181                }
 182
 183                // If this one's maximum era is less than our minimum era
 184                // then we've gotten too low in the era #s, so we're done
 0185                if (baseEras[i].yearOffset + baseEras[i].maxEraYear < MinLunisolarYear)
 186                {
 187                    break;
 188                }
 189
 190                // Wasn't too large or too small, can use this one
 0191                newEras[newIndex] = baseEras[i];
 0192                newIndex++;
 193            }
 194
 195            // If we didn't copy any then something was wrong, just return base
 0196            if (newIndex == 0) return baseEras;
 197
 0198            Array.Resize(ref newEras, newIndex);
 0199            return newEras;
 200        }
 201
 0202        public JapaneseLunisolarCalendar()
 203        {
 0204            _helper = new GregorianCalendarHelper(this, TrimEras(JapaneseCalendar.GetEraInfo()));
 0205        }
 206
 0207        public override int GetEra(DateTime time) => _helper.GetEra(time);
 208
 0209        internal override CalendarId BaseCalendarID => CalendarId.JAPAN;
 210
 0211        internal override CalendarId ID => CalendarId.JAPANESELUNISOLAR;
 212
 0213        public override int[] Eras => _helper.Eras;
 214    }
 215}
 216