Bug 13276 - DateTime.Parse fails to parse an ISO encoded date containing a time zone
Summary: DateTime.Parse fails to parse an ISO encoded date containing a time zone
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.2.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2013-07-16 17:22 UTC by Val Savvateev
Modified: 2013-07-17 02:35 UTC (History)
2 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 FIXED

Description Val Savvateev 2013-07-16 17:22:02 UTC
This will work fine on Mono for OSX, but fails in an iOS project:

DateTime.Parse(
	"2013-07-16T21:05:51.509735+00:00",
	CultureInfo.CurrentCulture,
	DateTimeStyles.RoundtripKind
);

Our current workaround is to use ParseExact instead:

var d = DateTime.ParseExact(
	"2013-07-16T20:50:31.023245+00:00",
	"yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK",
	CultureInfo.CurrentCulture,
	DateTimeStyles.RoundtripKind
);



Stack trace:

System.FormatException: String was not recognized as a valid DateTime.
  at System.DateTime.Parse (System.String s, IFormatProvider provider, DateTimeStyles styles) [0x00027] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/DateTime.cs:830 
  at TestiOSProj.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00000] in /Temp/TestiOSProj/AppDelegate.cs:31
Comment 1 Marek Safar 2013-07-16 17:35:05 UTC
What is your CultureInfo.CurrentCulture? It seems to work for me
Comment 2 Val Savvateev 2013-07-16 19:58:31 UTC
The culture is "en-US". I ran this code in iPhone Simulator 6.1

Xamarin Studio
Version 4.0.9 (build 12)

Mono 2.10.12 (mono-2-10/c9b270d)

Xcode 4.6.3 (2068)
Build 4H1503

Xamarin.iOS
Version: 6.2.7.1 (Business Edition)
Hash: 947e664
Branch: 
Build date: 2013-30-05 18:02:40-0400
Comment 3 Marek Safar 2013-07-17 02:35:17 UTC
The bug was filled against 6.9.* Xamarin.iOS but you are running 6.2.7.1 You need at least version 6.3 which should have this fixed already.