<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sankofa &#187; Localization</title>
	<atom:link href="http://blog.ianuy.com/tag/localization/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ianuy.com</link>
	<description>From Script Kiddie to Professional Software Developer</description>
	<lastBuildDate>Tue, 18 May 2010 16:09:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DateTime.Parse on Localized Systems</title>
		<link>http://blog.ianuy.com/2009/06/28/datetime-parse-on-localized-systems/</link>
		<comments>http://blog.ianuy.com/2009/06/28/datetime-parse-on-localized-systems/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 14:16:25 +0000</pubDate>
		<dc:creator>Ian Uy</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Localization]]></category>

		<guid isPermaLink="false">http://blog.ianuy.com/?p=468</guid>
		<description><![CDATA[Today&#8217;s post is a simple reminder that Localization is a dirty job!
So, after some time working on the migration project, we finally released a stable Release Candidate. While the Test Team is still running their Critical Regression testing (that&#8217;s the final test before release) on the release candidate, I was transferred back to the Localization [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s post is a simple reminder that <a title="Localization: A Programmer’s Dirty Job " href="http://blog.ianuy.com/2009/04/12/localization-a-programmers-dirty-job/" target="_blank">Localization is a dirty job</a>!</p>
<div id="attachment_469" class="wp-caption aligncenter" style="width: 208px"><a href="http://blog.ianuy.com/wp-content/uploads/2009/06/Broken-Clock.jpg"><img class="size-full wp-image-469" title="Broken-Clock" src="http://blog.ianuy.com/wp-content/uploads/2009/06/Broken-Clock.jpg" alt="DateTime.Parse() will break your software on localized system" width="198" height="214" /></a><p class="wp-caption-text">DateTime.Parse() will break your software on localized system</p></div>
<p>So, after some time working on <a title="Migration: Why Developers Hate Microsoft or Why Developers Hate Vista or My First Encounter how Microsoft can Break your Software " href="http://blog.ianuy.com/2009/05/10/migration-why-developers-hate-microsoft-or-my-first-encounter-how-microsoft-can-break-your-software/" target="_blank">the migration project</a>, we finally released a stable Release Candidate. While the Test Team is still running their Critical Regression testing (that&#8217;s the final test before release) on the release candidate, I was transferred back to the Localization project.</p>
<p>My current task is to make a certain web application work with the localized version of our product which is running on a localized version of Windows.</p>
<p>So far, there are 8 tracks filled against this certain web application. A quick look at the tracks revealed a common problem:</p>
<blockquote>
<h3 style="text-align: center;">&#8220;String was not recognized as a valid DateTime.&#8221;</h3>
</blockquote>
<p style="text-align: left;"><span id="more-468"></span></p>
<p style="text-align: left;">Along with that error message, the exception also gave the error&#8217;s stack trace. Lucky for me, it already gave the name of the offending namespace (but no line number, weird.) So I dig thru the code and found this on a simple Get/Set class:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> DateTime _offset <span style="color: #008000;">=</span> DateTime.<span style="color: #0000FF;">Parse</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;04/21/2007 1:45 PM&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>There are a couple of things that tickled my curiosity. Firstly, what is the purpose of this offset and why is this certain date chosen as the offset? Secondly, why is there a hardcoded date on this code? Finally (and most importantly), will DateTime.Parse() be able to parse the standard US date format (MM/DD/YYYY) in a localized version of Windows (running a Russian locale)?</p>
<p>The first two questions were never answered (the developer who made it is no longer connected with the company). But the answer to the last question was given (more like demonstrated) by my manager using <a title="What is Iron Python?" href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython" target="_blank">Iron Python</a>. My manager loaded a copy of Iron Python into a running Russian Windows Server 2008. He then launched Iron Python&#8217;s Command Line Interpreter for .NET (ipy.exe) then typed the following commands:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">import <span style="color: #000000;">System</span>
DateTime _offset <span style="color: #008000;">=</span> DateTime.<span style="color: #0000FF;">Parse</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;04/21/2007 1:45 PM&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Shockingly, the Parse command thrown an exception! DateTime.Parse() is dependent to the current CultureInfo of the machine! Since the Russian version of Windows uses the default russian date format (<a title="ISO639.1" href="ftp://ftp.software.ibm.com/software/globalization/locales/Russia-Russian_Date.pdf" target="_blank">ISO 639.1</a>) which is DD.MM.YYYY, DateTime.Parse() was not able to &#8220;understand&#8221; the supplied date in standard US format MM/DD/YYYY.</p>
<p>As a simple fix, instead of parsing the date and time, I passed the values as argument like so:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> DateTime _offset <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DateTime<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">4</span>,<span style="color: #FF0000;">21</span>,<span style="color: #FF0000;">2007</span>,<span style="color: #FF0000;">13</span>,<span style="color: #FF0000;">45</span>,00<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Problem solved! <img src='http://blog.ianuy.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>



Share and Enjoy:


	<a rel="nofollow" href="mailto:?subject=DateTime.Parse%20on%20Localized%20Systems&amp;body=http%3A%2F%2Fblog.ianuy.com%2F2009%2F06%2F28%2Fdatetime-parse-on-localized-systems%2F" title="E-mail this story to a friend!"><img src="http://blog.ianuy.com/wp-content/plugins/sociable/images/email_link.png" title="E-mail this story to a friend!" alt="E-mail this story to a friend!" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.ianuy.com%2F2009%2F06%2F28%2Fdatetime-parse-on-localized-systems%2F&amp;title=DateTime.Parse%20on%20Localized%20Systems&amp;bodytext=Today%27s%20post%20is%20a%20simple%20reminder%20that%20Localization%20is%20a%20dirty%20job%21%0D%0A%0D%0A%0D%0ASo%2C%20after%20some%20time%20working%20on%20the%20migration%20project%2C%20we%20finally%20released%20a%20stable%20Release%20Candidate.%20While%20the%20Test%20Team%20is%20still%20running%20their%20Critical%20Regression%20testing%20%28tha" title="Digg"><img src="http://blog.ianuy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fblog.ianuy.com%2F2009%2F06%2F28%2Fdatetime-parse-on-localized-systems%2F&amp;title=DateTime.Parse%20on%20Localized%20Systems" title="Reddit"><img src="http://blog.ianuy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fblog.ianuy.com%2F2009%2F06%2F28%2Fdatetime-parse-on-localized-systems%2F&amp;title=DateTime.Parse%20on%20Localized%20Systems&amp;notes=Today%27s%20post%20is%20a%20simple%20reminder%20that%20Localization%20is%20a%20dirty%20job%21%0D%0A%0D%0A%0D%0ASo%2C%20after%20some%20time%20working%20on%20the%20migration%20project%2C%20we%20finally%20released%20a%20stable%20Release%20Candidate.%20While%20the%20Test%20Team%20is%20still%20running%20their%20Critical%20Regression%20testing%20%28tha" title="del.icio.us"><img src="http://blog.ianuy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://twitter.com/home?status=DateTime.Parse%20on%20Localized%20Systems%20-%20http%3A%2F%2Fblog.ianuy.com%2F2009%2F06%2F28%2Fdatetime-parse-on-localized-systems%2F" title="Twitter"><img src="http://blog.ianuy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://slashdot.org/bookmark.pl?title=DateTime.Parse%20on%20Localized%20Systems&amp;url=http%3A%2F%2Fblog.ianuy.com%2F2009%2F06%2F28%2Fdatetime-parse-on-localized-systems%2F" title="Slashdot"><img src="http://blog.ianuy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.ianuy.com%2F2009%2F06%2F28%2Fdatetime-parse-on-localized-systems%2F&amp;t=DateTime.Parse%20on%20Localized%20Systems" title="Facebook"><img src="http://blog.ianuy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fblog.ianuy.com%2F2009%2F06%2F28%2Fdatetime-parse-on-localized-systems%2F&amp;t=DateTime.Parse%20on%20Localized%20Systems" title="MySpace"><img src="http://blog.ianuy.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.ianuy.com%2F2009%2F06%2F28%2Fdatetime-parse-on-localized-systems%2F&amp;title=DateTime.Parse%20on%20Localized%20Systems&amp;annotation=Today%27s%20post%20is%20a%20simple%20reminder%20that%20Localization%20is%20a%20dirty%20job%21%0D%0A%0D%0A%0D%0ASo%2C%20after%20some%20time%20working%20on%20the%20migration%20project%2C%20we%20finally%20released%20a%20stable%20Release%20Candidate.%20While%20the%20Test%20Team%20is%20still%20running%20their%20Critical%20Regression%20testing%20%28tha" title="Google Bookmarks"><img src="http://blog.ianuy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://www.dotnetkicks.com/kick/?url=http%3A%2F%2Fblog.ianuy.com%2F2009%2F06%2F28%2Fdatetime-parse-on-localized-systems%2F&amp;title=DateTime.Parse%20on%20Localized%20Systems" title="DotNetKicks"><img src="http://blog.ianuy.com/wp-content/plugins/sociable/images/dotnetkicks.png" title="DotNetKicks" alt="DotNetKicks" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.ianuy.com/2009/06/28/datetime-parse-on-localized-systems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
