Bug 3779 - iOS and Android date difference (using web service)
Summary: iOS and Android date difference (using web service)
Status: CLOSED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-03-07 05:53 UTC by Maxim
Modified: 2012-04-25 16:42 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:
CLOSED FIXED

Description Maxim 2012-03-07 05:53:30 UTC
Hi!

I have an web service reference in project. In one method my app invoke method, which returns two date. Code is pretty simple, no any date conversions or math:
Console.WriteLine("Date: " + elem.date + " | Begin date: " + elem.workTime.startTime);

Under iOS it returns:
Date: 05.03.2012 0:00:00 | Begin date: 05.03.2012 15:30:00

It's a good result.

Under Android it returns:
Date: 04.03.2012 23:00:00 | Begin date: 05.03.2012 14:30:00

One hour was subtracted.

If I switched to US locale, it returns:
Date: 3/4/2012 11:00:00 PM | Begin date: 3/5/2012 2:30:00 PM

Note that I use iOS and Android simulators with Russian locale. How could I take dates in any Android app part without taking into account any locale settings? 


Notes:
The problem is when I using web service. I tested web service via
SoapUI 3.6 - dates values are expected. In iOS simulator works fine
too.
I noted that service reference code after calling method returns date
with kind = local. I tried to change it to unspecified with no
results.
Comment 1 Maxim 2012-03-07 06:14:24 UTC
Example of raw data, which web service respond:
              <date>2012-03-07T00:00:00+04:00</date>
              <workTime>
                 <startTime>2012-03-07T15:30:00+04:00</startTime>
                 <endTime>2012-03-07T20:00:00+04:00</endTime>
                 <type>Рабочее время</type>
              </workTime>
Comment 2 Maxim 2012-03-12 05:16:36 UTC
Ok. The problem that in Android 2.3 emulator Moscow timezone is GMT+3, but since 2011 it's GMT+4 at any time of year (without daylight +1 hour/-1 switching).

So the questions are:
1. Is it possible to update Moscow or Russian timezones in Android 2.3?
2. How to ignore timezones when Mono's web service wrapper reads dates from XML-response to DateTime variables?
Comment 3 Eric Beisecker 2012-03-12 12:05:52 UTC
Hello Maxim,

So by default the DateTime class converts the Parsed time to whatever the current TimeZone is for the device / Emulator. 

A workaround that seems to work for me is you can explicitly convert a DateTime to whatever timezone using code similar to this.


var theTime = DateTime.Parse("2012-03-07T00:00:00+04:00"); // Gives me 2012-3-06 15:00 
var rusZone = TimeZoneInfo.FindSystemTimeZoneById("Europe/Moscow");
var convertedTime = TimeZoneInfo.ConvertTime(parsedTime, rusZone); // Now is 2012-3-07 00:00

I hope this helps.
Comment 4 Maxim 2012-04-25 16:06:18 UTC
Thank you. No more question about this issue.
Comment 5 Eric Beisecker 2012-04-25 16:42:17 UTC
Closing the bug