diff options
Diffstat (limited to 'src/mscorlib/corefx/System/Globalization/Calendar.cs')
-rw-r--r-- | src/mscorlib/corefx/System/Globalization/Calendar.cs | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/src/mscorlib/corefx/System/Globalization/Calendar.cs b/src/mscorlib/corefx/System/Globalization/Calendar.cs index 343682d156..78e9f00d08 100644 --- a/src/mscorlib/corefx/System/Globalization/Calendar.cs +++ b/src/mscorlib/corefx/System/Globalization/Calendar.cs @@ -2,9 +2,7 @@ // 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; -using System.Runtime.CompilerServices; -using System.Globalization; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.Serialization; @@ -99,8 +97,14 @@ namespace System.Globalization } } - - + [System.Runtime.InteropServices.ComVisible(false)] + public virtual CalendarAlgorithmType AlgorithmType + { + get + { + return CalendarAlgorithmType.Unknown; + } + } protected Calendar() { @@ -164,9 +168,9 @@ namespace System.Globalization // //////////////////////////////////////////////////////////////////////// [System.Runtime.InteropServices.ComVisible(false)] - internal static Calendar ReadOnly(Calendar calendar) + public static Calendar ReadOnly(Calendar calendar) { - if (calendar == null) { throw new ArgumentNullException("calendar"); } + if (calendar == null) { throw new ArgumentNullException(nameof(calendar)); } Contract.EndContractBlock(); if (calendar.IsReadOnly) { return (calendar); } @@ -206,7 +210,7 @@ namespace System.Globalization // The following code assumes that the current era value can not be -1. if (_currentEraValue == -1) { - Contract.Assert(BaseCalendarID != CalendarId.UNINITIALIZED_VALUE, "[Calendar.CurrentEraValue] Expected a real calendar ID"); + Debug.Assert(BaseCalendarID != CalendarId.UNINITIALIZED_VALUE, "[Calendar.CurrentEraValue] Expected a real calendar ID"); _currentEraValue = CalendarData.GetCalendarData(BaseCalendarID).iCurrentEra; } return (_currentEraValue); @@ -242,7 +246,7 @@ namespace System.Globalization double tempMillis = (value * scale + (value >= 0 ? 0.5 : -0.5)); if (!((tempMillis > -(double)MaxMillis) && (tempMillis < (double)MaxMillis))) { - throw new ArgumentOutOfRangeException("value", SR.ArgumentOutOfRange_AddValue); + throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_AddValue); } long millis = (long)tempMillis; @@ -521,7 +525,7 @@ namespace System.Globalization // this value can be less than 0. It's fine since we are making it positive again in calculating offset. int dayForJan1 = (int)GetDayOfWeek(time) - (dayOfYear % 7); int offset = (dayForJan1 - firstDayOfWeek + 14) % 7; - Contract.Assert(offset >= 0, "Calendar.GetFirstDayWeekOfYear(): offset >= 0"); + Debug.Assert(offset >= 0, "Calendar.GetFirstDayWeekOfYear(): offset >= 0"); return ((dayOfYear + offset) / 7 + 1); } @@ -646,7 +650,7 @@ namespace System.Globalization if ((int)firstDayOfWeek < 0 || (int)firstDayOfWeek > 6) { throw new ArgumentOutOfRangeException( - "firstDayOfWeek", SR.Format(SR.ArgumentOutOfRange_Range, + nameof(firstDayOfWeek), SR.Format(SR.ArgumentOutOfRange_Range, DayOfWeek.Sunday, DayOfWeek.Saturday)); } Contract.EndContractBlock(); @@ -660,7 +664,7 @@ namespace System.Globalization return (GetWeekOfYearFullDays(time, (int)firstDayOfWeek, 4)); } throw new ArgumentOutOfRangeException( - "rule", SR.Format(SR.ArgumentOutOfRange_Range, + nameof(rule), SR.Format(SR.ArgumentOutOfRange_Range, CalendarWeekRule.FirstDay, CalendarWeekRule.FirstFourDayWeek)); } @@ -700,6 +704,16 @@ namespace System.Globalization public abstract bool IsLeapMonth(int year, int month, int era); + // Returns the leap month in a calendar year of the current era. This method returns 0 + // if this calendar does not have leap month, or this year is not a leap year. + // + + [System.Runtime.InteropServices.ComVisible(false)] + public virtual int GetLeapMonth(int year) + { + return (GetLeapMonth(year, CurrentEra)); + } + // Returns the leap month in a calendar year of the specified era. This method returns 0 // if this calendar does not have leap month, or this year is not a leap year. // @@ -808,7 +822,7 @@ namespace System.Globalization { if (year < 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), SR.ArgumentOutOfRange_NeedNonNegNum); } Contract.EndContractBlock(); @@ -830,7 +844,7 @@ namespace System.Globalization if (millisecond < 0 || millisecond >= MillisPerSecond) { throw new ArgumentOutOfRangeException( - "millisecond", + nameof(millisecond), String.Format( CultureInfo.InvariantCulture, SR.Format(SR.ArgumentOutOfRange_Range, 0, MillisPerSecond - 1))); |