<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: support of both 'u' and 'U' PHP date formats</title>
	<link>http://www.trirand.com/blog/?page_id=393/bugs/support-of-both-u-and-u-php-date-formats</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/bugs/support-of-both-u-and-u-php-date-formats/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>OlegK on support of both 'u' and 'U' PHP date formats</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/support-of-both-u-and-u-php-date-formats#p26016</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/support-of-both-u-and-u-php-date-formats#p26016</guid>
        	        	<description><![CDATA[<p>Hello Tony,</p>
<p>tanks for your answer. Now I think I understand where the problem is. You use some specific PHP funcions which I don&#39;t know and I read only the documentation and follow strong it. The problem is that 1330249977 is <strong>not the time in miliseconds</strong> - it&#39;s time in <strong>seconds</strong>. It corresponds the "U" format. The format "u" is the time in <strong>microseconds</strong>, but JavaScript need the time in <strong>miliseconds</strong>. Moreover I find that the documentation of "u" format really misunderstandable. How I could read <a href="http://www.php.net/manual/en/function.date.php#93891" target="_blank">here</a>&#160;the "u" format can be supported by <strong>DateTime</strong> calss and not the <strong>date</strong> calss. Moreover it seems be not the total number of ticks, but just the microsecond part of the time. If can be used in the form <strong>$d-&#62;format("Y-m-d H:i:s.u")</strong> where <strong>$d</strong> is <strong>DateTime</strong>.</p>
<p>So I suppose that the input value for the "u" format should be integer from 0 till 999. One should convert it to string and include padding 0 if needed. For example the value 43 should be converted to "043". One can additionally cut the traling 0 characters, so to convert 40 to "04" and not as "040". One should not use the "u" value as the part of <strong>new Date</strong>&#160;because JavaScript don&#39;t support the resolution. Instead of that one can add <strong>decimalSeparator</strong>&#160;to resulting string and then append the "u" value.</p>
<p>So I agree that my original suggestion is wrong, but I still think that the usage of "u" format in jqGrid is still incorrect.</p>
<p>Another problem is that the current code of jqGrid have all formats oriented on PHP, but other languges use alternative formats as default. Microsoft .NET support serializing of DateTime in the string like&#160;<strong>\/Date(ticks)\/</strong>&#160;and where&#160;<em>ticks</em>&#160;represents milliseconds since epoch (UTC). It seems that Java or MVC Spring produce just <strong>ticks</strong>&#160;with milliseconds. So the problem is which format can be used to convert the date.</p>
<p>Moreover one use now much more another Date format. The datepicker uses <span class="selflink"><a style="font-weight: bold;" href="http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate" target="_blank">$.datepicker.formatDate</a>&#160;and it&#39;s very unpractical to support always two different formats. For example newformat: &#39;d-M-Y&#39; corresponds to dateFormat:&#160;&#39;dd-M-yy&#39; in the datepicker. I think it&#39;s more larger problem.</span></p>
<p>Best regards<br />Oleg</p>
]]></description>
        	        	<pubDate>Sun, 26 Feb 2012 16:25:11 +0200</pubDate>
        </item>
        <item>
        	<title>tony on support of both 'u' and 'U' PHP date formats</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/support-of-both-u-and-u-php-date-formats#p26013</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/support-of-both-u-and-u-php-date-formats#p26013</guid>
        	        	<description><![CDATA[<p>Hello Oleg,</p>
<p>Thanks again.Right now I have time to look at the new "u" option added in 5.2.2</p>
<p>This tiime I think you have misunderstud the "u" option.</p>
<p>With few words the u option is equal to <a href="http://www.w3schools.com/jsref/jsref_getmilliseconds.asp" target="_blank">getMilliseconds</a> javascript function and it can not be used separatley.</p>
<p>In order proff my concept I have creatted simple test in PHP:</p>
<p>echo date("U");</p>
<p>echo date("u");</p>
<p>The second echo return in my demo "000000". I asked myself why?</p>
<p>My investigations go to the following equvalent of date("u") = &#62; microtime()</p>
<p>(note that at PHP site you have point for the date function we have a note:</p>
<p><strong class="note">Note</strong>:</p>
<p class="para">Since this function only accepts <a class="type integer" href="http://www.php.net/manual/en/language.types.integer.php" target="_blank">integer</a> timestamps the         <em>u</em> format character is only useful when using the         <a class="function" href="http://www.php.net/manual/en/function.date-format.php" target="_blank">date_format()</a> function with user based timestamps         created with <a class="function" href="http://www.php.net/manual/en/function.date-create.php" target="_blank">date_create()</a>.</p>
<p class="para">)</p>
<p>Having this I have two numbers from the following expressins:</p>
<p>echo date("U"); ====&#62;1330249977</p>
<p>echo microtime( true); ====&#62;1330249977.874</p>
</p>
<p>Now I pass the numbers to the following expression</p>
<p>var timestamp1 = new Date (1330249977);</p>
<p>var timestamp2 = new Date (1330249977.877);</p>
<p>Both of these return</p>
<p><a class="objectLink objectLink-Date a11yFocus " target="_blank">Date {Fri Jan 16 1970 11:30:49 GMT+0200 (FLE Standard Time)}</a></p>
</p>
<p>Now doing</p>
<p>var timestamp1 = new Date ( parseFloat(1330249977)*100);</p>
<p>var timestamp2 = new Date ( parseFloat(1330249977.877) *1000);</p>
<p>both of these return</p>
</p>
<p><a class="objectLink objectLink-Date a11yFocus " target="_blank">Date {Sun Feb 26 2012 11:52:57 GMT+0200 (FLE Standard Time)}</a></p>
</p>
<p>With simple words I think&#160; that the code should not be changed.</p>
</p>
<p>If you do not know there is a project called PHP.JS.</p>
<p>You can see how the date formating is represented here for the options u and U:</p>
<p><a href="http://phpjs.org/functions/date:380" rel="nofollow" target="_blank">http://phpjs.org/functions/date:380</a></p>
</p>
<p>Kind Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Sun, 26 Feb 2012 12:04:21 +0200</pubDate>
        </item>
        <item>
        	<title>OlegK on support of both 'u' and 'U' PHP date formats</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/support-of-both-u-and-u-php-date-formats#p26003</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/support-of-both-u-and-u-php-date-formats#p26003</guid>
        	        	<description><![CDATA[<p>Hi Tony,</p>
</p>
<p>the constructor of Date with the number as parameter wait for milliseconds: "Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch)."&#160;(see <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date" target="_blank">here</a> for example). The same format has "U" format of PHP (see <a href="http://php.net/manual/en/function.date.php" target="_blank">here</a>). If the input is in <strong>micro</strong>seconds which corresponds to "u" format of PHP, then because 1000 microsecond&#160;=&#160;1 milliseconds one have to <strong>devide</strong> the input value to 1000 to have the value in milliseconds required as input of the Date constructor. So I think that the correct should be</p>
<p><input type='button' class='sfcodeselect' name='sfselectit2498' value='Select Code' data-codeid='sfcode2498' /></p>
<div class='sfcode' id='sfcode2498'>timestamp = new Date(parseFloat(date)<strong>/(String(format) === &#34;u&#34; ?&#160;1000 : 1)</strong>);</div>
<p>Best regards<br />Oleg</p>
]]></description>
        	        	<pubDate>Fri, 24 Feb 2012 17:28:02 +0200</pubDate>
        </item>
        <item>
        	<title>tony on support of both 'u' and 'U' PHP date formats</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/support-of-both-u-and-u-php-date-formats#p25985</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/support-of-both-u-and-u-php-date-formats#p25985</guid>
        	        	<description><![CDATA[<p>Thanks Oleg,</p>
<p>Can not confirm right now, but the expression maybe should look like this:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit2068' value='Select Code' data-codeid='sfcode2068' /></p>
<div class='sfcode' id='sfcode2068'>
<p>..</p>
<p>timestamp = new Date( parseFloat(date)<strong>*(String(format) === &#34;U&#34; ?&#160;1000 : 1)</strong>);</p>
</p>
</div>
<p>Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Tue, 21 Feb 2012 16:25:53 +0200</pubDate>
        </item>
        <item>
        	<title>OlegK on support of both 'u' and 'U' PHP date formats</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/support-of-both-u-and-u-php-date-formats#p25975</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/support-of-both-u-and-u-php-date-formats#p25975</guid>
        	        	<description><![CDATA[<p>Hello Tony,</p>
<p>the current implementation of DateFormat from jquery.fmatter.js module supports only &#39;u&#39; format of input dates which follows to misunderstandnisses (see <a href="http://stackoverflow.com/q/8341824/315935" target="_blank">here</a> and <a href="http://stackoverflow.com/q/9313635/315935" target="_blank">here</a> for example).</p>
<p>PHP destinguish two different date formates: &#39;u&#39; and &#39;U&#39; (see <a href="http://php.net/manual/en/function.date.php" target="_blank">here</a>) which are different. The current code uses <strong>String(format).toLowerCase() == "u"</strong> and interpret both as the same (see <a href="https://github.com/tonytomov/jqGrid/blob/v4.3.1/js/jquery.fmatter.js#L144-146" target="_blank">here</a>):</p>
<p><input type='button' class='sfcodeselect' name='sfselectit379' value='Select Code' data-codeid='sfcode379' /></p>
<div class='sfcode' id='sfcode379'>if( !isNaN( date &#8211; 0 ) &#38;&#38; String(format).toLowerCase() == &#34;u&#34;) {<br />&#160; &#160; //Unix timestamp<br />&#160; &#160; timestamp = new Date( parseFloat(date)*1000 );&#160;</div>
<p>I suggest to fix the code to for example the following</p>
<p><input type='button' class='sfcodeselect' name='sfselectit1505' value='Select Code' data-codeid='sfcode1505' /></p>
<div class='sfcode' id='sfcode1505'>if( !isNaN( date &#8211; 0 ) &#38;&#38; String(format).toLowerCase() == &#34;u&#34;) {<br />&#160; &#160; <strong>// &#39;U&#39; &#8211; Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)<br />&#160; &#160; // &#39;u&#39; &#8211; Microseconds (added in PHP 5.2.2)</strong><br />&#160; &#160; timestamp = new Date( parseFloat(date)<strong>*(String(format) === &#34;u&#34; ?&#160;1000 : 1)</strong>);&#160;</div>
<p>Best regards<br />Oleg</p>
<p>P.S. The code of date formatter in the version 4.1.2 (see <a href="https://github.com/tonytomov/jqGrid/blob/v4.1.2/js/jquery.fmatter.js#L144-149" target="_blank">here</a>) worked still correctly with &#39;U&#39; format, but in the version 4.2.0 <a href="https://github.com/tonytomov/jqGrid/blob/v4.2.0/js/jquery.fmatter.js#L144-146" target="_blank">the new code</a> had alread the described above bug.</p>
]]></description>
        	        	<pubDate>Fri, 17 Feb 2012 11:13:07 +0200</pubDate>
        </item>
</channel>
</rss>