Bug 23544 - CultureInfo.CurrentCulture.DateTimeFormat != Android format
Summary: CultureInfo.CurrentCulture.DateTimeFormat != Android format
Status: ASSIGNED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.18.0
Hardware: PC Windows
: Normal enhancement
Target Milestone: ---
Assignee: Marek Habersack
URL:
Depends on:
Blocks:
 
Reported: 2014-10-02 04:13 UTC by Jamie
Modified: 2016-08-30 21:19 UTC (History)
3 users (show)

Tags: XATriaged
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 23544 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:
ASSIGNED

Description Jamie 2014-10-02 04:13:15 UTC
From the fourm: http://forums.xamarin.com/discussion/24987/cultureinfo-currentculture-datetimeformat-android-format

The format returned by CultureInfo.CurrentCulture.DateTimeFormat is not the same as the format displayed in the rest of Android and also does not take account of the "Use 24-hour format" setting.

For example:
- With the language set to English (United Kingdom) the time is by default, 24 hour. If I uncheck "Use 24-hour format" Android shows a format without AM/PM. CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern still returns HH:mm:ss.
- With the language set to English (United States) the time by default is 24 hour so the opposite happens. Interestingly, CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern returns h:mm tt which does not match the format displayed in the rest of Android of h:mm.
Comment 1 Arpit Jha 2014-10-03 10:00:39 UTC
I have checked this issue and unable to reproduce it.

I have tried following steps to reproduce it.
1.Create Xamarin android application.
2.Did Some code in MainActivity.cs
 var timepattern = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern.ToString ();
3.Set breakpoint on this line .
4.Run the application.

I observed that above code always returns HH:MM in both 24 hour and 12 hour time format.

Additonal Info :
Returns HH:MM format when change time zone.

Let me know If I missed anything to reproduce it.

Screencast regarding Same :
http://screencast.com/t/WXbHN2mW

Environment Info: 
=== Xamarin Studio ===

Version 5.4 (build 240)
Installation UUID: b5156fb6-e8d3-47e2-b3a5-0925a4054ffd
Runtime:
	Microsoft .NET 4.0.30319.34003
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.25

=== Xamarin.Android ===

Version: 4.16.0 (Trial Edition)
Android SDK: D:\android-sdk
	Supported Android versions:
		1.6    (API level 4)
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.0    (API level 11)
		3.1    (API level 12)
		4.0    (API level 14)
		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)
Java SDK: C:\Program Files\Java\jdk1.7.0_67
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Build Information ===

Release ID: 504000240
Git revision: 01786bc67c7024ec33d327ed27e4416d7a846f4e
Build date: 2014-09-17 11:05:20-04
Xamarin addins: 7cd7dfcd6b7b7b53281508954ec080f1cd153ad3

=== Operating System ===

Windows 6.2.9200.0 (64-bit)
Comment 2 Jonathan Pryor 2014-11-13 10:36:44 UTC
@Arpit:

> I observed that above code always returns HH:MM in 
> both 24 hour and 12 hour time format.

This is in fact your reproducing the issue. Rephrasing Comment #0:

> The format returned by CultureInfo.CurrentCulture.DateTimeFormat...
> does not take account of the "Use 24-hour format" setting.

meaning that the value *should* differ between 24-hour and 12-hour format, yet your observation is that the values are the *same* between both formats.

Comment #0 also mentioned using United Kingdom and United States locales, neither of which were reported as having the HH:MM format you provided in Comment #1.
Comment 3 Jamie 2014-11-13 10:41:16 UTC
That's correct Jon. The reason I mentioned the US and UK cultures is because they have different defaults (US is 12-hour, UK is 24-hour).

If the user is in the UK and unchecks "Use 24-hour format" in the device's settings, it will be ignored and .NET/mono will still return a 24-hour time format (HH:mm). If a user in the US checks "Use 24-hour format" .NET/mono will still return a 12-hour time format (h:mm).
Comment 4 Jonathan Pryor 2014-11-13 10:48:12 UTC
This is not easily fixed.

The problem is that the CultureInfo.DateTimeFormat information comes from locale data "baked into" mono. It is not looked up from Java:

https://github.com/mono/mono/blob/97bb0ff149e498447c0e98901e4d2268cde7259d/mcs/class/corlib/System.Globalization/CultureInfo.cs#L520
https://github.com/mono/mono/blob/97bb0ff149e498447c0e98901e4d2268cde7259d/mono/metadata/locales.c#L160-206

Fixing this will require:

1. Figuring out the appropriate Java APIs from which to extract the appropriate format information.

2. Update CultureInfo so that instead of calling into mono it calls into Mono.Android.dll (so that it can more easily perform the Java calls).
Comment 5 Arpit Jha 2014-11-14 06:21:47 UTC
I have checked this issue and observed that XVS 3.3.47(XA 4.14) returns CultureInfo in HH:mm format and XVS 3.7.248 (XA 4.18) returns cultureInfo  in h:mm tt format.

Below are my observation with diffrent XVS build and with diffrent timezone.

using var timepattern = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern.ToString();


XVS :3.7.248
TimeZone    24 Hour Checked     timepattern

GMT +0:00          Yes		 h:mm tt
GMT +0:00          No		 h:mm tt
GMT -11:00         No            h:mm tt
GMT -11:00         Yes           h:mm tt



XVS :3.3.47	

GMT +00            Yes		 HH:mm
GMT +00            No	         HH:mm	
GMT -11            No            HH:mm  
GMT -11            Yes           HH:mm
GMT+ 5.30          yes           HH:mm

Getting same behaviour with device. 

Screencast : http://www.screencast.com/t/OOZfKbbDMDNV

Environment Info:
Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.53344

Installed Version: Professional

Xamarin.Visual Studio   3.3.47.0 (0b2a123923812a88ed3091909478dbe9e0111f00)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android
Xamarin.Visual Studio   3.7.248.0
java version "1.7.0_72"
Comment 6 Jonathan Pryor 2016-07-29 17:07:20 UTC
Changing to NEW as the problem is understood, if somewhat intractable.