<?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>Emad Alashi&#039;s Blog &#187; code convention</title>
	<atom:link href="http://www.emadashi.com/index.php/tag/code-convention/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emadashi.com</link>
	<description></description>
	<lastBuildDate>Sun, 15 Jan 2012 10:05:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JavaScript Date Object and Code Convention</title>
		<link>http://www.emadashi.com/index.php/2009/02/javascript-datetime-and-code-convention/</link>
		<comments>http://www.emadashi.com/index.php/2009/02/javascript-datetime-and-code-convention/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 22:01:17 +0000</pubDate>
		<dc:creator>Emad Alashi</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[code convention]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.emadashi.com/index.php/2009/02/javascript-datetime-and-code-convention/</guid>
		<description><![CDATA[&#8220;is Code Convention important?&#8221;, I couldn&#8217;t find better time to answer this with a big, decorated, shiny, flashing &#8220;YES&#8221; more than now!
I was doing some coding with JavaScript in which I needed to create a Date object and add to it 30 days, simple job! So I did the following:


&#160;&#160;&#160; var x = new Date();
&#160;&#160;&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;is Code Convention important?&#8221;, I couldn&#8217;t find better time to answer this with a big, decorated, shiny, flashing &#8220;YES&#8221; more than now!</p>
<p>I was doing some coding with JavaScript in which I needed to create a Date object and add to it 30 days, simple job! So I did the following:</p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof1256\uc1 \deff0{\fonttbl{\f0\fnil\fcharset178\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red242\green235\blue227;\red0\green0\blue0;\red0\green128\blue0;}??\fs20 \cf1\cb2\highlight2 var\cf0  x = \cf1 new\cf0  Date();\par ??    x.setFullYear(2009, 3, 12);\cf4 //Create date 12th of March, 2009\par ??\cf0     x.setDate(x.getDate() + 30);\par ??    document.writeln(x);}<br />
-->
<div style="font-size: 10pt; background: #f2ebe3; color: black; font-family: courier new">
<p style="margin: 0px"><span style="color: blue">&nbsp;&nbsp;&nbsp; var</span> x = <span style="color: blue">new</span> Date();</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; x.setFullYear(2009, 3, 12);<span style="color: green">//Create date 12th of March, 2009</span></p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; x.setDate(x.getDate() + 30);</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; document.writeln(x);</p>
</div>
<p>Great, when I checked the result it was: &#8220;<strong>Tue May 12 &#8230; 2009</strong>&#8220;! OMG why May?!, where did the additional month come from?! if I am in 12th of March and I add 30 days I expect it to be 11th of April, what is going on?!</p>
<p>God knows how much time I spent checking that cheesy 3rd line in my code, what could be wrong in it? maybe the &#8220;getDate()&#8221; doesn&#8217;t really return the proper type needed to set a new date? I tried all various ways doing it, checking many &#8220;solutions&#8221; scattered all over the web.</p>
<p>[Give your self sometime to figure it out before continue reading].</p>
<p>Well, the problem actually wasn&#8217;t in the 3rd line at all, it was in the 2nd! see that 2nd parameter with the value &#8220;3&#8243;? it is 0-based numeric! why on earth would it be 0-based?! any sane developer who never knew this fact would instantly deal with it &#8220;3 as March&#8221;.</p>
<p>Code Convention is as important as <a href="http://www.emadashi.com/index.php/2008/12/importance-of-documentation/">documentation</a>; if I need documentation to know how to deal with piece of code and save me time to figure it out, Code Convention is as important.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadashi.com/index.php/2009/02/javascript-datetime-and-code-convention/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

