< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 46
Coverable lines: 46
Total lines: 184
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
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%
.ctor()100%110%
AddMonths(...)100%110%
AddYears(...)100%110%
GetDaysInMonth(...)100%110%
GetDaysInYear(...)100%110%
GetDayOfMonth(...)100%110%
GetDayOfWeek(...)100%110%
GetDayOfYear(...)100%110%
GetMonthsInYear(...)100%110%
GetWeekOfYear(...)100%110%
GetEra(...)100%110%
GetMonth(...)100%110%
GetYear(...)100%110%
IsLeapDay(...)100%110%
IsLeapYear(...)100%110%
GetLeapMonth(...)100%110%
IsLeapMonth(...)100%110%
ToDateTime(...)100%110%
ToFourDigitYear(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.CoreLib/src/System/Globalization/KoreanCalendar.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    /// <summary>
 7    /// Korean calendar is based on the Gregorian calendar.  And the year is an offset to Gregorian calendar.
 8    /// That is,
 9    ///      Korean year = Gregorian year + 2333.  So 2000/01/01 A.D. is Korean 4333/01/01
 10    ///
 11    /// 0001/1/1 A.D. is Korean year 2334.
 12    /// </summary>
 13    /// <remarks>
 14    /// Calendar support range:
 15    ///     Calendar    Minimum     Maximum
 16    ///     ==========  ==========  ==========
 17    ///     Gregorian   0001/01/01   9999/12/31
 18    ///     Korean      2334/01/01  12332/12/31
 19    /// </remarks>
 20    public class KoreanCalendar : Calendar
 21    {
 22        public const int KoreanEra = 1;
 23
 24        // Since
 25        //    Gregorian Year = Era Year + yearOffset
 26        // Gregorian Year 1 is Korean year 2334, so that
 27        //    1 = 2334 + yearOffset
 28        //  So yearOffset = -2333
 29        // Gregorian year 2001 is Korean year 4334.
 030        private static readonly EraInfo[] s_koreanEraInfo =
 031        [
 032            new EraInfo(1, 1, 1, 1, -2333, 2334, GregorianCalendar.MaxYear + 2333)   // era #, start year/month/day, yea
 033        ];
 34
 35        private readonly GregorianCalendarHelper _helper;
 36
 037        public override DateTime MinSupportedDateTime => DateTime.MinValue;
 38
 039        public override DateTime MaxSupportedDateTime => DateTime.MaxValue;
 40
 041        public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.SolarCalendar;
 42
 043        public KoreanCalendar()
 44        {
 45            try
 46            {
 047                new CultureInfo("ko-KR");
 048            }
 049            catch (ArgumentException e)
 50            {
 051                throw new TypeInitializationException(GetType().ToString(), e);
 52            }
 53
 054            _helper = new GregorianCalendarHelper(this, s_koreanEraInfo);
 055        }
 56
 057        internal override CalendarId ID => CalendarId.KOREA;
 58
 59
 60        public override DateTime AddMonths(DateTime time, int months)
 61        {
 062            return _helper.AddMonths(time, months);
 63        }
 64
 65        public override DateTime AddYears(DateTime time, int years)
 66        {
 067            return _helper.AddYears(time, years);
 68        }
 69
 70        public override int GetDaysInMonth(int year, int month, int era)
 71        {
 072            return _helper.GetDaysInMonth(year, month, era);
 73        }
 74
 75        public override int GetDaysInYear(int year, int era)
 76        {
 077            return _helper.GetDaysInYear(year, era);
 78        }
 79
 80        public override int GetDayOfMonth(DateTime time)
 81        {
 082            return _helper.GetDayOfMonth(time);
 83        }
 84
 85        public override DayOfWeek GetDayOfWeek(DateTime time)
 86        {
 087            return _helper.GetDayOfWeek(time);
 88        }
 89
 90        public override int GetDayOfYear(DateTime time)
 91        {
 092            return _helper.GetDayOfYear(time);
 93        }
 94
 95        public override int GetMonthsInYear(int year, int era)
 96        {
 097            return _helper.GetMonthsInYear(year, era);
 98        }
 99
 100        public override int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
 101        {
 0102            return _helper.GetWeekOfYear(time, rule, firstDayOfWeek);
 103        }
 104
 105        public override int GetEra(DateTime time)
 106        {
 0107            return _helper.GetEra(time);
 108        }
 109
 110        public override int GetMonth(DateTime time)
 111        {
 0112            return _helper.GetMonth(time);
 113        }
 114
 115        public override int GetYear(DateTime time)
 116        {
 0117            return _helper.GetYear(time);
 118        }
 119
 120        public override bool IsLeapDay(int year, int month, int day, int era)
 121        {
 0122            return _helper.IsLeapDay(year, month, day, era);
 123        }
 124
 125        public override bool IsLeapYear(int year, int era)
 126        {
 0127            return _helper.IsLeapYear(year, era);
 128        }
 129
 130        public override int GetLeapMonth(int year, int era)
 131        {
 0132            return _helper.GetLeapMonth(year, era);
 133        }
 134
 135        public override bool IsLeapMonth(int year, int month, int era)
 136        {
 0137            return _helper.IsLeapMonth(year, month, era);
 138        }
 139
 140        public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisec
 141        {
 0142            return _helper.ToDateTime(year, month, day, hour, minute, second, millisecond, era);
 143        }
 144
 0145        public override int[] Eras => _helper.Eras;
 146
 147        private const int DefaultTwoDigitYearMax = 4362;
 148
 149
 150        public override int TwoDigitYearMax
 151        {
 152            get
 153            {
 0154                if (_twoDigitYearMax == -1)
 155                {
 0156                    _twoDigitYearMax = GetSystemTwoDigitYearSetting(ID, DefaultTwoDigitYearMax);
 157                }
 158
 0159                return _twoDigitYearMax;
 160            }
 161            set
 162            {
 0163                VerifyWritable();
 0164                if (value < 99 || value > _helper.MaxYear)
 165                {
 0166                    throw new ArgumentOutOfRangeException(
 0167                        nameof(value),
 0168                        value,
 0169                        SR.Format(SR.ArgumentOutOfRange_Range, 99, _helper.MaxYear));
 170                }
 171
 0172                _twoDigitYearMax = value;
 0173            }
 174        }
 175
 176        public override int ToFourDigitYear(int year)
 177        {
 0178            ArgumentOutOfRangeException.ThrowIfNegative(year);
 179
 0180            return _helper.ToFourDigitYear(year, TwoDigitYearMax);
 181        }
 182    }
 183}
 184