Microsoft vs Microsoft: C# DateTime vs IE 8 Date Object
There's a lot that can be said about what happens to a software corporation once it becomes very large, and one negative aspect is that your products eventually become disconnected. This is an inevitability, because in order for any specific product to be effective and accepted in the mass markets, it has to be tailored to the people that use them. What you end up with is a bunch of software products each targeting disparate markets, all part of a suite of very specialized tools.
That being said, I think Microsoft's development of and complete move to the .NET framework helps to resolve a lot of these issues for code development. I would even bet that the main reason they initially researched the development of the .NET framework is because they knew they needed a solid, easy-to-use code base for all of their projects that would drastically ease interoperability, speed development, and improve general code stability for their products. The natural side-effect of this is that we all get to partake of the goodness that is .NET. I can only imagine all the changes and demands being made on shared code within Microsoft itself before the move...
However, in spite of all of their efforts to make their products play nice with each other, it is kind of fun to find special cases where they do not. That being said...
A Date object's toUTCString() in IE 7+ (maybe even before) javascript creates a string like:
"Thu, 03 Jun 2010 17:22:33 UTC"
"Thu, 03 Jun 2010 17:22:33 GMT"
If you pass this as a string to your Web Service method, and then try to parse it and 'UTC' exists in the string, DateTime.TryParse() will fail because the .NET DateTime.TryParse() method does not recognize 'UTC'. It does, however, recognize 'Z'.
The solution is a wrapper method around the TryParse() .NET method, like so:
private static DateTime? ParseDate(string dateTimeString) { DateTime temp; dateTimeString = dateTimeString.Replace("UTC", "Z"); if(DateTime.TryParse(dateTimeString, out temp)) { return temp; } return null; }
If you find any other Microsoft vs Microsoft querks, let me know!
Comments
Post a Comment