Skip to content

Get \u202F(8239) instead of ' '(32) on DateTime.ToLongTimeString when the currentCulture is en-us with in mcr.microsoft.com/dotnet/aspnet:8.0 #95620

Closed

Description

@czd890

Description

Get \u202F(8239) instead of ' '(32) on DateTime.ToLongTimeString when the currentCulture is en-us with in mcr.microsoft.com/dotnet/aspnet:8.0

on windows 11, it will get ' '(32) when running on NET8.

Reproduction Steps

  • Default Net8 project.
  • Set InvariantGlobalization =false in csproj
System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
Value = new
{
    dateime_toString = DateTime.UtcNow.ToString(),
    time_toLongTimeString = DateTime.UtcNow.ToLongTimeString(),
    datetime_toString_format = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"),
    currentCulture = System.Globalization.CultureInfo.CurrentCulture.ToString(),
    currentCulture_LongTimePattern = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern,
    currentCulture_c = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern[^3],
    currentCulture_c_int = (int)System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern[^3],
    space_c = ' ',
    space_c_int = (int)(' ')
}

// output
        "value": {
            "dateime_toString": "12/5/2023 3:53:56\u202FAM",
            "time_toLongTimeString": "3:53:56\u202FAM",
            "datetime_toString_format": "2023-12-05 03:53:56",
            "currentCulture": "en-US",
            "currentCulture_LongTimePattern": "h:mm:ss\u202Ftt",
            "currentCulture_c": "\u202F",
            "currentCulture_c_int": 8239,
            "space_c": " ",
            "space_c_int": 32
        }

Expected behavior

time_toLongTimeString equal to "h:mm:ss tt"

Actual behavior

time_toLongTimeString equal to "h:mm:ss\u202Ftt"

Regression?

Will get ' '(32) in NET6

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. ghost added
    untriaged
    on Dec 5, 2023
  2. czd890 commented on Dec 5, 2023

    @czd890
    Author

    Similar issue: nodejs/help#4068

  3. danmoseley commented on Dec 5, 2023

    @danmoseley
    Contributor

    From the linked issue (thanks!) ICU intentionally changed this to a non breaking space, which sort of makes sense as one would expect no line break there.

  4. czd890 commented on Dec 5, 2023

    @czd890
    Author

    Hi @danmoseley How can we roll back this change in NET8? This update will block the upgrade from NET6 to NET8.
    and, I did not find any related information on https://learn.microsoft.com/en-us/dotnet/core/compatibility/8.0#globalization

  5. danmoseley commented on Dec 5, 2023

    @danmoseley
    Contributor

    ICU is part of the OS distro, we do not distribute it. The linked issue suggests it's from this update

    https://github.com/unicode-org/icu/releases/tag/release-72-1

    Could you share how this is breaking your upgrade?

  6. czd890 commented on Dec 5, 2023

    @czd890
    Author

    The client relies on ' '(32) for parsing data, just like fromJson('{"value":"3:53:56\u202FAM"}').value.split(' '/is 32 instead of 8239/).

  7. tarekgh commented on Dec 5, 2023

    @tarekgh
    Member

    The client relies on ' '(32) for parsing data, just like fromJson('{"value":"3:53:56\u202FAM"}').value.split(' '/is 32 instead of 8239/).

    This is wrong to assume the globalization data will never change. It is consistently changing. The client needs to fix their code. Sooner or later, the client will run into more issues if they don't fix that.

    If want to revert using the old ICU version, you can use the app-local-icu feature. Include the following in your project.

      <ItemGroup>
        <PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="68.2.0.9" />
        <RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="68.2.0.9" />
      </ItemGroup>

    I hope to get the client to fix their code as it is wrong approach. Note, on Windows, users can fully customize the date format to something unexpected too.

  8. ghost removed
    untriaged
    on Dec 5, 2023
  9. Clockwork-Muse commented on Dec 5, 2023

    @Clockwork-Muse
    Contributor

    The client needs to fix their code. Sooner or later, the client will run into more issues if they don't fix that.

    This isn't entirely a client problem (although they should fix it too).

    DateTime.ToLongTimeString when the currentCulture is en-us

    @czd890 - If you're passing data between systems, you should be explicitly passing the invariant culture when formatting data, especially date/time.

  10. czd890 commented on Dec 6, 2023

    @czd890
    Author

    @tarekgh @Clockwork-Muse Thanks!
    Yes, I also agree that both server and client should adhere to the new rules of ICU. However, our service is a public Web API with numerous clients, making compatibility and fixing work challenging on the client side. This requires more transitional solutions and time to handle.

    Meanwhile, we should explicitly mention this breaking change in the compatibility/8.0#globalization or compatibility/8.0#containers section, highlighting that they behave differently on Windows and Linux. What are your thoughts on this?

    😂😢
    We have some APIs (that have been around for a long time) currently formatting and passing date/time in a fixed 'en-us'culture.

  11. Clockwork-Muse commented on Dec 6, 2023

    @Clockwork-Muse
    Contributor

    highlighting that they behave differently on Windows and Linux.

    Ah, no, you misunderstand.
    You have no guarantee that the formatting will be the same on any platform the next time the OS is updated. Windows or Linux. Linux distros may use different data or update it at different rates. Different machines can and will have different formatting data, even if they have the same OS. Potentially different processes on the same machine can return different data. The updates for this data isn't something we control. Your application can explicitly manage it's own formatting data, but normally you shouldn't do that (your case aside...).

    Except in rare cases, changes in the formatting data is not considered a breaking change on our end. This does not meet that bar.

    We have some APIs (that have been around for a long time) currently formatting and passing date/time in a fixed 'en-us'culture.

    Unless you're manually creating your own culture, no you're not - you're one OS update from it being yanked out from under you.

    I'd evaluate whether the InvariantCulture works for you or not (since its behavior is mostly "en-US"-like. If not, create and use an explicitly created/set up culture of your own, and ignore the host-OS data.

  12. MichalPetryka commented on Dec 6, 2023

    @MichalPetryka
    Contributor

    Or I'd say more correct would be explicitly using a standardized format like RFC 3339 or ISO 8601 when serialising the dates and keeping it fixed in code.

  13. czd890 commented on Dec 6, 2023

    @czd890
    Author

    @Clockwork-Muse I am planning to do it this way "create and use an explicitly created/set up culture of your own".
    @MichalPetryka Yes, but there are always some legacy things that need to be compatible.

  14. Clockwork-Muse commented on Dec 6, 2023

    @Clockwork-Muse
    Contributor

    @MichalPetryka - Well yes, explicitly ISO would be better on top of that.

  15. locked and limited conversation to collaborators on Jan 6, 2024
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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions