Evil Date Parsing lives! Viva Evil Date Parsing!

by Michael S. Kaplan, published on 2010/02/11 08:16 -05:00, original URI: http://blogs.msdn.com/b/michkap/archive/2010/02/11/9962007.aspx


So a  question came up the other day about an unusual interaction between the "universal sortable" format and the Arabic Um Al Qura Calendar. Here is some code that shows the problem:

CultureInfo ci = new CultureInfo("ar-sa");
ci.DateTimeFormat.Calendar = ci.OptionalCalendars[1];
Thread.CurrentThread.CurrentCulture = ci;
String value = DateTime.UtcNow.ToString("u");
DateTime dt = DateTime.Parse(value, ci, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);

Running this code causes an error on the Parse call....

Now I start with one of my very first blogs from the beginning ('Evil date parsing', Parse, and ParseExact) and suggest that the definition of evil be extended to include parsing errors. :-)

Beyond that, it is very interesting to see what is happening here.

I'll explain what is going on here tomorrow in nauseating detail, but doesd anyone want to take a stab at explaining what is going on before I do that?


Dale on 11 Feb 2010 8:49 AM:

guess 1...   you get a date that uses Indic digits and the parse code chokes on that

guess 2... the date is RTL and sorts before or after all the other dates..

Larry H. on 12 Feb 2010 8:22 AM:

"I'll explain what is going on here tomorrow in nauseating detail..."

What's going on here tomorrow? And why do you need to explain it? '-)

Michael S. Kaplan on 12 Feb 2010 12:28 PM:

Larry, see Evil Date Parsing lives! Viva Evil Date Parsing!, explained for the explanation.

Larry H. on 12 Feb 2010 7:51 PM:

I know, Michael. You had a dangling participle and I was just making a joke. Apparently not that funny.


Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

referenced by

2010/02/12 Evil Date Parsing lives! Viva Evil Date Parsing!, explained

go to newer or older post, or back to index or month or day