-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
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 Line 25 in dd6696a
|
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: Line 25 in dd6696a
@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 runtime/src/libraries/System.Private.CoreLib/src/System/Globalization/Calendar.cs Line 714 in 20d4e30
Need to change. Instead of branching for runtime/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Nls.cs Line 14 in 20d4e30
and on none-Windows we'll do runtime/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs Line 86 in 20d4e30
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. |
@@ -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 = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? CalendarData.NlsGetTwoDigitYearMax(CalID) : CalendarData.IcuGetTwoDigitYearMax(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, this has been corrected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
did you merge away some of your tests? I only see one |
|
||
public override int TwoDigitYearMax | ||
{ | ||
get | ||
{ | ||
if (_twoDigitYearMax == -1) | ||
{ | ||
_twoDigitYearMax = GetSystemTwoDigitYearSetting(BaseCalendarID, GetYear(new DateTime(DefaultGregorianTwoDigitYearMax, 1, 1))); | ||
_twoDigitYearMax = GetSystemTwoDigitYearSetting(ID, DefaultGregorianTwoDigitYearMax); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replied to that comment. Please try to revert this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that was my bad.
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.