dotnet / runtime

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

[Android] ToShortTimeString() missing space between time and AM/PM on API 34 #93410

Open tombly opened 1 year ago

tombly commented 1 year ago

Description

In Android 14 (API 34) the DateTime.Now.ToShortTimeString() method no longer includes a space between the time and the am/pm. For example:

API 34: image

API 33: image

Steps to Reproduce

  1. Create a new MAUI project: dotnet new maui
  2. Add a call to DateTime.Now.ToShortTimeString() and display the output in the UI.
  3. Set Android emulator (API 34) to a locale that uses AM/PM.
  4. Run the app and observe the UI.

Expected: Short time string should have a space between the time and the am/pm. Actual: There is no space between the time and the am/pm.

Link to public reproduction project repository

No response

Version with bug

7.0.92

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 14 (API 34)

Did you find any workaround?

No response

Relevant log output

No response

samhouts commented 1 year ago

@jonathanpeppers Ideas?

drasticactions commented 1 year ago

https://github.com/drasticactions/MauiRepros/tree/main/MauiShortDateTime https://github.com/drasticactions/MauiRepros/tree/main/AndroidShortDateTime

Trying in both a .NET Android and MAUI app, running on .NET 8 with API 34, I couldn't repro this behavior. It seems to work fine in all cases in the simulator and devices I have that can run API 34.

スクリーンショット 2023-10-03 15 06 24

https://github.com/dotnet/runtime/blob/82fee2692b3954ba8903fa4764f1f4e36a26341a/src/libraries/System.Private.CoreLib/src/System/DateTime.cs#L1781-L1784

ToShortTimeString is a ToString("t") and is in the runtime. The literal string should have a space in it still. If it's rendering different in your app, maybe it has to do with something you have setup in your app? Maybe create a repro project showing it? Or try running mine and see if they show for you?

Also, I believe API 34 is .NET 8.0 only? You selected "Version with bug" with net7.0, was that mistaken?

ghost commented 1 year ago

Hi @tombly. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

tombly commented 1 year ago

Hi @drasticactions. Thanks for taking a look at this. We're using Visual Studio Mac so we're still on .NET 7 (and targeting Android API 33) and running the app on an API 34 device. I also tried targeting API 34, so maybe this issue is specific to .NET 7?

jonathanpeppers commented 1 year ago

@tombly maybe you can reproduce the issue in a dotnet new android app and share it? If this is BCL, we probably will need someone on the Mono team to take a look.

ghost commented 1 year ago

Hi @tombly. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost commented 1 year ago

Hi @tombly. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

tombly commented 1 year ago

@jonathanpeppers Here's a simple project that demonstrates the issue (includes a screenshot): https://github.com/tombly/shared/tree/main/AndroidTimeFormatIssue

For some reason dotnet new android doesn't work for me, so I just used Visual Studio 2022 (Windows) to create a new "Android Application" project, added 2 lines to the MainActivity.cs file and then ran the app on API 33 and 34 emulators. Thanks!

jonathanpeppers commented 1 year ago

/cc @steveisok looks like there is a difference between Android 33 & 34 with DateTime.Now, see screenshot:

https://github.com/tombly/shared/blob/main/AndroidTimeFormatIssue/Screenshot.png

Clockwork-Muse commented 1 year ago

.... does android update its ICU libraries during API changes? I'm asking because net core gets its localization data (including time format strings) from the host OS, and ICU updates multiple times a year. There have been changes to how we parse certain types of input when reading the format strings, including certain types of spaces; see https://github.com/dotnet/runtime/issues/83571 for a related example.

That aside, barring certain extremely specific edge cases, you shouldn't care about or pay attention to the actual formatted value; eg, in tests you should almost never test that the output string ends up a certain way (other than "not empty").

ghost commented 10 months ago

Tagging subscribers to 'arch-android': @steveisok, @akoeplinger See info in area-owners.md if you want to be subscribed.

Issue Details
### Description In Android 14 (API 34) the `DateTime.Now.ToShortTimeString()` method no longer includes a space between the time and the am/pm. For example: API 34: ![image](https://github.com/dotnet/maui/assets/6111417/5696709f-b6d6-49b3-a44b-51a1db06a9bc) API 33: ![image](https://github.com/dotnet/maui/assets/6111417/4d06f04f-0a28-4478-9b49-7663f5c59d6a) ### Steps to Reproduce 1. Create a new MAUI project: `dotnet new maui` 2. Add a call to `DateTime.Now.ToShortTimeString()` and display the output in the UI. 3. Set Android emulator (API 34) to a locale that uses AM/PM. 4. Run the app and observe the UI. Expected: Short time string should have a space between the time and the am/pm. Actual: There is no space between the time and the am/pm. ### Link to public reproduction project repository _No response_ ### Version with bug 7.0.92 ### Is this a regression from previous behavior? Yes, this used to work in .NET MAUI ### Last version that worked well Unknown/Other ### Affected platforms Android ### Affected platform versions Android 14 (API 34) ### Did you find any workaround? _No response_ ### Relevant log output _No response_
Author: tombly
Assignees: mdh1418
Labels: `os-android`, `area-CoreLib-mono`
Milestone: -