From ebf4ea7601f82cdc3f7cb9e7539a84e423d0d23a Mon Sep 17 00:00:00 2001 From: Connor Bullard <32420624+cdbullard@users.noreply.github.com> Date: Sat, 22 Oct 2022 18:22:58 -0400 Subject: [PATCH] Update Value of TwoDigitYearMax to 2049 (#76848) Co-authored-by: Dan Moseley --- .../ThaiBuddhistCalendarToFourDigitYear.cs | 4 ++-- .../src/System/Globalization/Calendar.cs | 17 +++++++++-------- .../System/Globalization/CalendarData.Icu.cs | 9 --------- .../System/Globalization/CalendarData.Nls.cs | 12 ------------ .../System/Globalization/CalendarData.Unix.cs | 13 ++++++++++++- .../Globalization/CalendarData.Windows.cs | 12 ++++++++++++ .../src/System/Globalization/CalendarData.cs | 5 ++--- .../Globalization/EastAsianLunisolarCalendar.cs | 2 +- .../System/Globalization/GregorianCalendar.cs | 2 +- .../src/System/Globalization/JulianCalendar.cs | 2 +- 10 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/libraries/System.Globalization.Calendars/tests/ThaiBuddhistCalendar/ThaiBuddhistCalendarToFourDigitYear.cs b/src/libraries/System.Globalization.Calendars/tests/ThaiBuddhistCalendar/ThaiBuddhistCalendarToFourDigitYear.cs index a80fd1e40dc6c..efec0263fc531 100644 --- a/src/libraries/System.Globalization.Calendars/tests/ThaiBuddhistCalendar/ThaiBuddhistCalendarToFourDigitYear.cs +++ b/src/libraries/System.Globalization.Calendars/tests/ThaiBuddhistCalendar/ThaiBuddhistCalendarToFourDigitYear.cs @@ -16,12 +16,12 @@ public class ThaiBuddhistCalendarToFourDigitYear public void ToFourDigitYear(int year) { ThaiBuddhistCalendar calendar = new ThaiBuddhistCalendar(); - calendar.TwoDigitYearMax = 2029; + calendar.TwoDigitYearMax = 2049; if (year > 99) { Assert.Equal(year, calendar.ToFourDigitYear(year)); } - else if (year > 29) + else if (year > 49) { Assert.Equal(year + 1900, calendar.ToFourDigitYear(year)); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/Calendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/Calendar.cs index a24facc1ea19a..ed7a1844b3f82 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/Calendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/Calendar.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Runtime.InteropServices; namespace System.Globalization { @@ -650,10 +651,10 @@ internal virtual bool IsValidDay(int year, int month, int day, int era) /// Returns and assigns the maximum value to represent a two digit year. /// This value is the upper boundary of a 100 year range that allows a /// two digit year to be properly translated to a four digit year. - /// For example, if 2029 is the upper boundary, then a two digit value of - /// 30 should be interpreted as 1930 while a two digit value of 29 should - /// be interpreted as 2029. In this example, the 100 year range would be - /// from 1930-2029. See ToFourDigitYear(). + /// For example, if 2049 is the upper boundary, then a two digit value of + /// 30 should be interpreted as 1950 while a two digit value of 49 should + /// be interpreted as 2049. In this example, the 100 year range would be + /// from 1950-2049. See ToFourDigitYear(). /// public virtual int TwoDigitYearMax { @@ -667,9 +668,9 @@ public virtual int TwoDigitYearMax /// /// Converts the year value to the appropriate century by using the - /// TwoDigitYearMax property. For example, if the TwoDigitYearMax value is 2029, - /// then a two digit value of 30 will get converted to 1930 while a two digit - /// value of 29 will get converted to 2029. + /// TwoDigitYearMax property. For example, if the TwoDigitYearMax value is 2049, + /// then a two digit value of 50 will get converted to 1950 while a two digit + /// value of 49 will get converted to 2049. /// public virtual int ToFourDigitYear(int year) { @@ -711,7 +712,7 @@ internal static long TimeToTicks(int hour, int minute, int second, int milliseco internal static int GetSystemTwoDigitYearSetting(CalendarId CalID, int defaultYearValue) { - int twoDigitYearMax = GlobalizationMode.UseNls ? CalendarData.NlsGetTwoDigitYearMax(CalID) : CalendarData.IcuGetTwoDigitYearMax(); + int twoDigitYearMax = CalendarData.GetTwoDigitYearMax(CalID); return twoDigitYearMax >= 0 ? twoDigitYearMax : defaultYearValue; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs index 77ceddee9662a..7be936a58c505 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs @@ -81,15 +81,6 @@ private bool IcuLoadCalendarDataFromSystem(string localeName, CalendarId calenda return result; } - internal static int IcuGetTwoDigitYearMax() - { - Debug.Assert(!GlobalizationMode.UseNls); - - // There is no user override for this value on Linux or in ICU. - // So just return -1 to use the hard-coded defaults. - return -1; - } - // Call native side to figure out which calendars are allowed internal static int IcuGetCalendars(string localeName, CalendarId[] calendars) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Nls.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Nls.cs index 3c1cc9d4d291e..5753747a80bc7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Nls.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Nls.cs @@ -10,17 +10,6 @@ namespace System.Globalization { internal sealed partial class CalendarData { - // Get native two digit year max - internal static int NlsGetTwoDigitYearMax(CalendarId calendarId) - { - Debug.Assert(GlobalizationMode.UseNls); - - return GlobalizationMode.Invariant ? Invariant.iTwoDigitYearMax : - CallGetCalendarInfoEx(null, calendarId, CAL_ITWODIGITYEARMAX, out int twoDigitYearMax) ? - twoDigitYearMax : - -1; - } - private static bool NlsSystemSupportsTaiwaneseCalendar() { Debug.Assert(!GlobalizationMode.Invariant); @@ -34,7 +23,6 @@ private static bool NlsSystemSupportsTaiwaneseCalendar() private const uint CAL_RETURN_NUMBER = 0x20000000; private const uint CAL_SCALNAME = 0x00000002; - private const uint CAL_ITWODIGITYEARMAX = 0x00000030; private static bool CallGetCalendarInfoEx(string? localeName, CalendarId calendar, uint calType, out int data) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs index fede23f8e2576..140b6484e3041 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics; + namespace System.Globalization { internal sealed partial class CalendarData @@ -12,5 +14,14 @@ private bool LoadCalendarDataFromSystemCore(string localeName, CalendarId calend internal static int GetCalendarsCore(string localeName, bool useUserOverride, CalendarId[] calendars) => IcuGetCalendars(localeName, calendars); #pragma warning restore IDE0060 - } + + internal static int GetTwoDigitYearMax(CalendarId calendarId) + { + Debug.Assert(!GlobalizationMode.UseNls); + + // There is no user override for this value on Linux or in ICU. + // So just return -1 to use the hard-coded defaults. + return GlobalizationMode.Invariant ? Invariant.iTwoDigitYearMax : -1; + } + } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Windows.cs index bf787bb66bf36..917b60fe350f3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Windows.cs @@ -23,6 +23,7 @@ internal sealed partial class CalendarData private const uint CAL_SSHORTESTDAYNAME7 = 0x00000037; private const uint CAL_SERASTRING = 0x00000004; private const uint CAL_SABBREVERASTRING = 0x00000039; + private const uint CAL_ITWODIGITYEARMAX = 0x00000030; private const uint ENUM_ALL_CALENDARS = 0xffffffff; @@ -426,5 +427,16 @@ private static int NlsGetCalendars(string localeName, bool useUserOverride, Cale // Now we have a list of data, return the count return data.calendars.Count; } + + // Get native two digit year max + internal static int GetTwoDigitYearMax(CalendarId calendarId) + { + Debug.Assert(GlobalizationMode.UseNls); + + return GlobalizationMode.Invariant ? Invariant.iTwoDigitYearMax : + CallGetCalendarInfoEx(null, calendarId, CAL_ITWODIGITYEARMAX, out int twoDigitYearMax) ? + twoDigitYearMax : + -1; + } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.cs index 35e493adcbc9f..fa1662b1f5979 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.cs @@ -39,8 +39,7 @@ internal sealed partial class CalendarData internal string[] saAbbrevMonthGenitiveNames = null!; // Genitive Abbrev Month Names (13) internal string[] saLeapYearMonthNames = null!; // Multiple strings for the month names in a leap year. - // Integers at end to make marshaller happier - internal int iTwoDigitYearMax = 2029; // Max 2 digit year (for Y2K bug data entry) + internal int iTwoDigitYearMax = 2049; // Max 2 digit year private int iCurrentEra; // current era # (usually 1) // Use overrides? @@ -66,7 +65,7 @@ private static CalendarData CreateInvariant() invariant.sNativeName = "Gregorian Calendar"; // Calendar Name // Year - invariant.iTwoDigitYearMax = 2029; // Max 2 digit year (for Y2K bug data entry) + invariant.iTwoDigitYearMax = 2049; // Max 2 digit year invariant.iCurrentEra = 1; // Current era # // Formats diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/EastAsianLunisolarCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/EastAsianLunisolarCalendar.cs index 73322a6570a72..6e5a322c6d1cb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/EastAsianLunisolarCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/EastAsianLunisolarCalendar.cs @@ -646,7 +646,7 @@ public override bool IsLeapYear(int year, int era) return InternalIsLeapYear(year); } - private const int DefaultGregorianTwoDigitYearMax = 2029; + private const int DefaultGregorianTwoDigitYearMax = 2049; public override int TwoDigitYearMax { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/GregorianCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/GregorianCalendar.cs index e883c8e3772ad..bc49fb7b37f73 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/GregorianCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/GregorianCalendar.cs @@ -406,7 +406,7 @@ internal override bool TryToDateTime(int year, int month, int day, int hour, int return DateTime.TryCreate(year, month, day, hour, minute, second, millisecond, out result); } - private const int DefaultTwoDigitYearMax = 2029; + private const int DefaultTwoDigitYearMax = 2049; public override int TwoDigitYearMax { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/JulianCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/JulianCalendar.cs index c7f13158a326c..d81f1ca00382a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/JulianCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/JulianCalendar.cs @@ -54,7 +54,7 @@ public class JulianCalendar : Calendar public JulianCalendar() { // There is no system setting of TwoDigitYear max, so set the value here. - _twoDigitYearMax = 2029; + _twoDigitYearMax = 2049; } internal override CalendarId ID => CalendarId.JULIAN;