< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 49
Coverable lines: 49
Total lines: 189
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
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%
GetDefaultInstance()0%220%
.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/TaiwanCalendar.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    /// Taiwan calendar is based on the Gregorian calendar.  And the year is an offset to Gregorian calendar.
 8    /// That is,
 9    ///      Taiwan year = Gregorian year - 1911.  So 1912/01/01 A.D. is Taiwan 1/01/01
 10    /// </summary>
 11    /// <remarks>
 12    ///  Calendar support range:
 13    ///      Calendar    Minimum     Maximum
 14    ///      ==========  ==========  ==========
 15    ///      Gregorian   1912/01/01  9999/12/31
 16    ///      Taiwan      01/01/01    8088/12/31
 17    /// </remarks>
 18    public class TaiwanCalendar : Calendar
 19    {
 20        // Since
 21        //    Gregorian Year = Era Year + yearOffset
 22        // When Gregorian Year 1912 is year 1, so that
 23        //    1912 = 1 + yearOffset
 24        //  So yearOffset = 1911
 025        private static readonly EraInfo[] s_taiwanEraInfo =
 026        [
 027            new EraInfo(1, 1912, 1, 1, 1911, 1, GregorianCalendar.MaxYear - 1911)    // era #, start year/month/day, yea
 028        ];
 29
 30        private static Calendar? s_defaultInstance;
 31
 32        private readonly GregorianCalendarHelper _helper;
 33
 034        internal static Calendar GetDefaultInstance() => s_defaultInstance ??= new TaiwanCalendar();
 35
 036        private static readonly DateTime s_calendarMinValue = new DateTime(1912, 1, 1);
 37
 038        public override DateTime MinSupportedDateTime => s_calendarMinValue;
 39
 040        public override DateTime MaxSupportedDateTime => DateTime.MaxValue;
 41
 042        public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.SolarCalendar;
 43
 044        public TaiwanCalendar()
 45        {
 46            try
 47            {
 048                new CultureInfo("zh-TW");
 049            }
 050            catch (ArgumentException e)
 51            {
 052                throw new TypeInitializationException(GetType().ToString(), e);
 53            }
 54
 055            _helper = new GregorianCalendarHelper(this, s_taiwanEraInfo);
 056        }
 57
 058        internal override CalendarId ID => CalendarId.TAIWAN;
 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 = 99;
 148
 149        public override int TwoDigitYearMax
 150        {
 151            get
 152            {
 0153                if (_twoDigitYearMax == -1)
 154                {
 0155                    _twoDigitYearMax = GetSystemTwoDigitYearSetting(ID, DefaultTwoDigitYearMax);
 156                }
 157
 0158                return _twoDigitYearMax;
 159            }
 160            set
 161            {
 0162                VerifyWritable();
 0163                if (value < 99 || value > _helper.MaxYear)
 164                {
 0165                    throw new ArgumentOutOfRangeException(
 0166                        nameof(value),
 0167                        value,
 0168                        SR.Format(SR.ArgumentOutOfRange_Range, 99, _helper.MaxYear));
 169                }
 170
 0171                _twoDigitYearMax = value;
 0172            }
 173        }
 174
 175        /// <summary>
 176        /// For Taiwan calendar, four digit year is not used.
 177        /// Therefore, for any two digit number, we just return the original number.
 178        /// </summary>
 179
 180        public override int ToFourDigitYear(int year)
 181        {
 0182            ArgumentOutOfRangeException.ThrowIfNegativeOrZero(year);
 0183            ArgumentOutOfRangeException.ThrowIfGreaterThan(year, _helper.MaxYear);
 184
 0185            return year;
 186        }
 187    }
 188}
 189