summaryrefslogtreecommitdiff
path: root/src/mscorlib/shared/System/Globalization/EastAsianLunisolarCalendar.cs
blob: d06b13cd7d62416e4eb6cefdd7a53e7494a1aae0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics.Contracts;

namespace System.Globalization
{
    [Serializable]
    public abstract class EastAsianLunisolarCalendar : Calendar
    {
        internal const int LeapMonth = 0;
        internal const int Jan1Month = 1;
        internal const int Jan1Date = 2;
        internal const int nDaysPerMonth = 3;

        // # of days so far in the solar year
        internal static readonly int[] DaysToMonth365 =
        {
            0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
        };

        internal static readonly int[] DaysToMonth366 =
        {
            0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335
        };

        internal const int DatePartYear = 0;
        internal const int DatePartDayOfYear = 1;
        internal const int DatePartMonth = 2;
        internal const int DatePartDay = 3;

        public override CalendarAlgorithmType AlgorithmType
        {
            get
            {
                return CalendarAlgorithmType.LunisolarCalendar;
            }
        }

        // Return the year number in the 60-year cycle.
        //

        public virtual int GetSexagenaryYear(DateTime time)
        {
            CheckTicksRange(time.Ticks);

            int year = 0, month = 0, day = 0;
            TimeToLunar(time, ref year, ref month, ref day);

            return ((year - 4) % 60) + 1;
        }

        // Return the celestial year from the 60-year cycle.
        // The returned value is from 1 ~ 10.
        //

        public int GetCelestialStem(int sexagenaryYear)
        {
            if ((sexagenaryYear < 1) || (sexagenaryYear > 60))
            {
                throw new ArgumentOutOfRangeException(
                                nameof(sexagenaryYear),
                                SR.Format(SR.ArgumentOutOfRange_Range, 1, 60));
            }
            Contract.EndContractBlock();

            return ((sexagenaryYear - 1) % 10) + 1;
        }

        // Return the Terrestial Branch from the the 60-year cycle.
        // The returned value is from 1 ~ 12.
        //

        public int GetTerrestrialBranch(int sexagenaryYear)
        {
            if ((sexagenaryYear < 1) || (sexagenaryYear > 60))
            {
                throw new ArgumentOutOfRangeException(
                                nameof(sexagenaryYear),
                                SR.Format(SR.ArgumentOutOfRange_Range, 1, 60));
            }
            Contract.EndContractBlock();

            return ((sexagenaryYear - 1) % 12) + 1;
        }

        internal abstract int GetYearInfo(int LunarYear, int Index);
        internal abstract int GetYear(int year, DateTime time);
        internal abstract int GetGregorianYear(int year, int era);

        internal abstract int MinCalendarYear { get; }
        internal abstract int MaxCalendarYear { get; }
        internal abstract EraInfo[] CalEraInfo { get; }
        internal abstract DateTime MinDate { get; }
        internal abstract DateTime MaxDate { get; }

        internal const int MaxCalendarMonth = 13;
        internal const int MaxCalendarDay = 30;

        internal int MinEraCalendarYear(int era)
        {
            EraInfo[] mEraInfo = CalEraInfo;
            //ChineseLunisolarCalendar does not has m_EraInfo it is going to retuen null
            if (mEraInfo == null)
            {
                return MinCalendarYear;
            }

            if (era == Calendar.CurrentEra)
            {
                era = CurrentEraValue;
            }
            //era has to be in the supported range otherwise we will throw exception in CheckEraRange()
            if (era == GetEra(MinDate))
            {
                return (GetYear(MinCalendarYear, MinDate));
            }

            for (int i = 0; i < mEraInfo.Length; i++)
            {
                if (era == mEraInfo[i].era)
                {
                    return (mEraInfo[i].minEraYear);
                }
            }
            throw new ArgumentOutOfRangeException(nameof(era), SR.ArgumentOutOfRange_InvalidEraValue);
        }

        internal int MaxEraCalendarYear(int era)
        {
            EraInfo[] mEraInfo = CalEraInfo;
            //ChineseLunisolarCalendar does not has m_EraInfo it is going to retuen null
            if (mEraInfo == null)
            {
                return MaxCalendarYear;
            }

            if (era == Calendar.CurrentEra)
            {
                era = CurrentEraValue;
            }
            //era has to be in the supported range otherwise we will throw exception in CheckEraRange()
            if (era == GetEra(MaxDate))
            {
                return (GetYear(MaxCalendarYear, MaxDate));
            }

            for (int i = 0; i < mEraInfo.Length; i++)
            {
                if (era == mEraInfo[i].era)
                {
                    return (mEraInfo[i].maxEraYear);
                }
            }
            throw new ArgumentOutOfRangeException(nameof(era), SR.ArgumentOutOfRange_InvalidEraValue);
        }

        internal EastAsianLunisolarCalendar()
        {
        }

        internal void CheckTicksRange(long ticks)
        {
            if (ticks < MinSupportedDateTime.Ticks || ticks > MaxSupportedDateTime.Ticks)
            {
                throw new ArgumentOutOfRangeException(
                                "time",
                                String.Format(CultureInfo.InvariantCulture, SR.ArgumentOutOfRange_CalendarRange,
                                MinSupportedDateTime, MaxSupportedDateTime));
            }
            Contract.EndContractBlock();
        }

        internal void CheckEraRange(int era)
        {
            if (era == Calendar.CurrentEra)
            {
                era = CurrentEraValue;
            }

            if ((era < GetEra(MinDate)) || (era > GetEra(MaxDate)))
            {
                throw new ArgumentOutOfRangeException(nameof(era), SR.ArgumentOutOfRange_InvalidEraValue);
            }
        }

        internal int CheckYearRange(int year, int era)
        {
            CheckEraRange(era);
            year = GetGregorianYear(year, era);

            if ((year < MinCalendarYear) || (year > MaxCalendarYear))
            {
                throw new ArgumentOutOfRangeException(
                                nameof(year),
                                SR.Format(SR.ArgumentOutOfRange_Range, MinEraCalendarYear(era), MaxEraCalendarYear(era)));
            }
            return year;
        }

        internal int CheckYearMonthRange(int year, int month, int era)
        {
            year = CheckYearRange(year, era);

            if (month == 13)
            {
                //Reject if there is no leap month this year
                if (GetYearInfo(year, LeapMonth) == 0)
                    throw new ArgumentOutOfRangeException(nameof(month), SR.ArgumentOutOfRange_Month);
            }

            if (month < 1 || month > 13)
            {
                throw new ArgumentOutOfRangeException(nameof(month), SR.ArgumentOutOfRange_Month);
            }
            return year;
        }

        internal int InternalGetDaysInMonth(int year, int month)
        {
            int nDays;
            int mask;        // mask for extracting bits

            mask = 0x8000;
            // convert the lunar day into a lunar month/date
            mask >>= (month - 1);
            if ((GetYearInfo(year, nDaysPerMonth) & mask) == 0)
                nDays = 29;
            else
                nDays = 30;
            return nDays;
        }

        // Returns the number of days in the month given by the year and
        // month arguments.
        //

        public override int GetDaysInMonth(int year, int month, int era)
        {
            year = CheckYearMonthRange(year, month, era);
            return InternalGetDaysInMonth(year, month);
        }

        private static int GregorianIsLeapYear(int y)
        {
            return ((((y) % 4) != 0) ? 0 : ((((y) % 100) != 0) ? 1 : ((((y) % 400) != 0) ? 0 : 1)));
        }

        // Returns the date and time converted to a DateTime value.  Throws an exception if the n-tuple is invalid.
        //

        public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
        {
            year = CheckYearMonthRange(year, month, era);
            int daysInMonth = InternalGetDaysInMonth(year, month);
            if (day < 1 || day > daysInMonth)
            {
                throw new ArgumentOutOfRangeException(
                            nameof(day),
                            SR.Format(SR.ArgumentOutOfRange_Day, daysInMonth, month));
            }

            int gy = 0; int gm = 0; int gd = 0;

            if (LunarToGregorian(year, month, day, ref gy, ref gm, ref gd))
            {
                return new DateTime(gy, gm, gd, hour, minute, second, millisecond);
            }
            else
            {
                throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadYearMonthDay);
            }
        }


        //
        // GregorianToLunar calculates lunar calendar info for the given gregorian year, month, date.
        // The input date should be validated before calling this method.
        //
        internal void GregorianToLunar(int nSYear, int nSMonth, int nSDate, ref int nLYear, ref int nLMonth, ref int nLDate)
        {
            //    unsigned int nLYear, nLMonth, nLDate;    // lunar ymd
            int nSolarDay;        // day # in solar year
            int nLunarDay;        // day # in lunar year
            int fLeap;                    // is it a solar leap year?
            int LDpM;        // lunar days/month bitfield
            int mask;        // mask for extracting bits
            int nDays;        // # days this lunar month
            int nJan1Month, nJan1Date;

            // calc the solar day of year
            fLeap = GregorianIsLeapYear(nSYear);
            nSolarDay = (fLeap == 1) ? DaysToMonth366[nSMonth - 1] : DaysToMonth365[nSMonth - 1];
            nSolarDay += nSDate;

            // init lunar year info
            nLunarDay = nSolarDay;
            nLYear = nSYear;
            if (nLYear == (MaxCalendarYear + 1))
            {
                nLYear--;
                nLunarDay += ((GregorianIsLeapYear(nLYear) == 1) ? 366 : 365);
                nJan1Month = GetYearInfo(nLYear, Jan1Month);
                nJan1Date = GetYearInfo(nLYear, Jan1Date);
            }
            else
            {
                nJan1Month = GetYearInfo(nLYear, Jan1Month);
                nJan1Date = GetYearInfo(nLYear, Jan1Date);

                // check if this solar date is actually part of the previous
                // lunar year
                if ((nSMonth < nJan1Month) ||
                    (nSMonth == nJan1Month && nSDate < nJan1Date))
                {
                    // the corresponding lunar day is actually part of the previous
                    // lunar year
                    nLYear--;

                    // add a solar year to the lunar day #
                    nLunarDay += ((GregorianIsLeapYear(nLYear) == 1) ? 366 : 365);

                    // update the new start of year
                    nJan1Month = GetYearInfo(nLYear, Jan1Month);
                    nJan1Date = GetYearInfo(nLYear, Jan1Date);
                }
            }

            // convert solar day into lunar day.
            // subtract off the beginning part of the solar year which is not
            // part of the lunar year.  since this part is always in Jan or Feb,
            // we don't need to handle Leap Year (LY only affects March
            // and later).
            nLunarDay -= DaysToMonth365[nJan1Month - 1];
            nLunarDay -= (nJan1Date - 1);

            // convert the lunar day into a lunar month/date
            mask = 0x8000;
            LDpM = GetYearInfo(nLYear, nDaysPerMonth);
            nDays = ((LDpM & mask) != 0) ? 30 : 29;
            nLMonth = 1;
            while (nLunarDay > nDays)
            {
                nLunarDay -= nDays;
                nLMonth++;
                mask >>= 1;
                nDays = ((LDpM & mask) != 0) ? 30 : 29;
            }
            nLDate = nLunarDay;
        }

        /*
        //Convert from Lunar to Gregorian
        //Highly inefficient, but it works based on the forward conversion
        */
        internal bool LunarToGregorian(int nLYear, int nLMonth, int nLDate, ref int nSolarYear, ref int nSolarMonth, ref int nSolarDay)
        {
            int numLunarDays;

            if (nLDate < 1 || nLDate > 30)
                return false;

            numLunarDays = nLDate - 1;

            //Add previous months days to form the total num of days from the first of the month.
            for (int i = 1; i < nLMonth; i++)
            {
                numLunarDays += InternalGetDaysInMonth(nLYear, i);
            }

            //Get Gregorian First of year
            int nJan1Month = GetYearInfo(nLYear, Jan1Month);
            int nJan1Date = GetYearInfo(nLYear, Jan1Date);

            // calc the solar day of year of 1 Lunar day
            int fLeap = GregorianIsLeapYear(nLYear);
            int[] days = (fLeap == 1) ? DaysToMonth366 : DaysToMonth365;

            nSolarDay = nJan1Date;

            if (nJan1Month > 1)
                nSolarDay += days[nJan1Month - 1];

            // Add the actual lunar day to get the solar day we want
            nSolarDay = nSolarDay + numLunarDays;// - 1;

            if (nSolarDay > (fLeap + 365))
            {
                nSolarYear = nLYear + 1;
                nSolarDay -= (fLeap + 365);
            }
            else
            {
                nSolarYear = nLYear;
            }

            for (nSolarMonth = 1; nSolarMonth < 12; nSolarMonth++)
            {
                if (days[nSolarMonth] >= nSolarDay)
                    break;
            }

            nSolarDay -= days[nSolarMonth - 1];
            return true;
        }

        internal DateTime LunarToTime(DateTime time, int year, int month, int day)
        {
            int gy = 0; int gm = 0; int gd = 0;
            LunarToGregorian(year, month, day, ref gy, ref gm, ref gd);
            return (GregorianCalendar.GetDefaultInstance().ToDateTime(gy, gm, gd, time.Hour, time.Minute, time.Second, time.Millisecond));
        }

        internal void TimeToLunar(DateTime time, ref int year, ref int month, ref int day)
        {
            int gy = 0; int gm = 0; int gd = 0;

            Calendar Greg = GregorianCalendar.GetDefaultInstance();
            gy = Greg.GetYear(time);
            gm = Greg.GetMonth(time);
            gd = Greg.GetDayOfMonth(time);

            GregorianToLunar(gy, gm, gd, ref year, ref month, ref day);
        }

        // Returns the DateTime resulting from adding the given number of
        // months to the specified DateTime. The result is computed by incrementing
        // (or decrementing) the year and month parts of the specified DateTime by
        // value months, and, if required, adjusting the day part of the
        // resulting date downwards to the last day of the resulting month in the
        // resulting year. The time-of-day part of the result is the same as the
        // time-of-day part of the specified DateTime.
        //

        public override DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException(
                            nameof(months),
                            SR.Format(SR.ArgumentOutOfRange_Range, -120000, 120000));
            }
            Contract.EndContractBlock();

            CheckTicksRange(time.Ticks);

            int y = 0; int m = 0; int d = 0;
            TimeToLunar(time, ref y, ref m, ref d);

            int i = m + months;
            if (i > 0)
            {
                int monthsInYear = InternalIsLeapYear(y) ? 13 : 12;

                while (i - monthsInYear > 0)
                {
                    i -= monthsInYear;
                    y++;
                    monthsInYear = InternalIsLeapYear(y) ? 13 : 12;
                }
                m = i;
            }
            else
            {
                int monthsInYear;
                while (i <= 0)
                {
                    monthsInYear = InternalIsLeapYear(y - 1) ? 13 : 12;
                    i += monthsInYear;
                    y--;
                }
                m = i;
            }

            int days = InternalGetDaysInMonth(y, m);
            if (d > days)
            {
                d = days;
            }
            DateTime dt = LunarToTime(time, y, m, d);

            CheckAddResult(dt.Ticks, MinSupportedDateTime, MaxSupportedDateTime);
            return (dt);
        }


        public override DateTime AddYears(DateTime time, int years)
        {
            CheckTicksRange(time.Ticks);

            int y = 0; int m = 0; int d = 0;
            TimeToLunar(time, ref y, ref m, ref d);

            y += years;

            if (m == 13 && !InternalIsLeapYear(y))
            {
                m = 12;
                d = InternalGetDaysInMonth(y, m);
            }
            int DaysInMonths = InternalGetDaysInMonth(y, m);
            if (d > DaysInMonths)
            {
                d = DaysInMonths;
            }

            DateTime dt = LunarToTime(time, y, m, d);
            CheckAddResult(dt.Ticks, MinSupportedDateTime, MaxSupportedDateTime);
            return (dt);
        }

        // Returns the day-of-year part of the specified DateTime. The returned value
        // is an integer between 1 and [354|355 |383|384].
        //

        public override int GetDayOfYear(DateTime time)
        {
            CheckTicksRange(time.Ticks);

            int y = 0; int m = 0; int d = 0;
            TimeToLunar(time, ref y, ref m, ref d);

            for (int i = 1; i < m; i++)
            {
                d = d + InternalGetDaysInMonth(y, i);
            }
            return d;
        }

        // Returns the day-of-month part of the specified DateTime. The returned
        // value is an integer between 1 and 29 or 30.
        //

        public override int GetDayOfMonth(DateTime time)
        {
            CheckTicksRange(time.Ticks);

            int y = 0; int m = 0; int d = 0;
            TimeToLunar(time, ref y, ref m, ref d);

            return d;
        }

        // Returns the number of days in the year given by the year argument for the current era.
        //

        public override int GetDaysInYear(int year, int era)
        {
            year = CheckYearRange(year, era);

            int Days = 0;
            int monthsInYear = InternalIsLeapYear(year) ? 13 : 12;

            while (monthsInYear != 0)
                Days += InternalGetDaysInMonth(year, monthsInYear--);

            return Days;
        }

        // Returns the month part of the specified DateTime. The returned value is an
        // integer between 1 and 13.
        //

        public override int GetMonth(DateTime time)
        {
            CheckTicksRange(time.Ticks);

            int y = 0; int m = 0; int d = 0;
            TimeToLunar(time, ref y, ref m, ref d);

            return m;
        }

        // Returns the year part of the specified DateTime. The returned value is an
        // integer between 1 and MaxCalendarYear.
        //

        public override int GetYear(DateTime time)
        {
            CheckTicksRange(time.Ticks);

            int y = 0; int m = 0; int d = 0;
            TimeToLunar(time, ref y, ref m, ref d);

            return GetYear(y, time);
        }

        // Returns the day-of-week part of the specified DateTime. The returned value
        // is an integer between 0 and 6, where 0 indicates Sunday, 1 indicates
        // Monday, 2 indicates Tuesday, 3 indicates Wednesday, 4 indicates
        // Thursday, 5 indicates Friday, and 6 indicates Saturday.
        //

        public override DayOfWeek GetDayOfWeek(DateTime time)
        {
            CheckTicksRange(time.Ticks);
            return ((DayOfWeek)((int)(time.Ticks / Calendar.TicksPerDay + 1) % 7));
        }

        // Returns the number of months in the specified year and era.

        public override int GetMonthsInYear(int year, int era)
        {
            year = CheckYearRange(year, era);
            return (InternalIsLeapYear(year) ? 13 : 12);
        }

        // Checks whether a given day in the specified era is a leap day. This method returns true if
        // the date is a leap day, or false if not.
        //

        public override bool IsLeapDay(int year, int month, int day, int era)
        {
            year = CheckYearMonthRange(year, month, era);
            int daysInMonth = InternalGetDaysInMonth(year, month);

            if (day < 1 || day > daysInMonth)
            {
                throw new ArgumentOutOfRangeException(
                            nameof(day),
                            SR.Format(SR.ArgumentOutOfRange_Day, daysInMonth, month));
            }
            int m = GetYearInfo(year, LeapMonth);
            return ((m != 0) && (month == (m + 1)));
        }

        // Checks whether a given month in the specified era is a leap month. This method returns true if
        // month is a leap month, or false if not.
        //

        public override bool IsLeapMonth(int year, int month, int era)
        {
            year = CheckYearMonthRange(year, month, era);
            int m = GetYearInfo(year, LeapMonth);
            return ((m != 0) && (month == (m + 1)));
        }

        // Returns  the leap month in a calendar year of the specified era. This method returns 0
        // if this this year is not a leap year.
        //

        public override int GetLeapMonth(int year, int era)
        {
            year = CheckYearRange(year, era);
            int month = GetYearInfo(year, LeapMonth);
            if (month > 0)
            {
                return (month + 1);
            }
            return 0;
        }

        internal bool InternalIsLeapYear(int year)
        {
            return (GetYearInfo(year, LeapMonth) != 0);
        }
        // Checks whether a given year in the specified era is a leap year. This method returns true if
        // year is a leap year, or false if not.
        //

        public override bool IsLeapYear(int year, int era)
        {
            year = CheckYearRange(year, era);
            return InternalIsLeapYear(year);
        }

        private const int DEFAULT_GREGORIAN_TWO_DIGIT_YEAR_MAX = 2029;


        public override int TwoDigitYearMax
        {
            get
            {
                if (twoDigitYearMax == -1)
                {
                    twoDigitYearMax = GetSystemTwoDigitYearSetting(BaseCalendarID, GetYear(new DateTime(DEFAULT_GREGORIAN_TWO_DIGIT_YEAR_MAX, 1, 1)));
                }
                return (twoDigitYearMax);
            }

            set
            {
                VerifyWritable();
                if (value < 99 || value > MaxCalendarYear)
                {
                    throw new ArgumentOutOfRangeException(
                                nameof(value),
                                SR.Format(SR.ArgumentOutOfRange_Range, 99, MaxCalendarYear));
                }
                twoDigitYearMax = value;
            }
        }


        public override int ToFourDigitYear(int year)
        {
            if (year < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(year),
                    SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            Contract.EndContractBlock();

            year = base.ToFourDigitYear(year);
            CheckYearRange(year, CurrentEra);
            return (year);
        }
    }
}