Skip to content

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

Closed

Description

@ppekrol

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

Activity

  1. transferred this issue fromdotnet/corefxon Aug 26, 2019
  2. stephentoub commented on Aug 26, 2019

    @stephentoub
    Member
  3. tarekgh commented on Aug 26, 2019

    @tarekgh
    Member

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

  4. stephentoub commented on Aug 26, 2019

    @stephentoub
    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.

  5. tarekgh commented on Aug 26, 2019

    @tarekgh
    Member

    Thanks @stephentoub, I'll take a look.

  6. tarekgh commented on Aug 26, 2019

    @tarekgh
    Member

    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

  7. tarekgh commented on Aug 27, 2019

    @tarekgh
    Member

    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.

  8. tarekgh commented on Aug 27, 2019

    @tarekgh
    Member

    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 :-)

  9. transferred this issue fromdotnet/coreclron Jan 31, 2020
  10. added this to the 3.0 milestone on Jan 31, 2020
  11. ghost locked as resolved and limited conversation to collaborators on Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions