Bug 28636 - ToLocalTime() not working when enabling linker
Summary: ToLocalTime() not working when enabling linker
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: XI 8.8.0
Hardware: PC Windows
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-04-01 11:26 UTC by jm.alfonsi
Modified: 2015-04-15 13:21 UTC (History)
3 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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description jm.alfonsi 2015-04-01 11:26:33 UTC
I have a Xamarin.iOS unified app. I pull objects with DateTime from a REST service.
These DateTime are UTC. For display, I convert them to local time using ToLocalTime() (I am in CET time zone), so far so good.

Now when I don't link the project (iOS Build -> Linker Options -> Don't link), everything is working fine.
When I link the project (iOS Build -> Linker Options -> Link SDK assemblies only), ToLocalTime() is wrong.

iOS SDK version used is 8.2.
Comment 1 Sebastien Pouliot 2015-04-01 15:47:52 UTC
The linker does not change anything about the dates/time zones. This code runs identically with or without the linker enabled (EST time zone).

		public void D ()
		{
			var x = DateTime.UtcNow;
			Console.WriteLine (x);
			var y = x.ToLocalTime ();
			Console.WriteLine (y);
		}

Linker enabled:

2015-04-01 15:44:08.509 linkall[17199:19531250] 4/1/2015 7:44:08 PM
2015-04-01 15:44:09.980 linkall[17199:19531250] 4/1/2015 3:44:08 PM

Linker disabled:

2015-04-01 15:45:12.190 linkall[17228:19537035] 4/1/2015 7:45:11 PM
2015-04-01 15:45:13.331 linkall[17228:19537035] 4/1/2015 3:45:11 PM



However REST services are generally used with serialization and that might need some extra care (reflection being used) to ensure unused code is not removed. I strongly suspect the issue exists before the conversion to local time. 

Is it possible to provide a test case ?

You can also try to print the date (e.g. `dt.Ticks`) before and after the conversion (ToLocalTime). My guess is that the conversion is correct but the original value (deserialized from the REST response) is different.
Comment 2 jm.alfonsi 2015-04-15 13:21:13 UTC
Yes, it's definitely an issue from the way we deserialize the DateTime from the REST service.
I close this one, it's not relevant.