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

Short date pattern from 'ky' culture produces invalid output in .NET Core 3.0 #13316

Closed
ppekrol opened this issue Aug 24, 2019 · 7 comments
Closed

Comments

@ppekrol
Copy link

ppekrol commented Aug 24, 2019

Hi,

I'm trying to convert date to string and then parse it back. I'm using short date pattern for that and 'ky' culture. Unfortunately this gives me FormatException when doing DateTime.ParseExact.

From my brief investigation it looks like the pattern, which is 'd-MMM yy' for 'ky' culture, produces additional . (dot) in output in .NET Core 3.0.

Simple code that demonstrates the issue (works fine in .NET Core 2.2):

            var cultureInfo = CultureInfo.GetCultureInfo("ky");
            Thread.CurrentThread.CurrentCulture = cultureInfo;
            var pattern = cultureInfo.DateTimeFormat.ShortDatePattern; // d-MMM yy

            Calendar calendar = new GregorianCalendar();
            DateTime date1 = calendar.ToDateTime(2000, 1, 4, 0, 0, 0, 0);

            // .NET Core 2.2: 4-янв 00
            // .NET Core 3.0: 4-янв. 00
            var dateAsString = date1.ToString(pattern);

            var date2 = DateTime.ParseExact(dateAsString, pattern, cultureInfo);

            if (date1 != date2)
                throw new InvalidOperationException("Date!");
dotnet --version
3.0.100-preview8-013656
@stephentoub stephentoub transferred this issue from dotnet/corefx Aug 26, 2019
@stephentoub
Copy link
Member

cc: @krwq, @tarekgh

@tarekgh
Copy link
Member

tarekgh commented Aug 26, 2019

@ppekrol what OS you are running on? and are you running both 2.2 and 3.0 on the exact same OS?

@stephentoub
Copy link
Member

@tarekgh, FYI, I repro'd this on Windows 10 Build 18362: running on 2.2 there's no error, and running on 3.0 there's an error.

@tarekgh
Copy link
Member

tarekgh commented Aug 26, 2019

Thanks @stephentoub, I'll take a look.

@tarekgh
Copy link
Member

tarekgh commented Aug 26, 2019

I looked at the issue, I am seeing this is happened because we have fixed the abbreviated genitive month formatting in 3.0 through the issue https://github.com/dotnet/corefx/issues/2804 and the PR dotnet/coreclr#21230. This fix still good but it looks we want to fix the parsing side too to allow parsing the abbreviated genitive month names too. I'll look more at the fix.

CC @lillo42

@tarekgh
Copy link
Member

tarekgh commented Aug 27, 2019

Description

In last December we have made a fix for the issue https://github.com/dotnet/corefx/issues/2804 allowing formatting dates with Genitive month names. The fix is good but we missed adding a support to the date parser to handle the genitive month names.
On Windows 10, there are 133 cultures with genitive names out of total 848 cultures.

Customer Impact

If the customer app dealing with date and time formatting and parsing functionality will be potentially broken if format a date with genitive months and then try to parse it back to DateTime. The parsing is going to throw exception. Some of the cultures uses date/time formatting pattern with genitive month names specifiers as the default format. For example, culture Ky uses a default short date pattern d-MMM yy produce a genitive month names in the date formatting and parsing such strings is going to throw exception.

Regression?

Yes, although the fix we did is not the real regression but the regression caused because we missed to add the parsing part with the fix.

Risk

The risk is low as we are going to allow the date parser to try the genitive month names so the failing case will start succeed.

@tarekgh
Copy link
Member

tarekgh commented Aug 27, 2019

The fix of this issue will be included in 3.0 release per the PR dotnet/coreclr#26384.

Thanks @ppekrol for reporting this issue in the right time :-)

@tarekgh tarekgh closed this as completed Aug 27, 2019
jonpryor referenced this issue in dotnet/android Dec 3, 2019
Changes: mono/api-snapshot@fc50bc4...45a61d9

        $ git diff --shortstat fc50bc4f...45a61d93
         22 files changed, 775 insertions(+), 474 deletions(-)

Changes: dotnet/cecil@a6c8f5e...a6a7f5c

        $ git diff --shortstat a6c8f5e1...a6a7f5c0
         55 files changed, 818 insertions(+), 530 deletions(-)

Changes: mono/corefx@1f87de3...49f1c45

        $ git diff --shortstat e4f7102b...49f1c453
         38 files changed, 1171 insertions(+), 419 deletions(-)

Changes: dotnet/linker@ebe2a1f...e8d054b

        $ git diff --shortstat ebe2a1f4...e8d054bf
         137 files changed, 5360 insertions(+), 1781 deletions(-)

Changes: mono/mono@8946e49...18920a8

        $ git diff --shortstat 8946e49a...18920a83
         1811 files changed, 47240 insertions(+), 48331 deletions(-)

Changes: xamarin/xamarin-android-api-compatibility@a61271e...50a3c52

        $ git diff --shortstat a61271e0...50a3c52d
         1 file changed, 2 insertions(+), 791 deletions(-)

Fixes: #3619

Context: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1005448
Context: https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/967582
Context: https://github.com/dotnet/coreclr/issues/26370
Context: https://github.com/dotnet/coreclr/issues/26479
Context: https://github.com/dotnet/corefx/issues/40455
Context: https://github.com/dotnet/corefx/issues/40578
Context: mono/mono#7377
Context: mono/mono#12421
Context: mono/mono#12586
Context: mono/mono#14080
Context: mono/mono#14725
Context: mono/mono#14772
Context: mono/mono#15261
Context: mono/mono#15262
Context: mono/mono#15263
Context: mono/mono#15307
Context: mono/mono#15308
Context: mono/mono#15310
Context: mono/mono#15646
Context: mono/mono#15687
Context: mono/mono#15805
Context: mono/mono#15992
Context: mono/mono#15994
Context: mono/mono#15999
Context: mono/mono#16032
Context: mono/mono#16034
Context: mono/mono#16046
Context: mono/mono#16192
Context: mono/mono#16308
Context: mono/mono#16310
Context: mono/mono#16369
Context: mono/mono#16380
Context: mono/mono#16381
Context: mono/mono#16395
Context: mono/mono#16411
Context: mono/mono#16415
Context: mono/mono#16486
Context: mono/mono#16570
Context: mono/mono#16605
Context: mono/mono#16616
Context: mono/mono#16689
Context: mono/mono#16701
Context: mono/mono#16712
Context: mono/mono#16742
Context: mono/mono#16759
Context: mono/mono#16803
Context: mono/mono#16808
Context: mono/mono#16824
Context: mono/mono#16876
Context: mono/mono#16879
Context: mono/mono#16918
Context: mono/mono#16943
Context: mono/mono#16950
Context: mono/mono#16974
Context: mono/mono#17004
Context: mono/mono#17017
Context: mono/mono#17038
Context: mono/mono#17040
Context: mono/mono#17083
Context: mono/mono#17084
Context: mono/mono#17133
Context: mono/mono#17139
Context: mono/mono#17151
Context: mono/mono#17180
Context: mono/mono#17278
Context: mono/mono#17549
Context: mono/mono#17569
Context: mono/mono#17665
Context: mono/mono#17687
Context: mono/mono#17737
Context: mono/mono#17790
Context: mono/mono#17924
Context: mono/mono#17931
Context: https://github.com/mono/mono/issues/26758
Context: https://github.com/mono/mono/issues/37913
Context: xamarin/xamarin-macios#7005
jonpryor referenced this issue in dotnet/android Dec 3, 2019
Changes: mono/api-snapshot@fc50bc4...45a61d9

        $ git diff --shortstat fc50bc4f...45a61d93
         22 files changed, 775 insertions(+), 474 deletions(-)

Changes: dotnet/cecil@a6c8f5e...a6a7f5c

        $ git diff --shortstat a6c8f5e1...a6a7f5c0
         55 files changed, 818 insertions(+), 530 deletions(-)

Changes: mono/corefx@1f87de3...49f1c45

        $ git diff --shortstat e4f7102b...49f1c453
         38 files changed, 1171 insertions(+), 419 deletions(-)

Changes: dotnet/linker@ebe2a1f...e8d054b

        $ git diff --shortstat ebe2a1f4...e8d054bf
         137 files changed, 5360 insertions(+), 1781 deletions(-)

Changes: mono/mono@8946e49...18920a8

        $ git diff --shortstat 8946e49a...18920a83
         1811 files changed, 47240 insertions(+), 48331 deletions(-)

Changes: xamarin/xamarin-android-api-compatibility@a61271e...50a3c52

        $ git diff --shortstat a61271e0...50a3c52d
         1 file changed, 2 insertions(+), 791 deletions(-)

Fixes: #3619

Context: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1005448
Context: https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/967582
Context: https://github.com/dotnet/coreclr/issues/26370
Context: https://github.com/dotnet/coreclr/issues/26479
Context: https://github.com/dotnet/corefx/issues/40455
Context: https://github.com/dotnet/corefx/issues/40578
Context: mono/mono#7377
Context: mono/mono#12421
Context: mono/mono#12586
Context: mono/mono#14080
Context: mono/mono#14725
Context: mono/mono#14772
Context: mono/mono#15261
Context: mono/mono#15262
Context: mono/mono#15263
Context: mono/mono#15307
Context: mono/mono#15308
Context: mono/mono#15310
Context: mono/mono#15646
Context: mono/mono#15687
Context: mono/mono#15805
Context: mono/mono#15992
Context: mono/mono#15994
Context: mono/mono#15999
Context: mono/mono#16032
Context: mono/mono#16034
Context: mono/mono#16046
Context: mono/mono#16192
Context: mono/mono#16308
Context: mono/mono#16310
Context: mono/mono#16369
Context: mono/mono#16380
Context: mono/mono#16381
Context: mono/mono#16395
Context: mono/mono#16411
Context: mono/mono#16415
Context: mono/mono#16486
Context: mono/mono#16570
Context: mono/mono#16605
Context: mono/mono#16616
Context: mono/mono#16689
Context: mono/mono#16701
Context: mono/mono#16712
Context: mono/mono#16742
Context: mono/mono#16759
Context: mono/mono#16803
Context: mono/mono#16808
Context: mono/mono#16824
Context: mono/mono#16876
Context: mono/mono#16879
Context: mono/mono#16918
Context: mono/mono#16943
Context: mono/mono#16950
Context: mono/mono#16974
Context: mono/mono#17004
Context: mono/mono#17017
Context: mono/mono#17038
Context: mono/mono#17040
Context: mono/mono#17083
Context: mono/mono#17084
Context: mono/mono#17133
Context: mono/mono#17139
Context: mono/mono#17151
Context: mono/mono#17180
Context: mono/mono#17278
Context: mono/mono#17549
Context: mono/mono#17569
Context: mono/mono#17665
Context: mono/mono#17687
Context: mono/mono#17737
Context: mono/mono#17790
Context: mono/mono#17924
Context: mono/mono#17931
Context: https://github.com/mono/mono/issues/26758
Context: https://github.com/mono/mono/issues/37913
Context: xamarin/xamarin-macios#7005
@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants