[iOS] Fix TimePicker AM/PM frequently changes when the app is closed and reopened#31066
Conversation
|
Hey there @@devanathan-vaithiyanathan! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where the TimePicker on iOS would incorrectly display AM/PM values after restarting the app when using 12-hour time formats. The solution ensures consistent culture usage between the display text and the native iOS picker control.
Key Changes:
- Refactored culture selection logic to use a consistent culture for both text formatting and picker locale
- Simplified the culture determination by checking for AM/PM indicators ('t') or 12-hour format ('h') to use en-US culture
- Added comprehensive UI tests to validate the TimePicker behavior
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Core/src/Platform/iOS/TimePickerExtensions.cs | Refactored the UpdateTime method to use consistent culture selection for both text display and picker locale |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30837.cs | Added UI test to verify TimePicker format consistency |
| src/Controls/tests/TestCases.HostApp/Issues/Issue30837.cs | Created test page with TimePicker using 12-hour format to reproduce the issue |
| } | ||
|
|
||
| // Apply the same culture to both the text display and the picker | ||
| mauiTimePicker.Text = time.ToFormattedString(format ?? string.Empty, formattingCulture); |
There was a problem hiding this comment.
Using string.Empty as fallback when format is null may cause issues. The original code passed format directly to ToFormattedString, which likely handles null formats appropriately. Consider using format directly or verify that ToFormattedString handles empty strings the same way as null.
| mauiTimePicker.Text = time.ToFormattedString(format ?? string.Empty, formattingCulture); | |
| mauiTimePicker.Text = time.ToFormattedString(format, formattingCulture); |
|
/azp run MAUI-UITests-public |
1 similar comment
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
|
Azure Pipelines successfully started running 1 pipeline(s). |
@jsuarezruiz , I've added the snapshots |
|
/azp run MAUI-DeviceTests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/rebase |
bb52f5b to
e4a60cd
Compare
|
Azure Pipelines successfully started running 1 pipeline(s). |
2 similar comments
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 31066Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 31066" |
kubaflo
left a comment
There was a problem hiding this comment.
Hi! Could you please add iOS-26 screenshots?
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
@kubaflo , I have added the iOS 26 snapshot. |
kubaflo
left a comment
There was a problem hiding this comment.
Hi! Could you please apply the AI Summary suggestions?
Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
@kubaflo, I have addressed the AI review summary comment |


Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details
The TimePicker was not showing AM/PM correctly after restarting the app when using the format "HH:mm tt".
Description of Change
We now use the same culture for both the display text and the TimePicker control to ensure consistency. When the format includes AM/PM, we use the en-US culture. For 24-hour formats, we use the de-DE culture.
Issues Fixed
Fixes #30837
Fixes #33722
Tested the behavior in the following platforms.
iOS-Before.mov
iOS-After.mov