Update Value of TwoDigitYearMax to 2049#76848
Update Value of TwoDigitYearMax to 2049#76848tarekgh merged 17 commits intodotnet:mainfrom cdbullard:twoyearvalue
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-globalization Issue DetailsFix #75148 Update the century assumption cutoff year for determining whether a year is referring to a 19XX date or a 20XX date from 2029 to 2049.
|
src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/EastAsianLunisolarCalendar.cs
Show resolved
Hide resolved
|
Tests are all under System.Globalization.Calendars. Search for "twodigityear" eg |
src/libraries/System.Globalization.Calendars/System.Globalization.Calendars.sln
Outdated
Show resolved
Hide resolved
|
Interestingly when I try to change this to 2049 and 2069, the unit test fails: @danmoseley Just wanted to leave a note, this section is giving me trouble with updating the unit tests (and others seem to cause similar issues, even with the updated code). Do you have any advice? |
src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.cs
Outdated
Show resolved
Hide resolved
|
build failures are fixed by #76860 |
|
I am not seeing any change to read the two digits max settings when running on Windows (when using ICU). I mean the code at Need to change. Instead of branching for and on none-Windows we'll do Usually, we can have these two different implementations in |
|
some extra context here @cdbullard, although you probably know
This has info on how to switch to NLS mode. Before your change, you should notice that in NLS mode, when you change the Windows two digit year value in the Windows UI, your C# code will see the change. That's the behavior that needs to stay. |
| internal static int GetSystemTwoDigitYearSetting(CalendarId CalID, int defaultYearValue) | ||
| { | ||
| int twoDigitYearMax = GlobalizationMode.UseNls ? CalendarData.NlsGetTwoDigitYearMax(CalID) : CalendarData.IcuGetTwoDigitYearMax(); | ||
| int twoDigitYearMax = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? CalendarData.NlsGetTwoDigitYearMax(CalID) : CalendarData.IcuGetTwoDigitYearMax(); |
There was a problem hiding this comment.
Thanks @cdbullard for adding that. We usually avoid doing the OS checks inside the code. Instead we separate the code during compile time.
For this change, please move the method NlsGetTwoDigitYearMax to the file CalendarData.Windows.cs and rename the method to something like GetTwoDigitYearMax. Then move the method IcuGetTwoDigitYearMax to the file CalendarData.Unix.cs and rename the method to the same name GetTwoDigitYearMax (taking same parameters as the one moved to Windows file). last, make GetSystemTwoDigitYearSetting just CalendarData.GetTwoDigitYearMax.
There was a problem hiding this comment.
Thanks for clarifying that for me. If I make the method GetSystemTwoDigitYearSetting like this:
internal static int GetSystemTwoDigitYearSetting(CalendarId CalID, int defaultYearValue)
{
return CalendarData.GetTwoDigitYearMax(CalID);
}
should I also remove the defaultYearValue from the signature and from the places this method is being called?
There was a problem hiding this comment.
No, please keep it as:
internal static int GetSystemTwoDigitYearSetting(CalendarId CalID, int defaultYearValue)
{
int twoDigitYearMax = CalendarData.GetTwoDigitYearMax(CalID);
return twoDigitYearMax >= 0 ? twoDigitYearMax : defaultYearValue;
}Sorry I was not clear in that part :-)
There was a problem hiding this comment.
Thanks! I've just pushed a commit for this, let me know if any of it should be changed
|
|
||
| // 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; |
There was a problem hiding this comment.
Sure thing, this has been corrected
There was a problem hiding this comment.
please check there's a test that reads this in invariant mode (ie that would fail without the change above)
|
@cdbullard I added one more little comment, LGTM otherwise. Let's see if all tests pass and then we merge it. |
|
Added When you commit this breaking change:
Tagging @dotnet/compat for awareness of the breaking change. |
please remove |
src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.cs
Outdated
Show resolved
Hide resolved
…CalendarData.cs Co-authored-by: Dan Moseley <danmose@microsoft.com>
…nto twoyearvalue
|
did you merge away some of your tests? I only see one |
| if (_twoDigitYearMax == -1) | ||
| { | ||
| _twoDigitYearMax = GetSystemTwoDigitYearSetting(BaseCalendarID, GetYear(new DateTime(DefaultGregorianTwoDigitYearMax, 1, 1))); | ||
| _twoDigitYearMax = GetSystemTwoDigitYearSetting(ID, DefaultGregorianTwoDigitYearMax); |
There was a problem hiding this comment.
Why did you change this? GetYear gets the year from the used calendar and not necessary to match the Gregorian year.
There was a problem hiding this comment.
This change was discussed under this comment, but let me know if it was handled incorrectly in my commit
There was a problem hiding this comment.
I replied to that comment. Please try to revert this change.
|
Thanks @cdbullard for helping with this change! |
|
My pleasure @tarekgh! Will keep an eye out for more :-) |
Fix #75148
Update the century assumption cutoff year for determining whether a year is referring to a 19XX date or a 20XX date from 2029 to 2049.