dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.96k stars 4.65k forks source link

DateTime ToString wrong delimiter for culture danish #63727

Closed mikkeljohnsen closed 2 years ago

mikkeljohnsen commented 2 years ago

Description

Culture is using the wrong delimiter for time in Danish.

Reproduction Steps

Running this:

CultureInfo culture = new CultureInfo("da-DK");
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", culture));

dotnet: 2022-01-13 09.03.51 mono: 2022-01-13 09:24:27

Expected behavior

dotnet: 2022-01-13 09:03:51

Actual behavior

dotnet: 2022-01-13 09.03.51

Regression?

Yes from .NET Framework and Mono

Known Workarounds

No response

Configuration

$ dotnet --info .NET SDK (reflecting any global.json): Version: 6.0.101 Commit: ef49f6213a

Runtime Environment: OS Name: fedora OS Version: 34 OS Platform: Linux RID: fedora.34-x64 Base Path: /usr/share/dotnet/sdk/6.0.101/

Host (useful for support): Version: 6.0.1 Commit: 3a25a7f1cc

.NET SDKs installed: 5.0.404 [/usr/share/dotnet/sdk] 6.0.101 [/usr/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 5.0.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.13 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download

Other information

No response

ghost commented 2 years ago

Tagging subscribers to this area: @dotnet/area-system-globalization See info in area-owners.md if you want to be subscribed.

Issue Details
### Description Culture is using the wrong delimiter for time in Danish. ### Reproduction Steps Running this: ``` CultureInfo culture = new CultureInfo("da-DK"); Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", culture)); ``` dotnet: 2022-01-13 09.03.51 mono: 2022-01-13 09:24:27 ### Expected behavior dotnet: 2022-01-13 09:03:51 ### Actual behavior dotnet: 2022-01-13 09.03.51 ### Regression? Yes from .NET Framework and Mono ### Known Workarounds _No response_ ### Configuration $ dotnet --info .NET SDK (reflecting any global.json): Version: 6.0.101 Commit: ef49f6213a Runtime Environment: OS Name: fedora OS Version: 34 OS Platform: Linux RID: fedora.34-x64 Base Path: /usr/share/dotnet/sdk/6.0.101/ Host (useful for support): Version: 6.0.1 Commit: 3a25a7f1cc .NET SDKs installed: 5.0.404 [/usr/share/dotnet/sdk] 6.0.101 [/usr/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 5.0.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.13 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download ### Other information _No response_
Author: mikkeljohnsen
Assignees: -
Labels: `area-System.Globalization`, `untriaged`
Milestone: -
mikkeljohnsen commented 2 years ago

I see that I can do this:

DateTimeFormatInfo dtfi = culture.DateTimeFormat;
dtfi.TimeSeparator = ":";

But why is it changed in the first place ?

jnyrup commented 2 years ago

.net 5 aligned how Windows and Linux handles culture. So now all platforms use ICU which defines . as the time separator for Danish (as a Dane I was surprised about this too).

If you want to use the literal : disregarding the culture you can use \:.

https://docs.microsoft.com/en-us/dotnet/core/extensions/globalization-icu has more details and how to go back to using NLS (the Windows only library).

mikkeljohnsen commented 2 years ago

@jnyrup Thanks for the answer.

Hvilken instance i danmark har defineret det for ICU ?

Kan se at Danmark, Finland og Indonesien skulle bruge "." som de eneste. Det giver ingen mening.

jnyrup commented 2 years ago

I'm not aware about where CLDR (ICU) gets their definition of Danish from - my guess would be from whoever contributes the most reliable source. This open issue tracks changing the time separator for Danish from . to :.

I would regard "Dansk Standard" at the source of truth. If you happen to have a copy of https://webshop.ds.dk/da-dk/standard/iso-8601-12019 you could help CLDR by providing the relevant information.

tarekgh commented 2 years ago

Thanks all for the discussion. As indicated here, .NET gets the globalization data from ICU (which gets it from CLDR). And looks this issue is tracked by CLDR too by the ticket that @jnyrup pointed at. I would suggest helping to ask the CLDR to change that if you think they have wrong data. Also, the workarounds listed here are correct to use, but we don't recommend switching back to NLS because will lose other features and also ICU is the way to move forward in general and have consistent behavior between different OS's. By that I am closing this issue, feel free to send any more questions and we'll be happy to help you with. Thanks for your report.

Henr1k80 commented 2 years ago

Duplicates https://github.com/dotnet/runtime/issues/61380