Bug 28375 - DateTime.ToString returns wrong result
Summary: DateTime.ToString returns wrong result
Status: CONFIRMED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.4.x
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-03-24 13:39 UTC by Sebastian Span
Modified: 2017-04-28 20:04 UTC (History)
6 users (show)

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


Attachments
Output (2.33 MB, application/x-zip-compressed)
2015-03-25 10:34 UTC, Sebastian Span
Details
Catlog (478.19 KB, text/plain)
2015-03-30 04:13 UTC, Sebastian Span
Details
IDE Log (77.10 KB, application/octet-stream)
2015-03-30 04:13 UTC, Sebastian Span
Details
Application Output (77.09 KB, text/plain)
2015-03-30 04:13 UTC, Sebastian Span
Details
Test case (33.79 KB, application/zip)
2015-03-30 17:54 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
50 devices that do not show the problem (1.84 KB, text/plain)
2015-03-30 17:58 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
AndroidApp001.AndroidApp001-Signed.apk (4.63 MB, application/octet-stream)
2015-04-06 06:52 UTC, Ankit Jain
Details
AndroidApp001.AndroidApp001.apk (4.67 MB, application/octet-stream)
2015-04-06 06:56 UTC, Ankit Jain
Details


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 28375 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 Sebastian Span 2015-03-24 13:39:54 UTC
DateTime.ToString() returns invalid string (compared to Microsoft .NET)

The Exception is thrown if run under Mono for Android. Not thown in Microsoft .NET

var dateTime = new DateTime(635622052709999990);
var dateTimeAsString = dateTime.ToString("yyyyMMddHHmmssfff", CultureInfo.InvariantCulture);
if (dateTimeAsString.Length != 17)
{
	throw new Exception("Something went wrong. dateTimeAsString should contain 17 chars.");
}

Expectation: No Exception is thrown if on Mono for Android - same behavior as Microsoft .NET.
Comment 1 Ram Chandra 2015-03-25 10:22:21 UTC
I have checked this issue with both "Microsoft.NET" and "Mono 3.12.1" run time but I am not getting any error/exception. Application is working fine on both runtime.

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

Could you please provide build info, application output, IDE logs and device logs? So that we can reproduce this issue at our end.

It might be also helpful you provide the timezone of your device.

1. You can provide get build info from here:
      Xamarin Studio => Help => About => Show Details => Copy Information.

2. You can get Application output from here:
     Xamarin Studio => View => Pad => Application Output

3.You can get IDE logs form here:
    Xamarin Studio => help => Open Log Directory =>Ide logs( get latest timestamp)

You can get device logs using following command : adb logcat 

Environment Info:

=== Xamarin Studio ===

Version 5.9 (build 296)
Installation UUID: b6495454-eed9-49ee-a97b-abf8a686d664
Runtime:
 Microsoft .NET 4.0.30319.34003
 GTK+ 2.24.22 (MS-Windows theme)
 GTK# 2.12.26

=== Xamarin.Android ===

Version: 5.1.0 (Trial Edition)
Android SDK: D:\android-sdk\android-sdk
 Supported Android versions:
  2.3   (API level 10)
  4.0.3 (API level 15)
  4.4   (API level 19)
  5.0   (API level 21)
Java SDK: C:\Program Files (x86)\Java\jdk1.7.0_71
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: 0.2.5
Location: C:\Program Files\Xamarin Android Player\DeviceManager.exe

=== Build Information ===

Release ID: 509000296
Git revision: 7a9ca2a858ef1fac4ef8cab9e46cd3d9ac1cf870
Build date: 2015-03-23 15:53:36-04
Xamarin addins: fad66559ea5a308dacec9e5fdd1578c909d97688

=== Operating System ===

Windows 6.2.9200.0 (64-bit)
Comment 2 Sebastian Span 2015-03-25 10:33:31 UTC
Xamarin Studio
Version 5.5.3 (build 6)
Installation UUID: 74e8b167-8874-4a8d-9abd-6d4dc41b4934
Runtime:
	Microsoft .NET 4.0.30319.34209
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.25

Xamarin.Android
Version: 4.20.0 (Enterprise Edition)
Android SDK: C:\Users\Sebastian\AppData\Local\Android\android-sdk
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0.3  (API level 15)
		4.4    (API level 19)
		4.4.87 (API level 20)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_39
java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode, sharing)

Build Information
Release ID: 505030006
Git revision: fbe3e9453daf6a3bb9a9709ed22bec35f7c9056b
Build date: 2014-10-23 13:11:11-04
Xamarin addins: e44add2b39de4dd57c0742bb2e620dfad84c64c6

Operating System
Windows 6.2.9200.0 (64-bit)
Comment 3 Sebastian Span 2015-03-25 10:34:58 UTC
Created attachment 10497 [details]
Output
Comment 4 Sebastian Span 2015-03-25 10:36:44 UTC
Timezone: GMT+1
Comment 5 Sebastian Span 2015-03-25 10:38:22 UTC
Provided requested information
Comment 6 Ram Chandra 2015-03-25 11:49:40 UTC
@Sebastian: Thanks for providing the info.

I tried the same app with GMT+1 timezone and I am still not getting any exception/error.

The provided attachment doesn't contain logs. If you have a chance, It might also be helpful to attach Sample application, application output, IDE logs and device logs.

1. You can get Application output from here:
     Xamarin Studio => View => Pad => Application Output

2.You can get IDE logs form here:
    Xamarin Studio => help => Open Log Directory =>Ide logs( get latest
timestamp)

3.You can get IDE logs form here:
    Xamarin Studio => help => Open Log Directory =>Ide logs( get latest
timestamp).

4. You can get device logs using following command : adb logcat
Comment 7 Sebastian Span 2015-03-30 04:13:16 UTC
Created attachment 10548 [details]
Catlog
Comment 8 Sebastian Span 2015-03-30 04:13:35 UTC
Created attachment 10549 [details]
IDE Log
Comment 9 Sebastian Span 2015-03-30 04:13:51 UTC
Created attachment 10550 [details]
Application Output
Comment 10 Sebastian Span 2015-03-30 04:19:05 UTC
We've realised, that the Problem only occurs on the CAT BQ15 (http://www.catphones.com/en-gb/phones/b15q-smartphone/)

Android Version 4.4.2
Kernel-Version 3.4.67
Comment 11 Sebastian Span 2015-03-30 04:19:28 UTC
Changed Status to new
Comment 12 Ankit Jain 2015-03-30 04:31:09 UTC
Thanks for providing all the info!

What is the value of that dateTimeAsString variable? What language is set on the device?
Comment 13 Sebastian Span 2015-03-30 04:34:35 UTC
value of:

var dateTime = new DateTime(635622052709999990);
var dateTimeAsString = dateTime.ToString("yyyyMMddHHmmssfff");

dateTimeAsString is:
"201503171607501000" 
but should be:
"20150317160750999"
Comment 14 Sebastian Span 2015-03-30 04:35:29 UTC
Language is German (de-DE)
Comment 15 Sebastian Span 2015-03-30 04:47:38 UTC
Information provided
Comment 16 Ankit Jain 2015-03-30 04:57:33 UTC
I am not being able to reproduce this with Xamarin.Android 4.20.0.37 with a 4.4.2, API 19 ARM emulator. Could you try this with a simple Console application and see if you can still reproduce it?

Also, could you attach a simple test project which reproduces this issue, when deployed, just so that we are in sync?
Comment 17 Sebastian Span 2015-03-30 05:05:34 UTC
The Problem will not occur on Xamarin.Android 4.20.0.37 with a
4.4.2, API 19 ARM Emulator

It only occurs on one device: CAT B15Q. No Problems on, for example, MOTO G

Again... here's the sample (occurs in with any project type on CAT B15Q)

var dateTime = new DateTime(635622052709999990);
var dateTimeAsString = dateTime.ToString("yyyyMMddHHmmssfff");
if (dateTimeAsString.Length != 17)
{
   throw new Exception("Something went wrong. dateTimeAsString should contain 17 chars.");
}

Is there a way to share screen so that you can see that issue?
Comment 18 Brendan Zagaeski (Xamarin Team, assistant) 2015-03-30 17:54:06 UTC
Created attachment 10570 [details]
Test case

## Steps I followed to test on Test Cloud 


1. Build an APK for the Android app in the attached test case in the Release configuration.


2. Build the NUnit "Tests" project. 


3. Select 51 different Android devices on Test Cloud (32 of them were Android 4.4.2).


4. Run the Android app on Test Cloud using the `test-cloud.exe` command line tool. Use a locale of "de_DE".

> mono packages/Xamarin.UITest.0.7.1/tools/test-cloud.exe submit
>   TimeZoneOp.TimeZoneOp.apk $(API_KEY) --devices $(DEVICES) --series "master"
>   --locale "de_DE" --app-name "TimeZoneOp" --user $(XAMARIN_ACCOUNT)
>   --assembly-dir Tests/bin/Release/



## Results

Exactly 1 of the devices showed the problem:
Micromax Canvas Doodle 3, Android 4.4.2

The test fails when the app quits due to the unhandled exception:
> System.Exception: Something went wrong. dateTimeAsString should contain 17 chars.

The device's console log shows:
> I/mono-stdout( 4776): dateTimeAsString: 201503171607501000



## Expected result

The device console log should show:
> I/mono-stdout(12173): dateTimeAsString: 20150317160750999

This is an example from one of the 50 other devices I tested that did _not_ show the problem. I'll attach the complete list of devices in a follow-up comment.
Comment 19 Brendan Zagaeski (Xamarin Team, assistant) 2015-03-30 17:58:39 UTC
Created attachment 10571 [details]
50 devices that do not show the problem

## Brief version information for comment 18

Xamarin.Android 4.20.1.0
Mono 3.12.1 (detached/b63df7d)
Comment 23 Brendan Zagaeski (Xamarin Team, assistant) 2015-04-02 23:14:28 UTC
@Ankit, many thanks for the APKs. Unfortunately I do not have a "Micromax Canvas Doodle 3" at hand locally. I was only able to test on that device via Test Cloud.

In order for an APK to be testable on Test Cloud, it must have the INTERNET permission enabled. It appears the APKs from comment 20 and comment 21 do not have that permission enabled.

But I re-built and re-tested the test case in comment 19 after I had upgraded to today's alpha versions (Xamarin.Android 5.1.0.100 (7402e0b)).

The result was the same:
https://testcloud.xamarin.com/test/timezoneop_747931a5-8de5-4e96-a9a0-1ed13d380028/


### Excerpt from the device log

> I/mono-stdout( 4801): dateTimeAsString: 201503171607501000



Best,
Brendan
Xamarin Customer Support
Comment 24 Ankit Jain 2015-04-06 06:52:58 UTC
Created attachment 10641 [details]
AndroidApp001.AndroidApp001-Signed.apk
Comment 25 Ankit Jain 2015-04-06 06:56:12 UTC
Created attachment 10642 [details]
AndroidApp001.AndroidApp001.apk
Comment 26 Ankit Jain 2015-04-06 07:01:51 UTC
@Brendan,

Could you please test with the new APKs have I have attached? They are with 5.x, with some debug stuff added. I added the android.permission.INTERNET also.
Comment 27 Brendan Zagaeski (Xamarin Team, assistant) 2015-04-08 22:52:47 UTC
Thanks for the new APKs.


## New results

The APK from comment 24 shows the same behavior as the APKs in comment 18 and comment 23. Specifically, both the on-screen TextView and the "logcat" log show the following:

> Length: 18, string: 201503171607501000

> [2] https://testcloud.xamarin.com/test/a5e61ef6-e3d5-4502-aed9-2e643c8fe7ea/?step=0_0_0&device=micromax_canvas_doodle_3-4.4.2




## Quick overview of steps to test on Test Cloud

See also [1].

> [1] http://developer.xamarin.com/guides/testcloud/uitest/quickstart/uploading/#Uploading_Tests_To_Xamarin_Test_Cloud


1. Sign in on testcloud.xamarin.com.

2. Click "New Test Run" in the upper right.

3. Select "New Android App".

4. Select the "Micromax Canvas Doodle 3" device.

5. Set the system language to "German (Germany)".

6. Copy and paste the `mono` command line given by the dialog into a `Terminal.app` command prompt on OS X.

7. Adjust the various path names as needed. For example, replace the APK file name with the path to `AndroidApp001.AndroidApp001-Signed.apk`. For the "pathToTestDllFolder", you can compile the "Tests" project from the sample project attached in comment 18, and then use the `Tests/bin/Release/` folder. The UI test will "fail," but that doesn't matter for our purposes here. In this case we can use any "dummy" test, just so Test Cloud will run the app.