Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Value of TwoDigitYearMax to 2049 #76848

Merged
merged 17 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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().
/// </summary>
public virtual int TwoDigitYearMax
{
Expand All @@ -667,9 +668,9 @@ public virtual int TwoDigitYearMax

/// <summary>
/// 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.
/// </summary>
public virtual int ToFourDigitYear(int year)
{
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
danmoseley marked this conversation as resolved.
Show resolved Hide resolved

public override int TwoDigitYearMax
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down