Bug 10901 - TimeZone Daylight Saving Time is incorrect
Summary: TimeZone Daylight Saving Time is incorrect
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.5.x
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Peter Collins
Depends on:
Reported: 2013-03-05 05:37 UTC by Stuart Lodge
Modified: 2014-11-21 15:04 UTC (History)
8 users (show)

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:

Description Stuart Lodge 2013-03-05 05:37:48 UTC
'm currently running some code using the Olson timezone lookup:

        var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Australia/Sydney");
        var utc = DateTime.UtcNow;
        var oz = TimeZoneInfo.ConvertTimeFromUtc(utc, timeZone);
        MvxTrace.Trace("OZ TIME IS {0}", oz);
        MvxTrace.Trace("OZ TIMEZONE ISDST {0}", timeZone.IsDaylightSavingTime(oz));
        MvxTrace.Trace("OZ TIMEZONE SUPPORTSDST {0}", timeZone.SupportsDaylightSavingTime);
        MvxTrace.Trace("OZ TIMEZONE IS {0}", timeZone);

This seems to be giving me an out-by-1-hour problem - it's reporting 2:XXAM, 3rd March while Google tells me it should be 3:XXAM, 3rd March.

03-02 16:30:01.935 I/DashApp (27847):   0.90 OZ TIME IS 03/03/2013 02:30:01
03-02 16:30:01.935 I/DashApp (27847):   0.91 OZ TIMEZONE ISDST False
03-02 16:30:01.935 I/DashApp (27847):   0.91 OZ TIMEZONE SUPPORTSDST True
03-02 16:30:01.935 I/DashApp (27847):   0.91 OZ TIMEZONE IS Australia/Sydney

If I run up a Console Win32 exe with:

        var timeZone = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time");
        var utc = DateTime.UtcNow;
        var oz = TimeZoneInfo.ConvertTimeFromUtc(utc, timeZone);
        Debug.WriteLine("OZ TIME IS {0}", oz);
        Debug.WriteLine("OZ TIMEZONE ISDST {0}", timeZone.IsDaylightSavingTime(oz));
        Debug.WriteLine("OZ TIMEZONE SUPPORTSDST {0}", timeZone.SupportsDaylightSavingTime);
        Debug.WriteLine("OZ TIMEZONE IS {0}", timeZone);

then I get:

OZ TIME IS 03/03/2013 03:32:08
OZ TIMEZONE IS (UTC+10:00) Canberra, Melbourne, Sydney

When JonP ran

var jtz = Java.Util.TimeZone.GetTimeZone ("Australia/Sydney");
var jd = new Java.Util.Date ();
Console.WriteLine ("Java: OZ TIME IS {0}", jd);
Console.WriteLine ("Java: OZ TIMEZONE ISDST {0}", jtz.InDaylightTime (jd));
Console.WriteLine ("Java: USE DST {0}", jtz.UseDaylightTime ());
Console.WriteLine ("Java: TIMEZONE IS {0} [{1}]", jtz, jtz.DisplayName);


Java: OZ TIME IS Mon Mar 04 15:58:21 EST 2013
Java: USE DST True
Java: TIMEZONE IS libcore.util.ZoneInfo[Australia/Sydney,mRawOffset=36000000,mUseDst=true,mDstSavings=3600000]
   0 : time=-1672567140 Sun Dec 31 14:01:00 1916 UTC = Mon Jan 01 01:01:00 1917 AEDT isDst=1 offset= 3600 gmtOffset=39600
 [Australian Eastern Standard Time]

Possibly linked also to https://bugzilla.xamarin.com/show_bug.cgi?id=7953
Comment 1 Le-roy Staines 2014-01-09 15:19:08 UTC
I also have this problem. I noticed it trying to convert to New Zealand Standard Time using:

TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.Utc, "NZ")

I expect to get 9:18am but instead get 8:18am.
Comment 2 bmoran 2014-03-15 16:36:46 UTC
I too have experienced this bug on the Linux platform and found that there was no compensation for the start of Daylight Savings Time in TimeZone.ToLocalTime(DateTime time) within TimeZone.cs.

//existing code in place for compensating the delta on exiting daylight savings
if (local < dlt.End && dlt.End.Subtract (dlt.Delta) <= local)
	return DateTime.SpecifyKind (local, DateTimeKind.Local);

//Add (not replace) these lines for adding the delta compensation upon entering daylight savings time
if (local >= dlt.Start && dlt.Start.Add (dlt.Delta) > local)
	return DateTime.SpecifyKind (local.Subtract(dlt.Delta), DateTimeKind.Local);
Comment 3 Jeremy Marcus 2014-09-30 12:21:16 UTC
I am still seeing this as an issue. When converting a UTC datetime to local time using DateTime.ToLocalTime, if the time zone of the device is London (GMT +1) it is returning GMT. It does not appear to be taking daylight saving into account. On the same device set to a timezone of PDT (GMT -7) it correctly converts the time.
Comment 4 Jonathan Pryor 2014-11-20 22:23:39 UTC
@PeterC: Can you/QA please test to see if this is still an issue as of 4.20?
Comment 5 Peter Collins 2014-11-21 15:04:16 UTC
This does indeed appear to be fixed in 4.20-series.