Bug 15134 - DST/BST not correct for dates prior to 1970
Summary: DST/BST not correct for dates prior to 1970
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-10-02 15:03 UTC by Jon Goldberger [MSFT]
Modified: 2015-02-03 13:28 UTC (History)
6 users (show)

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


Attachments
test project (11.96 KB, application/zip)
2013-10-02 15:03 UTC, Jon Goldberger [MSFT]
Details
Version info (1.34 KB, text/plain)
2013-10-02 15:03 UTC, Jon Goldberger [MSFT]
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 15134 on GitHub or Developer Community 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: GitHub Markdown or Developer Community HTML
  • 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:
NEW

Description Jon Goldberger [MSFT] 2013-10-02 15:03:21 UTC
Created attachment 5040 [details]
test project

I'm using DateTime.ToLocalTime() in an iOS library and it's returning
unexpected results. The time doesn't seem to change to match the timezone
but the Kind is being set to Local.

I've posted an example on StackOverflow.com
http://stackoverflow.com/questions/19125776/is-tolocaltime-broken-on-xamarin

Is this expected behaviour?
======================================================================================

After further investigation this appears to be confined to dates before
1970 (note that BST started in 1916).

Please find attached:

- A sample project that outputs all the timezone and datetime
information (rename .zipped to .zip)
- A screenshot of it running on my mac (iOS Simulator)
- A copy of my 'About' information.

This is to be a very serious problem and means that all 'Date of births' in
my app are shown incorrectly as they are derived from UTC date strings.

In the screenshot you'll notice that the 'Daylight savings time for year
1970' is incorrect.
Comment 1 Jon Goldberger [MSFT] 2013-10-02 15:03:41 UTC
Created attachment 5041 [details]
Version info
Comment 3 Rolf Bjarne Kvinge [MSFT] 2013-10-03 17:34:12 UTC
Paolo, looks like this commit you made a long time ago is the source of this bug:

https://github.com/mono/mono/commit/0329cf4876ee772a05eb5b26bade2a432e547975

Here is a test case: https://gist.github.com/rolfbjarne/e599168fe2aba6b47353 - executing it will clearly show that there is no summertime information from before 1970.
Comment 5 Paolo Molaro 2013-10-28 11:07:41 UTC
While we implement a complete fix for this, you can use the following workaround for DateTime.ToLocalTime():

  Datetime localdate = TimeZoneInfo.ConvertTime (utcdate, TimeZoneInfo.Utc, TimeZoneInfo.Local);
Comment 6 chris 2013-10-28 11:17:46 UTC
Hi Paolo,

The workaround does not work. It results in the same issue.

I've added the following lines to the original sample project. 

// 1960 (2)
utcDateTime = new DateTime (1960, 07, 15, 15, 00, 00, DateTimeKind.Utc);
utcTimeString = utcDateTime.ToString ();
var localdate = TimeZoneInfo.ConvertTime (utcDateTime, TimeZoneInfo.Utc,TimeZoneInfo.Local);
localTimeString = localdate.ToString ();

Both the localTimeString and utcTimeString result in "7/15/1960 3:00:00 PM", which is incorrect. localTimeString should be "7/15/1960 4:00:00 PM"
Comment 7 Paolo Molaro 2013-10-29 04:07:45 UTC
Chris: what is the mono version and the platform version this is being run on?
TimeZoneInfo needs the zoneinfo data to be available (Android, Linux, OSX).
I had tested the workaround on my system with a date from 1918 and it was fine.
Comment 8 chris 2013-10-29 06:12:48 UTC
Hi Paolo,

I'm running under iOS and have tested in both simulator and device.

I have updated my system since the original version information was attached, so here it is again:

=== Xamarin Studio ===

Version 4.0.13 (build 38)
Installation UUID: 4e7a8b28-b1e8-4f65-9910-dd21d038725e
Runtime:
	Mono 3.2.3 ((no/8d3b4b7)
	GTK+ 2.24.20 theme: Raleigh
	GTK# (2.12.0.0)
	Package version: 302030000

=== Apple Developer Tools ===

Xcode 5.0.1 (3335.23)
Build 5A2053

=== Xamarin.iOS ===

Version: 7.0.2.7 (Business Edition)
Hash: 57edee2
Branch: 
Build date: 2013-04-10 18:05:51-0400

=== Xamarin.Android ===

Version: 4.8.3 (Starter Edition)
Android SDK: /Users/chriskoiak/Library/Developer/Xamarin/android-sdk-mac_x86
	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   (API level 14)
		4.0.3 (API level 15)
		4.2   (API level 17)
Java SDK: /usr
No Java runtime present, requesting install.

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Build Information ===

Release ID: 400130038
Git revision: 07afec667f7be5d0ee511eb7115bbac6377fbae8
Build date: 2013-09-24 08:53:29+0000
Xamarin addins: 61140345a5b109633a94409edcbc7a4c19a425c6

=== Operating System ===

Mac OS X 10.9.0
Darwin Chriss-MacBook-Pro-2.local 13.0.0 Darwin Kernel Version 13.0.0
    Thu Sep 19 22:22:27 PDT 2013
    root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64