Bug 22450 - DateTimeOffset does not round trip
Summary: DateTimeOffset does not round trip
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 3.6.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-08-28 09:52 UTC by Robert van der Boon
Modified: 2014-08-30 08:16 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 GitHub or Developer Community 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 Robert van der Boon 2014-08-28 09:52:56 UTC
Similar to #22417, but on DateTimeOffset:

DateTimeOffset ToString/TryParseExact does not round trip. I would have expected the following code to succeed:

using System;
using System.Globalization;
class P {
  static void Main(){
	string format = "r"; // with "s" it also fails.
	var dto = DateTimeOffset.UtcNow; // using .Now also fails.
	var s = dto.ToString(format, CultureInfo.InvariantCulture);
	Console.WriteLine("DTO ToString: {0}", s);
	DateTimeOffset dto2;
	bool parseExact = DateTimeOffset.TryParseExact(s, format, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out dto2);
	if (parseExact)
	  Console.WriteLine("DTO Success! {0:s}={1}={2:s}", dto, s, dto2);
	else
	  Console.WriteLine("DTO Fail! {0:s}={1} could not be parsed", dto, s);
  }
}

Output on RHEL 5.8 / Mono 3.6.0 and 3.2.1:
DTO ToString: Thu, 28 Aug 2014 13:49:18 GMT
DTO Fail! 2014-08-28T15:49:18=Thu, 28 Aug 2014 13:49:18 GMT could not be parsed


If I use DateTime for ToString/TryParseExact instead of DateTimeOffset, then the output is Success.
Comment 1 Marek Safar 2014-08-30 08:16:52 UTC
Already fixed in master