Skip to content

fr-CA culture is different in Linux than Windows #54021

Closed

Description

@jonathanmassehsj

Description

Windows 10 output NET Core 3.1 and 5.0 :

2008-03-15 18:23:32
2008-03-15 18:23:32
2008-03-15 18:23:32

Linux Ubuntu 20.04 output NET Core 3.1 and 5.0 :
2008-03-15 18:23:32
2008-03-15 18 h 23 h 32
2008-03-15 18:23:32

Here is the code:

using System;
using System.Globalization;

namespace ConsoleApp31
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime thisDate = new DateTime(2008, 3, 15,18,23,32);

            CultureInfo culture = CultureInfo.CreateSpecificCulture("fr-FR");
            DateTimeFormatInfo dtfi = culture.DateTimeFormat;
            Console.WriteLine(thisDate.ToString("yyyy-MM-dd HH:mm:ss", culture));


            culture = CultureInfo.CreateSpecificCulture("fr-CA");
            dtfi = culture.DateTimeFormat;
            Console.WriteLine(thisDate.ToString("yyyy-MM-dd HH:mm:ss", culture));

            culture = CultureInfo.CreateSpecificCulture("fr-CA");
            dtfi = culture.DateTimeFormat;
            dtfi.TimeSeparator = ":";
            Console.WriteLine(thisDate.ToString("yyyy-MM-dd HH:mm:ss", culture));
        }
    }
}

Configuration

Regression?

Other information

Activity

  1. michaelgsharp commented on Jun 10, 2021

    @michaelgsharp
    Contributor

    Were you using x86 or x64?

  2. jonathanmassehsj commented on Jun 10, 2021

    @jonathanmassehsj
    Author

    x64 on both.

    Windows 10 x64 Professional @ version 10.0.19043.1052.
    Ubuntu x64 20.04.2 LTS

  3. michaelgsharp commented on Jun 10, 2021

    @michaelgsharp
    Contributor

    Also reproes on Ubuntu x64 18.04 (WSL 2) with .NET 6 preview 3. Transferring to the runtime team who own System.Globalization.

  4. transferred this issue fromdotnet/coreon Jun 10, 2021
  5. ghost added
    untriaged
    on Jun 10, 2021
  6. tarekgh commented on Jun 10, 2021

    @tarekgh
    Member

    @jonathanmasseurca thanks for reporting the issue.

    I believe .NET 5.0 behavior on Windows is same as the behavior when running on Ubuntu too. You should be getting 2008-03-15 18 h 23 h 32. You may be not getting that either because you have fa-CA set as default user culture on the machine and picking up the user setting Windows or you are enabling NLS through a config switch.

    To explain more about the issue, when formatting a date/time with fr-CA culture and using the date pattern yyyy-MM-dd HH:mm:ss, the : in this pattern is not the literal colon character but it means the time separator. The time separator is derived from the culture time formatting pattern itself. For fr-CA, it has the time pattern as HH 'h' mm 'min' ss 's' and that cause the framework get h as the time separator.

    If you want to force the : in the date formatting, you may use something like yyyy'-'MM'-'dd HH':'mm':'ss instead.

  7. removed
    untriaged
    on Jun 10, 2021
  8. added this to the 6.0.0 milestone on Jun 10, 2021
  9. added
    enhancement
    on Jun 10, 2021
  10. jonathanmassehsj commented on Jun 11, 2021

    @jonathanmassehsj
    Author

    Thank you for your quick reply @tarekgh, I really appreciate,

    My windows language is en-US.

    In French h is not considered the separator, h means (h for heure, meaning hour), so it cannot be the separator, it should be the :

    In French (2008-03-15 18 h 23 h 32) is not considered a valid time because h is only allowed when it's HH:mm, Ex : 23 h 23 (is valid)

    https://en.wikipedia.org/wiki/Date_and_time_notation_in_France

    https://en.wikipedia.org/wiki/Date_and_time_notation_in_Canada

    I just tried on Windows Server 2019 using en-US as the windows language, I have a valid time :
    2008-03-15 18:23:32
    2008-03-15 18:23:32
    2008-03-15 18:23:32

    The issue is somehow just in the linux build and only affect fr-CA culture (fr-FR is showing a valid time in linux not sure why only fr-CA has this weird issue)

    Many thanks @tarekgh for your help,

  11. tarekgh commented on Jun 11, 2021

    @tarekgh
    Member

    In French h is not considered the separator, h means (h for heure, meaning hour), so it cannot be the separator, it should be the :

    That is right. We need to fix the logic in the framework how we can get the time separator for such cultures.

    I just tried on Windows Server 2019 using en-US as the windows language, I have a valid time
    The issue is somehow just in the linux build and only

    The issue is when we are using ICU library. If you try Windows 10 client, you should see the same Linux behavior with .NET 5.0.

  12. jonathanmassehsj commented on Jun 11, 2021

    @jonathanmassehsj
    Author

    The issue is when we are using ICU library. If you try Windows 10 client, you should see the same Linux behavior with .NET 5.0.

    That is right, I just did a fresh install of Windows 10 client using en-US, I confirm to have now the same behavior as Linux on NET Core 5 with the h separator,

    I did another test with Framework 4.7.2, it's interesting that on Framework 4.7.2 it came back with the : (Probably it's not using the ICU library or not the same one as NET Core 5).

    Many thanks @tarekgh

  13. danmoseley commented on Jul 27, 2021

    @danmoseley
    Contributor

    @tarekgh is there more work for us here ("we need to fix the logic in the framework") or can we now close this?

  14. tarekgh commented on Jul 27, 2021

    @tarekgh
    Member

    @danmoseley this needs to get fixed in the framework. That is why I am keeping it in 6.0 milestone.

  15. ghost locked as resolved and limited conversation to collaborators on Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Globalizationenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions