Bug 32887 - CultureInfo.CurrentCulture does not reflect custom format choices
Summary: CultureInfo.CurrentCulture does not reflect custom format choices
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: General (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: Normal enhancement
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-08-08 00:42 UTC by Cody Beyer (MSFT)
Modified: 2015-09-04 14:35 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 32887 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Cody Beyer (MSFT) 2015-08-08 00:42:44 UTC
### Description

When using CultureInfo.CurrentCulture, the culture is taken based entirely on the culture specified on the phone, and does not respect deviations from the global culture, such as the usage of a 24-hour clock in en-US

### Sample

https://www.dropbox.com/s/phckvka49kgnn9i/24HourTest.zip?dl=0

### Steps to Reproduce

1. Deploy to iOS Device
2. Run app
3. Notice time value on label is 2:30 PM
4. Close app
5. Open Settings > General > Date and Time > 24 hour time
6. Run app

### Expected Results

The time on the label should now show as 14:30

### Actual Results

The time continues to show 2:30 PM

### Versions

=== Xamarin Studio ===

Version 5.9.5 (build 9)
Installation UUID: 8915c17c-ec61-4ec3-8f89-0683d6363abf
Runtime:
	Mono 4.0.3 ((detached/d6946b4)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400030020

=== Apple Developer Tools ===

Xcode 6.4 (7720)
Build 6E35b

=== Xamarin.iOS ===

Version: 8.10.4.46 (Business Edition)
Hash: 2c66d2f
Branch: master
Build date: 2015-08-04 13:52:25-0400

=== Xamarin.Android ===

Version: 5.1.5.3 (Business Edition)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.0.2.111 (Business Edition)

=== Build Information ===

Release ID: 509050009
Git revision: b99cb19a1d3b15d8980c4616f13f837457e5b292
Build date: 2015-07-28 02:01:44-04
Xamarin addins: d53d6eceb828422f3d4aff8547f2f6bab6c9ea58

=== Operating System ===

Mac OS X 10.10.4
Darwin BeyerStudios.local 14.4.0 Darwin Kernel Version 14.4.0
    Thu May 28 11:35:04 PDT 2015
    root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64
Comment 1 Udham Singh 2015-08-10 07:13:08 UTC
I have checked this issue and observed that time displayed on label is always "2:30 PM" either set time format is '24-Hour Time' or '12-Hour Time'. Please refer the screencast : http://www.screencast.com/t/MxYior8o4

Ide Log : https://gist.github.com/Udham1/d73cba79dd23ab6d4fff
iOS Device Log (Xcode) : https://gist.github.com/Udham1/4ee5c40ef97b198ccaea
iOS Simulator Log (System Log) : https://gist.github.com/Udham1/5ae413baf457f3481c35

Note : I am getting this issue with both iOS device and iOS simulator.

Environment Info : 

=== Xamarin Studio ===

Version 5.9.5 (build 9)
Installation UUID: ce927b2a-2c07-44c5-b186-09cfdafba6dc
Runtime:
	Mono 4.0.3 ((detached/d6946b4)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400030020

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.iOS ===

Version: 8.10.4.49 (Business Edition)
Hash: 7e598ef
Branch: master
Build date: 2015-08-08 12:28:27-0400

=== Xamarin.Mac ===

Version: 2.0.2.125 (Business Edition)

=== Xamarin.Android ===

Version: 5.1.5.3 (Business Edition)
Android SDK: /Users/xamarin76/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Build Information ===

Release ID: 509050009
Git revision: b99cb19a1d3b15d8980c4616f13f837457e5b292
Build date: 2015-07-28 02:01:44-04
Xamarin addins: d53d6eceb828422f3d4aff8547f2f6bab6c9ea58

=== Operating System ===

Mac OS X 10.9.5
Darwin Xamarin76s-Mac-mini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 2 Sebastien Pouliot 2015-09-03 22:04:24 UTC
> the culture is taken based entirely on the culture specified on the phone

No, that's incorrect. The `CultureInfo.CurrentCulture` property is initialized based on the current iOS locale - it's not a perfect match (since both lists are not identical and varies with versions) but it's close.

However the current integration stops at initialization, the data from a CultureInfo comes only from the (mono) culture tables (not iOS). Again that's because the structures of the tables are not identical and mixing them can lead to contradictions (that would vary by locale).

Short story: Use `CultureInfo.CurrentCulture` for shared/portable code but, for UI code, prefer the NSLocale (and associated) API that iOS provides.

Keep open (as an enhancement) as we do have plans (but not dates) to attempt to close/minimize the gap between the two types.
Comment 3 Sebastien Pouliot 2015-09-04 14:35:21 UTC
An example of using the OS API (that will follow the user settings) would be to do:

> timeLabel.Text = NSDateFormatter.ToLocalizedString ((NSDate) twoThirtyPM, NSDateFormatterStyle.None, NSDateFormatterStyle.Short);